Public: anyone can read this; the crew can change it.
forked from trevato/cs
One AudioContext fake, behind the door: the sound device's test double stops being written three times #369
Check · Review · Land · Live done — Landed and live in production.
There were three copies of the fake `AudioContext`, and now there is one: `fakeAudioContext` in the new `src/engine/context.ts`, exported from `src/engine/index.ts` and listed in `surface.json` (which moves to 0.10.0). The engine's sound tests, the range's audio tests and the range's stage helper all use it now, and all three moved in one commit. No `expect` line changed in `sound.test.ts`, `src/r…
shipped production is serving it deploy ae07c2d
Sign in to join this conversation.
new above
offline
There were three copies of the fake
AudioContext, and now there is one:fakeAudioContextin the newsrc/engine/context.ts, exported fromsrc/engine/index.tsand listed insurface.json(which moves to 0.10.0). The engine's sound tests, the range's audio tests and the range's stage helper all use it now, and all three moved in one commit. Noexpectline changed insound.test.ts,src/range/audio.test.tsorboot.test.ts, andbun run test(typecheck plus 1490 tests) passes.How it records. Everything goes into one list,
log, in order: a param assigned (panner.pan.value), set or ramped at a time, a connect with the node it reached, and a start or stop with its scheduled time. Each entry names its node, and nodes are numbered in the order they were made (gain1,limiter2, …). The fake also keeps the nodes it handed out, the buffers it created, and counts of contexts opened andresume()calls. The two other views,edges(the graph) andscheduled(sets, ramps, starts and stops), are read straight offlog. Each node still connects to exactly one thing, sosound.test.tscan still walk a sound's route as a straight path.Options.
pannerandcompressorboth default to true. False removes the method from the context entirely, which is howsound.tschecks for a browser that lacks it.currentTime: 2by default, so a sound scheduled at 0 instead of "now" shows up in the times."suspended", which is what makes the device callresume().These defaults are what
sound.test.tswas already tested against. The range passescurrentTime: 0andstate: "running".The range's
voices. This is now a fold over the log (voicesOfinsrc/range/stage.test-helper.ts) rather than a second fake. The panner trick still works: the device assignspan.valuedirectly, so the fake writes that down as apanner.pan.valueevent, and the fold gives the side to the next sound started. The boot tests that check left and right pass unchanged.What changed in the callers, none of it an assertion:
sound.test.tskeeps itsfakeContextname as a thin wrapper that addspanners, read off the nodes.src/range/audio.test.ts'slogis now the recorder'sscheduledview. Its full log would include the setup the device does when the context opens, andexpect(a.log).toEqual([])means "no sound was scheduled", which is what that view says.New test file.
src/engine/context.test.tschecks that:sound.tsreads, found by reading its source;sound.ts;index.tsimport it;createBufferSourcefake.Guide.
GUIDE.mdhas a new### contextsection with its measured weight (1.7 kB raw, 0.9 kB gzipped). The whole-engine weight line is now 47.4 kB raw, 18.9 kB gzipped. The sound section names the fake as something a game gets for its tests, and the page section and the seam table no longer say a game brings its ownAudioContext. The bundle-size ceiling tests pass.Not done: the fake does not pretend to play sound. A param's value is only what was last assigned to it, and scheduling a change is written down but moves nothing.
🤖 Generated with Claude Code
Closes #332