Skip to content

Commit fb3e022

Browse files
committed
test(scenarios): the resolve recorder writes its record to a file, not to stdout at exit
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwgUKpQgCE3UWsA74d
1 parent e4cfda2 commit fb3e022

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎packages/qa/scenarios/test/build/built-consumer.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,30 @@ export const shape = () =>
4545
export const loadScore = () => import('@objectstack/scenarios/score');
4646
`;
4747

48-
// Preloaded into the child: every URL Node resolves, printed as the last line.
48+
// Preloaded into the child: every URL Node resolves, written to the file
49+
// named by SCENARIOS_RESOLVE_RECORD. A FILE, written synchronously: the record
50+
// is ~140 KB, larger than a pipe's buffer, and a stdout write from an `exit`
51+
// handler is not flushed past what the pipe takes before the process ends
52+
// (a truncated record on a loaded CI runner).
4953
const RECORDER = `
54+
const { writeFileSync } = require('node:fs');
5055
const { registerHooks } = require('node:module');
5156
const seen = [];
5257
registerHooks({ resolve(specifier, context, next) { const r = next(specifier, context); seen.push(r.url); return r; } });
53-
process.on('exit', () => process.stdout.write('\\n' + JSON.stringify(seen) + '\\n'));
58+
process.on('exit', () => writeFileSync(process.env.SCENARIOS_RESOLVE_RECORD, JSON.stringify(seen)));
5459
`;
5560

5661
let fixture = '';
5762

5863
function runNode(code: string, kind: 'module' | 'commonjs'): { out: Record<string, unknown>; resolved: string[] } {
64+
const record = join(fixture, `resolved-${kind}.json`);
65+
rmSync(record, { force: true });
5966
const stdout = execFileSync(process.execPath, ['--require', join(fixture, 'recorder.cjs'), `--input-type=${kind}`, '-e', code], {
6067
cwd: fixture,
6168
encoding: 'utf8',
69+
env: { ...process.env, SCENARIOS_RESOLVE_RECORD: record },
6270
});
63-
const lines = stdout.trim().split('\n');
64-
return { out: JSON.parse(lines[0]!) as Record<string, unknown>, resolved: JSON.parse(lines[lines.length - 1]!) as string[] };
71+
return { out: JSON.parse(stdout.trim()) as Record<string, unknown>, resolved: JSON.parse(readFileSync(record, 'utf8')) as string[] };
6572
}
6673

6774
const probe = (mod: string) => `

0 commit comments

Comments
 (0)