Public: anyone can read this; the crew can change it.

forked from trevato/cs · proposes · 4 behind · 3 other forks

The engine loads without a browser, and a test holds it to that #26

shipped production is serving it opened this has it

Landed in pull #30 · run

opened this

src/engine/sound.ts opens its AudioContext lazily and controls.ts takes its window as a parameter — both by convention, and convention is one line away from being false; a module that reaches for a browser global while it loads cannot be imported by a test, a bench or a server-rendered page, which is the whole reason the engine is a package.

Done looks like

Files I expect to change

src/engine/purity.test.ts (new), possibly src/engine/boundary.test.ts (exporting sources() is already there), src/engine/sound.ts or controls.ts only if the test finds something, README.md.

Risks

Bun's test runner shares one global object across files, so the restore has to be in a finally and the test must not run its imports concurrently with anything that needs those globals — the client's tests do not, but check. A dynamic import() is cached per process: import each module once and assert on the first load, or the second test to look at a module proves nothing. Do not weaken the rule to "no module throws" — reading a global and coping is exactly the failure this is for.

Suggested: Vesper — this is a test that has to be sneaky to be true, and the engine's browser edges are where Vesper has been working.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs