chore: scaffold tracks and tooling

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas Winther
2026-10-28 23:34:21 +01:00
co-authored by Claude Opus 5.5
parent 6dc5bdde9e
commit e150b7fefb
27 changed files with 282 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
{
"name": "snake-course-js",
"private": true,
"type": "module",
"scripts": {
"test": "node --test \"test/*.test.js\""
}
}
View File
View File
Executable
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Usage: ./test.sh [MNN] (no arg = all tests)
set -euo pipefail
cd "$(dirname "$0")"
if [ $# -ge 1 ]; then
m=$(echo "$1" | tr 'A-Z' 'a-z')
exec node --test "test/${m}-*.test.js"
else
exec node --test "test/*.test.js"
fi
+18
View File
@@ -0,0 +1,18 @@
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
const here = dirname(fileURLToPath(import.meta.url))
/** Load fixtures/<name>.json as { function, cases: [{ name, args, expected }] }. */
export const loadFixture = (name) =>
JSON.parse(readFileSync(join(here, '..', '..', 'fixtures', `${name}.json`), 'utf8'))
/** Deep-freeze for tests (independent of the student's deepFreeze). */
export const freeze = (x) => {
if (x !== null && typeof x === 'object' && !Object.isFrozen(x)) {
Object.freeze(x)
Object.values(x).forEach(freeze)
}
return x
}
+16
View File
@@ -0,0 +1,16 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { loadFixture, freeze } from './helpers.js'
test('m00 arithmetic', () => assert.equal(1 + 1, 2))
test('m00 fixture loads and cases hold', () => {
const fx = loadFixture('m00-sanity')
assert.equal(fx.function, 'sanity')
fx.cases.forEach((c) => assert.equal(c.args[0] + c.args[1], c.expected, c.name))
})
test('m00 freeze is deep', () => {
const o = freeze({ a: { b: [1] } })
assert.ok(Object.isFrozen(o.a) && Object.isFrozen(o.a.b))
})