Skip to content

Commit d0d8c10

Browse files
authored
fix(rees): run REES coverage's test child from review-enrichment/ (#8616)
spawnSync ran c8 and the node:test child it wraps with the same cwd (the monorepo root), needed so c8's lcov SF: paths remap to review-enrichment/src/** for Codecov. But that left the actual test process running from the wrong directory, so tests that read fixtures via bare relative paths (e.g. analyzer-metadata.test.ts reading "analyzer-metadata.json") failed with ENOENT even though the fixture exists at review-enrichment/analyzer-metadata.json. Preload a small --require script into only the spawned test child to chdir it into review-enrichment/ before node:test loads any files, leaving c8's own process cwd (and therefore its SF: path remapping) untouched. Test file arguments switch from root-relative to absolute paths since they're now resolved from a different cwd.
1 parent e56e9a7 commit d0d8c10

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

scripts/rees-coverage-chdir.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Preloaded via --require before node:test loads review-enrichment's test files.
2+
// c8 (the parent process) must keep its own cwd at the monorepo root so lcov SF: paths
3+
// remap to `review-enrichment/src/**` for Codecov (#6250); this only chdir's the spawned
4+
// test child, so tests that read fixtures with bare relative paths (e.g. "analyzer-metadata.json")
5+
// resolve them against review-enrichment/, matching `npm run test:node`.
6+
const { join } = require("node:path");
7+
8+
process.chdir(join(__dirname, "..", "review-enrichment"));

scripts/rees-coverage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// (not bare `src/**`), and expands the test list in-process so Windows/npm quoting cannot drop the suite.
44
import { spawnSync } from "node:child_process";
55
import { readFileSync, readdirSync, writeFileSync } from "node:fs";
6-
import { join, relative } from "node:path";
6+
import { join } from "node:path";
77
import { fileURLToPath, URL } from "node:url";
88

99
/** Normalize c8's SF: paths to forward slashes for Codecov. Swallows only a missing report
@@ -39,8 +39,10 @@ function main() {
3939
const c8Bin = join(root, "review-enrichment", "node_modules", "c8", "bin", "c8.js");
4040
const reportDir = join(root, "review-enrichment", "coverage");
4141
const testRoot = join(root, "review-enrichment", "test");
42+
const chdirPreload = join(root, "scripts", "rees-coverage-chdir.cjs");
4243

43-
const tests = collectTests(testRoot).map((path) => relative(root, path).split("\\").join("/"));
44+
// Absolute paths: the test child's cwd is review-enrichment/ (see chdirPreload), not root.
45+
const tests = collectTests(testRoot).map((path) => path.split("\\").join("/"));
4446
if (tests.length === 0) {
4547
console.error("rees-coverage: no review-enrichment/test/**/*.test.ts files found");
4648
process.exit(1);
@@ -57,6 +59,8 @@ function main() {
5759
"--exclude=**/*.d.ts",
5860
"--all",
5961
process.execPath,
62+
"--require",
63+
chdirPreload,
6064
"--test",
6165
"--experimental-strip-types",
6266
...tests,

0 commit comments

Comments
 (0)