Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions test/message/node_run_list.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';

require('../common');
const assert = require('node:assert/strict');
const childProcess = require('node:child_process');
const { spawnSyncAndExit } = require('../common/child_process');
const fixtures = require('../common/fixtures');

const child = childProcess.spawnSync(
const { child } = spawnSyncAndExit(
process.execPath,
[ '--no-warnings', '--run'],
{ cwd: fixtures.path('run-script'), encoding: 'utf8' },
{ status: 9, signal: null },
);
assert.strictEqual(child.status, 9);
console.log(child.stderr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is no longer necessary, the helper will output it in case of error

Suggested change
console.log(child.stderr);

@greenheadHQ greenheadHQ Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduh95 Thanks for the review!

I tried this locally and the test fails. This is a message test, so this console.log is what produces the output matched against node_run_list.out. The helper only prints on mismatch, and { status: 9, signal: null } is the expected result here.

Happy to update if I'm missing something!

4 changes: 2 additions & 2 deletions test/parallel/test-common-wpt-backends.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
const { backends, WPTRunner } = require('../common/wpt');

const queueProbe = process.env.NODE_TEST_WPT_QUEUE_PROBE === '1';
Expand Down Expand Up @@ -105,12 +106,11 @@ async function compare(throws) {
// End to end: the runner's own reporting has to match too. The webidl spec
// reports an uncaught error whose name the status file matches on.
function runDriver(driver, spec, backend) {
const { status, stdout, stderr } = spawnSync(
const { child: { stdout } } = spawnSyncAndExitWithoutError(
process.execPath,
[path.join(__dirname, '../wpt', driver), spec],
{ env: { ...process.env, WPT_BACKEND: backend }, encoding: 'utf8' },
);
assert.strictEqual(status, 0, `${spec} failed on the ${backend} backend:\n${stdout}${stderr}`);
// Specs run concurrently, so the lines arrive in an arbitrary order.
return stdout.split('\n').filter((line) => line.startsWith('[')).sort();
}
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-fs-glob.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as common from '../common/index.mjs';
import tmpdir from '../common/tmpdir.js';
import { spawnSync } from 'node:child_process';
import { spawnSyncAndExitWithoutError } from '../common/child_process.js';
import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path';
import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises';
import { glob, globSync, Dirent, chmodSync, writeFileSync, rmSync } from 'node:fs';
Expand Down Expand Up @@ -737,11 +737,10 @@ describe('glob - seen cache', function() {
`;

const seenDir = tmpdir.resolve('glob-seen');
const child = spawnSync(
spawnSyncAndExitWithoutError(
process.execPath,
['--expose-internals', '-e', script, seenDir],
{ encoding: 'utf8' },
);
assert.strictEqual(child.status, 0, child.stderr || child.stdout);
});
});
10 changes: 5 additions & 5 deletions test/parallel/test-module-unreadable-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const { spawnSyncAndAssert } = require('../common/child_process');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();
Expand All @@ -38,11 +39,10 @@ const entry = tmpdir.resolve('main.mjs');
fs.writeFileSync(entry, 'import { which } from "dep"; console.log(which);');

// Sanity check: the export resolves while the package config is readable.
{
const child = spawnSync(process.execPath, [entry], { encoding: 'utf8' });
assert.strictEqual(child.stdout.trim(), 'real');
assert.strictEqual(child.status, 0, child.stderr);
}
spawnSyncAndAssert(process.execPath, [entry], { encoding: 'utf8' }, {
stdout: 'real',
trim: true,
});

fs.chmodSync(depPackageJson, 0o000);

Expand Down
19 changes: 9 additions & 10 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const { spawnSyncAndAssert } = require('../common/child_process');
const { join } = require('path');
const fixtures = require('../common/fixtures');
const testFixtures = fixtures.path('test-runner');
Expand Down Expand Up @@ -70,16 +71,14 @@ for (const isolation of ['none', 'process']) {
const args = ['--test', '--test-reporter=tap',
'--no-experimental-strip-types',
`--test-isolation=${isolation}`, dir];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
const stdout = child.stdout.toString();

assert.match(stdout, /ok 1 - this should pass/);
assert.match(stdout, /ok 2 - this should pass/);
assert.match(stdout, /ok 3 - this should pass/);
spawnSyncAndAssert(process.execPath, args, { cwd: testFixtures }, {
stderr: '',
stdout(output) {
assert.match(output, /ok 1 - this should pass/);
assert.match(output, /ok 2 - this should pass/);
assert.match(output, /ok 3 - this should pass/);
},
});
}
}

Expand Down
42 changes: 20 additions & 22 deletions test/parallel/test-runner-coverage-default-exclusion.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '../common/index.mjs';
import { before, describe, it } from 'node:test';
import assert from 'node:assert';
import { spawnSync } from 'node:child_process';
import { cp } from 'node:fs/promises';
import tmpdir from '../common/tmpdir.js';
import fixtures from '../common/fixtures.js';
import { spawnSyncAndAssert } from '../common/child_process.js';
const skipIfNoInspector = {
skip: !process.features.inspector ? 'inspector disabled' : false
};
Expand Down Expand Up @@ -57,14 +57,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
'--test-reporter=tap',
'--no-experimental-strip-types',
];
const result = spawnSync(process.execPath, args, {
spawnSyncAndAssert(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
}, {
stderr: '',
stdout: new RegExp(RegExp.escape(report)),
});

assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
});

it('should exclude test files from coverage by default', async () => {
Expand All @@ -74,14 +73,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
'--experimental-test-coverage',
'--test-reporter=tap',
];
const result = spawnSync(process.execPath, args, {
spawnSyncAndAssert(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
}, {
stderr: '',
stdout: assertDefaultExclusions,
});

assert.strictEqual(result.stderr.toString(), '');
assertDefaultExclusions(result.stdout.toString());
assert.strictEqual(result.status, 0);
});

it('should exclude ts test files', async () => {
Expand All @@ -91,14 +89,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
'--disable-warning=ExperimentalWarning',
'--test-reporter=tap',
];
const result = spawnSync(process.execPath, args, {
spawnSyncAndAssert(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
}, {
stderr: '',
stdout: assertDefaultExclusions,
});

assert.strictEqual(result.stderr.toString(), '');
assertDefaultExclusions(result.stdout.toString());
assert.strictEqual(result.status, 0);
});

it('should exclude dotfile test files from coverage by default', async () => {
Expand All @@ -109,14 +106,15 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
'--test-reporter=tap',
'test/.dotfile.cjs',
];
const result = spawnSync(process.execPath, args, {
spawnSyncAndAssert(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
}, {
stderr: '',
stdout(output) {
assertDefaultExclusions(output);
assert.doesNotMatch(output, /#\s+\.dotfile\.cjs\s+\|/);
},
});

assert.strictEqual(result.stderr.toString(), '');
assertDefaultExclusions(result.stdout.toString());
assert.doesNotMatch(result.stdout.toString(), /#\s+\.dotfile\.cjs\s+\|/);
assert.strictEqual(result.status, 0);
});
});
26 changes: 14 additions & 12 deletions test/parallel/test-runner-coverage-thresholds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const common = require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { spawnSyncAndExit } = require('../common/child_process');
const { readdirSync } = require('node:fs');
const { test } = require('node:test');
const fixtures = require('../common/fixtures');
Expand Down Expand Up @@ -172,23 +173,24 @@ for (const coverage of coverages) {
});

test(`test failing ${coverage.flag} with dot reporter`, () => {
const result = spawnSync(process.execPath, [
const { child } = spawnSyncAndExit(process.execPath, [
'--test',
'--experimental-test-coverage',
'--test-coverage-exclude=!test/**',
`${coverage.flag}=99`,
'--test-reporter', 'dot',
fixture,
]);

const stdout = result.stdout.toString();
assert.match(
stdout,
RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`)
);
assert.match(stdout, /start of coverage report/);
assert.match(stdout, /end of coverage report/);
assert.strictEqual(result.status, 1);
assert(!findCoverageFileForPid(result.pid));
], {
status: 1,
stdout(output) {
assert.match(
output,
RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`)
);
assert.match(output, /start of coverage report/);
assert.match(output, /end of coverage report/);
},
});
assert(!findCoverageFileForPid(child.pid));
});
}
5 changes: 2 additions & 3 deletions test/pseudo-tty/test-set-raw-mode-modes.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

function isOnlcrEnabled() {
const { stdout, stderr, status } = spawnSync('stty', ['-a'], {
const { child: { stdout } } = spawnSyncAndExitWithoutError('stty', ['-a'], {
encoding: 'utf8',
stdio: ['inherit', 'pipe', 'pipe'],
});

assert.strictEqual(status, 0, stderr);
return /(?:^|[\s;])onlcr(?:[\s;]|$)/.test(stdout);
}

Expand Down