fix(js): keep test/helpers.js free of src imports
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
59bece5443
commit
045029639e
5 files changed
+13
-8
No files matched your search
@@ -1,9 +1,6 @@
|
|||||||
import { readFileSync } from 'node:fs'
|
import { readFileSync } from 'node:fs'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import { dirname, join } from 'node:path'
|
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))
|
const here = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
@@ -20,6 +17,3 @@ export const freeze = (x, seen = new WeakSet()) => {
|
|||||||
}
|
}
|
||||||
return x
|
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))
|
|
||||||
@@ -6,7 +6,8 @@ import { trace } from '../src/io.js'
|
|||||||
import { view } from '../src/view.js'
|
import { view } from '../src/view.js'
|
||||||
import { newGame } from '../src/spawn.js'
|
import { newGame } from '../src/spawn.js'
|
||||||
import { Action } from '../src/model.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 time = (t) => ({ tag: 'Time', t })
|
||||||
const down = (key) => ({ tag: 'KeyDown', key })
|
const down = (key) => ({ tag: 'KeyDown', key })
|
||||||
|
|||||||
@@ -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))
|
||||||
@@ -4,7 +4,7 @@ import { runIO, runApp } from '../src/runtime.js'
|
|||||||
import { pure, draw, randomSeed, map, sequence } from '../src/io.js'
|
import { pure, draw, randomSeed, map, sequence } from '../src/io.js'
|
||||||
import { view } from '../src/view.js'
|
import { view } from '../src/view.js'
|
||||||
import { newGame, tick } from '../src/spawn.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.
|
// A fake platform: records every call and lets the test fire events by hand.
|
||||||
const fakePlatform = (seed = 42) => {
|
const fakePlatform = (seed = 42) => {
|
||||||
|
|||||||
@@ -73,3 +73,7 @@ jsFiles(srcDir)
|
|||||||
.forEach((f) =>
|
.forEach((f) =>
|
||||||
test(`purity: ${f.slice(srcDir.length + 1)} has no banned constructs`, () =>
|
test(`purity: ${f.slice(srcDir.length + 1)} has no banned constructs`, () =>
|
||||||
assert.deepEqual(violations(readFileSync(f, 'utf8')), [])))
|
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\//))
|
||||||
Reference in new issue
Block a user