mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
fix(build): discover unit tests under server/, not only src/
npm test is the only suite CI runs, and its discovery walked src/ alone, so server/providers/transitHistory.test.mjs has never executed since it was added. Its 8 tests pass, so this was silent coverage loss rather than a hidden failure: the file reads like covered code in review and never ran anywhere. Add server/ to the searched roots, and pin the property with a test that walks the repository itself and compares the two sets, so a tree added later without updating the roots fails loudly instead of going quiet. Suite goes from 5090 to 5099 tests, 0 failures: the 8 tests in that file plus the regression test added here.
This commit is contained in:
1 parent
81eb44340d
commit
c87f007e34
2 files changed
+62
-3
No files matched your search
@@ -1,14 +1,40 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import {
|
||||
ALLOCATION_TEST_FILES,
|
||||
UNIT_TEST_ROOTS,
|
||||
allocationTestArgs,
|
||||
assertNode24AllocationRuntime,
|
||||
buildUnitTestPlan,
|
||||
discoverUnitTestFiles,
|
||||
isCalibratedAllocationRuntime,
|
||||
} from '../scripts/run-unit-tests.mjs';
|
||||
|
||||
const repositoryRoot = fileURLToPath(new URL('..', import.meta.url));
|
||||
|
||||
/** Every `*.test.mjs` a contributor could add, found without consulting the runner. */
|
||||
function testFilesOnDisk(root) {
|
||||
// Build outputs and dependencies are not places a contributor writes a test,
|
||||
// and walking them would be slow enough to matter. Everything else counts.
|
||||
const skip = new Set(['node_modules', 'dist', 'build', 'public']);
|
||||
const found = [];
|
||||
const visit = (directory) => {
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||
if (entry.name.startsWith('.') || skip.has(entry.name)) continue;
|
||||
const absolute = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) visit(absolute);
|
||||
else if (entry.isFile() && entry.name.endsWith('.test.mjs')) {
|
||||
found.push(path.relative(root, absolute).split(path.sep).join('/'));
|
||||
}
|
||||
}
|
||||
};
|
||||
visit(root);
|
||||
return found.sort();
|
||||
}
|
||||
|
||||
test('unit runner serializes only GC-bracketed allocation microbenchmarks', () => {
|
||||
const ordinary = [
|
||||
'src/data/manager.test.mjs',
|
||||
@@ -37,6 +63,29 @@ test('unit runner serializes only GC-bracketed allocation microbenchmarks', () =
|
||||
);
|
||||
});
|
||||
|
||||
test('the runner discovers every test file in the repository', () => {
|
||||
// `npm test` is the only suite CI runs, and it runs exactly what this
|
||||
// function returns. A `*.test.mjs` outside the searched roots therefore never
|
||||
// executes anywhere, while still reading — in review and to its author — like
|
||||
// covered code. Compare the two sets rather than their sizes, so the failure
|
||||
// names the files instead of only disagreeing about a count.
|
||||
const discovered = discoverUnitTestFiles(repositoryRoot);
|
||||
const onDisk = testFilesOnDisk(repositoryRoot);
|
||||
const undiscovered = onDisk.filter((file) => !discovered.includes(file));
|
||||
assert.deepEqual(
|
||||
undiscovered,
|
||||
[],
|
||||
`test files the runner never executes: ${undiscovered.join(', ')}`,
|
||||
);
|
||||
assert.deepEqual(discovered, onDisk);
|
||||
for (const file of discovered) {
|
||||
assert.ok(
|
||||
UNIT_TEST_ROOTS.some((root) => file.startsWith(`${root}/`)),
|
||||
`${file} should sit under one of ${UNIT_TEST_ROOTS.join(', ')}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('allocation runtime calibration is explicit and pinned to Node 24', () => {
|
||||
assert.equal(assertNode24AllocationRuntime('24.19.0'), '24.19.0');
|
||||
assert.throws(
|
||||
|
||||
Reference in new issue
Block a user