diff --git a/js/test/helpers.js b/js/test/helpers.js index 702e11d..15128cc 100644 --- a/js/test/helpers.js +++ b/js/test/helpers.js @@ -1,9 +1,6 @@ import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, join } from 'node:path' -import { states, classicActions, render } from '../src/app.js' -import { map as mapStream } from '../src/stream.js' -import { map as mapIO, randomSeed } from '../src/io.js' const here = dirname(fileURLToPath(import.meta.url)) @@ -20,6 +17,3 @@ export const freeze = (x, seen = new WeakSet()) => { } return x } - -/** The m09 program built from classicActions (ticks every 150 ms). The shipped `main` switches to speedActions in m10. */ -export const classicMain = mapIO(randomSeed, (seed) => mapStream(states(seed, classicActions), render)) diff --git a/js/test/m09-app.test.js b/js/test/m09-app.test.js index 15531f5..4717347 100644 --- a/js/test/m09-app.test.js +++ b/js/test/m09-app.test.js @@ -6,7 +6,8 @@ import { trace } from '../src/io.js' import { view } from '../src/view.js' import { newGame } from '../src/spawn.js' import { Action } from '../src/model.js' -import { freeze, classicMain } from './helpers.js' +import { freeze } from './helpers.js' +import { classicMain } from './m09-helpers.js' const time = (t) => ({ tag: 'Time', t }) const down = (key) => ({ tag: 'KeyDown', key }) diff --git a/js/test/m09-helpers.js b/js/test/m09-helpers.js new file mode 100644 index 0000000..c60a290 --- /dev/null +++ b/js/test/m09-helpers.js @@ -0,0 +1,6 @@ +import { states, classicActions, render } from '../src/app.js' +import { map as mapStream } from '../src/stream.js' +import { map as mapIO, randomSeed } from '../src/io.js' + +/** The m09 program built from classicActions (ticks every 150 ms). The shipped `main` switches to speedActions in m10. */ +export const classicMain = mapIO(randomSeed, (seed) => mapStream(states(seed, classicActions), render)) diff --git a/js/test/m09-runtime.test.js b/js/test/m09-runtime.test.js index 7de0395..3cce7fd 100644 --- a/js/test/m09-runtime.test.js +++ b/js/test/m09-runtime.test.js @@ -4,7 +4,7 @@ import { runIO, runApp } from '../src/runtime.js' import { pure, draw, randomSeed, map, sequence } from '../src/io.js' import { view } from '../src/view.js' import { newGame, tick } from '../src/spawn.js' -import { classicMain } from './helpers.js' +import { classicMain } from './m09-helpers.js' // A fake platform: records every call and lets the test fire events by hand. const fakePlatform = (seed = 42) => { diff --git a/js/test/purity.test.js b/js/test/purity.test.js index 8b78267..cde3355 100644 --- a/js/test/purity.test.js +++ b/js/test/purity.test.js @@ -73,3 +73,7 @@ jsFiles(srcDir) .forEach((f) => test(`purity: ${f.slice(srcDir.length + 1)} has no banned constructs`, () => assert.deepEqual(violations(readFileSync(f, 'utf8')), []))) + +// helpers.js is loaded by every test file; importing src/ there would make all tests fail at load time against the stubs. +test('test/helpers.js imports nothing from src/', () => + assert.doesNotMatch(readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'helpers.js'), 'utf8'), /from\s+['"][^'"]*src\//))