Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Write per-file test timings from each shard (issue #560)

Nguyen Xuan An475b1d0e785b
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 4b5642fc..2a8474b0 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -61,12 +61,14 @@ jobs:
- uses: ./.github/actions/setup
# The live MCP tests need build/ and build/mcp.
- run: npm run build:lib
- - run: mkdir -p coverage && npm run test:coverage -- --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/shard-${{ matrix.shard }}.info $(node scripts/shard-test-files.mjs ${{ matrix.shard }} 6)
+ - run: mkdir -p coverage && npm run test:coverage -- --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/shard-${{ matrix.shard }}.info --test-reporter=./scripts/test-timing-reporter.mjs --test-reporter-destination=coverage/timings-${{ matrix.shard }}.json $(node scripts/shard-test-files.mjs ${{ matrix.shard }} 6)
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: lcov-shard-${{ matrix.shard }}
- path: coverage/shard-${{ matrix.shard }}.info
+ path: |
+ coverage/shard-${{ matrix.shard }}.info
+ coverage/timings-${{ matrix.shard }}.json
if-no-files-found: error
coverage:
diff --git a/scripts/test-timing-reporter.mjs b/scripts/test-timing-reporter.mjs
new file mode 100644
index 00000000..2fdf87eb
--- /dev/null
+++ b/scripts/test-timing-reporter.mjs
@@ -0,0 +1,25 @@
+// Node test reporter that writes how long each test file took, as JSON: { "tests/x.test.js": milliseconds }.
+// Use: node --test --test-reporter=./scripts/test-timing-reporter.mjs --test-reporter-destination=timings.json <files>
+// scripts/shard-test-files.mjs reads the committed copy (test-timings.json) to balance the shards.
+import { relative } from 'node:path';
+
+export default async function* timingReporter(source) {
+ const millisecondsByFile = new Map();
+ for await (const event of source) {
+ if (event.type !== 'test:pass' && event.type !== 'test:fail') continue;
+ const { file, nesting, details, name } = event.data;
+ if (!file || nesting !== 0) continue;
+ const relativeFile = relative(process.cwd(), file).split('\\').join('/');
+ // Top-level tests of a file add up; the file's own entry (named after the file) already covers all of them.
+ const isFileEntry = name === file || name === relativeFile;
+ const previous = millisecondsByFile.get(relativeFile) ?? 0;
+ millisecondsByFile.set(
+ relativeFile,
+ isFileEntry ? Math.max(previous, details.duration_ms) : previous + details.duration_ms
+ );
+ }
+ const sorted = Object.fromEntries(
+ [...millisecondsByFile.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([file, ms]) => [file, Math.round(ms)])
+ );
+ yield `${JSON.stringify(sorted, null, 2)}\n`;
+}