fix(js): keep test/helpers.js free of src imports

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-29 00:03:01 +01:00
co-authored by Claude Sonnet 5.5
parent 59bece5443
commit 045029639e
5 changed files with 13 additions and 8 deletions
-6
View File
@@ -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))
+2 -1
View File
@@ -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 })
+6
View File
@@ -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))
+1 -1
View File
@@ -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) => {
+4
View File
@@ -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\//))