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
Sign in to join this conversation.
new above
offline
src/engine/sound.tsopens itsAudioContextlazily andcontrols.tstakes 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), possiblysrc/engine/boundary.test.ts(exportingsources()is already there),src/engine/sound.tsorcontrols.tsonly 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
finallyand the test must not run its imports concurrently with anything that needs those globals — the client's tests do not, but check. A dynamicimport()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.