Testing
Run the tests, change the messages, and find out what the worker is doing.
Run the tests
npm run checkIt does five things:
- Generates
src/protofrom the protocol submodule. - Checks that each env in
wrangler.jsoncrepeats the top-level settings. - Checks that
worker-configuration.d.tsmatcheswrangler.jsoncand.dev.vars.example. - Typechecks.
- Runs the tests in workerd, the runtime of Cloudflare Workers. The SFU and TURN APIs are mocked.
To run one file:
npx vitest run tests/workerd/room.test.ts| File | What it tests |
|---|---|
token.test.ts | The token API and opening the socket |
flow.test.ts | Device sockets, wake, publish, subscribe and sleep |
presence.test.ts | Pings, offline devices and reconnects |
room.test.ts | Rooms, members and limits |
data.test.ts | Data channels and control |
voice.test.ts | Microphones and the devices' voices |
admin.test.ts | The dashboard, with a key and with Access |
debug.test.ts | The debug pages |
pages.test.ts | The static pages |
Change the messages
The messages live in mazupo/protocol. This repo has it as a submodule in external/protocol.
- Change the
.protofiles inexternal/protocol, on a branch. - Run
npm run proto. It warns that the submodule is not at the recorded commit. That is expected while you work. - Merge the protocol change to its
main. - Point the submodule of this repo, pi-webrtc and client-sdk-js at the same commit.
- In this repo, set
protocol.commitinpackage.jsonto that commit too. A copy made by the Deploy to Cloudflare button has no submodule, so its build downloads the protos at this commit.npm run checkfails when the two differ.
CI checks that this repo pins the same protocol commit as pi-webrtc main. So merge the pi-webrtc change first.
Change the config
After you change vars, bindings or .dev.vars.example, run:
npm run cf-typegenOptional secrets that are not in .dev.vars.example go in src/env.d.ts.
Debug
- Server state on the demo pages shows what the Durable Objects hold. See Debug pages.
npm run devprints one JSON line for each event, such asdevice_gone.- To keep a separate local state, run
npx wrangler dev --persist-to <folder>.

