Skip to content

Commit fca009f

Browse files
committed
test: route test logs to stderr to stop node:test IPC crashes
Raw stdout writes share the pipe with node:test's serialized results and can corrupt them (nodejs/node#64061). A preload sends console output to stderr for every test file.
1 parent 701b98b commit fca009f

3 files changed

Lines changed: 3 additions & 4 deletions

File tree

‎backend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"dev": "nodemon server.js",
99
"start": "node server.js",
10-
"test": "node --test tests/*.test.js",
10+
"test": "node --test --import ./tests/setup.js tests/*.test.js",
1111
"test-caching": "node test-yesterday-caching.js",
1212
"test-refresh": "node test-refresh-functionality.js",
1313
"test-mock-summary": "node test-yesterday-summary-mock.js",

‎backend/tests/billingRoutes.test.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ beforeEach(() => {
4747
});
4848
currentUser = { _id: USER_ID, githubId: '1', username: 'dev', email: '[email protected]', trialEndsAt: new Date(Date.now() + 60_000) };
4949
stripeCalls = { customers: [], sessions: [], portal: [] };
50-
// Route logs on stdout can corrupt the node:test IPC stream (nodejs/node#64061)
51-
mock.method(console, 'log', () => {});
52-
mock.method(console, 'error', () => {});
5350
mock.method(User, 'findById', () => {
5451
const result = Promise.resolve(currentUser);
5552
result.select = () => Promise.resolve(currentUser);

‎backend/tests/setup.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// node:test reads each file's results from its stdout, and raw log writes there can corrupt them (nodejs/node#64061)
2+
console.log = console.info = console.debug = console.error;

0 commit comments

Comments
 (0)