Skip to content
Closed
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
test: use spawnSync helpers in cpu-prof tests
The cpu-prof tests hand-rolled a partial version of what
test/common/child_process already provides: log the child's stderr
when the status is non-zero, then assert the status. That manual
version never shows stdout, the signal, or the command that ran, so
a CI failure gives less information than the helper would.

Replace those blocks with spawnSyncAndExitWithoutError(). Every
existing expectation is preserved -- status 0 is still required, and
signal null is now checked as well, matching the helper defaults.

Only success-path blocks whose assertions map one-to-one onto the
helper defaults are converted.

Refs: #65351
Refs: #65552
Assisted-by: claude:opus-5
Signed-off-by: Junhwan Choi <devjunsday@gmail.com>
  • Loading branch information
DevJunz committed Sep 1, 2026
commit 3a58076ee40dfc998082f4c03840a0526e1c4bf4
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fixtures = require('../common/fixtures');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -20,17 +20,13 @@ const {

{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const profiles = getCpuProfiles(tmpdir.path);
assert.strictEqual(profiles.length, 1);
}
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-dir-absolute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();

const assert = require('assert');
const fs = require('fs');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -22,7 +22,7 @@ const {
{
tmpdir.refresh();
const dir = tmpdir.resolve('prof');
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
'--cpu-prof-interval',
kCpuProfInterval,
Expand All @@ -33,10 +33,6 @@ const {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
assert(fs.existsSync(dir));
const profiles = getCpuProfiles(dir);
assert.strictEqual(profiles.length, 1);
Expand Down
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-dir-and-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ common.skipIfInspectorDisabled();
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -23,7 +23,7 @@ const {
tmpdir.refresh();
const dir = tmpdir.resolve('prof');
const file = path.join(dir, 'test.cpuprofile');
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
'--cpu-prof-interval',
kCpuProfInterval,
Expand All @@ -36,10 +36,6 @@ const {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
assert(fs.existsSync(dir));
const profiles = getCpuProfiles(dir);
assert.deepStrictEqual(profiles, [file]);
Expand Down
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-dir-relative.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();

const assert = require('assert');
const fs = require('fs');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -21,7 +21,7 @@ const {
// relative --cpu-prof-dir
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
'--cpu-prof-interval',
kCpuProfInterval,
Expand All @@ -32,10 +32,6 @@ const {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const dir = tmpdir.resolve('prof');
assert(fs.existsSync(dir));
const profiles = getCpuProfiles(dir);
Expand Down
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-dir-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();

const assert = require('assert');
const fs = require('fs');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -21,7 +21,7 @@ const {
// --cpu-prof-dir with worker
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof-interval',
kCpuProfInterval,
'--cpu-prof-dir',
Expand All @@ -32,10 +32,6 @@ const {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const dir = tmpdir.resolve('prof');
assert(fs.existsSync(dir));
const profiles = getCpuProfiles(dir);
Expand Down
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-drained.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fixtures = require('../common/fixtures');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -21,7 +21,7 @@ const {

{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
'--cpu-prof-interval',
kCpuProfInterval,
Expand All @@ -30,10 +30,6 @@ const {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const profiles = getCpuProfiles(tmpdir.path);
assert.strictEqual(profiles.length, 1);
verifyFrames(output, profiles[0], 'fibonacci.js');
Expand Down
16 changes: 3 additions & 13 deletions test/sequential/test-cpu-prof-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ common.skipIfInspectorDisabled();
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -24,7 +24,7 @@ const {
{
tmpdir.refresh();
const file = tmpdir.resolve('test.cpuprofile');
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
'--cpu-prof-interval',
kCpuProfInterval,
Expand All @@ -35,10 +35,6 @@ const {
cwd: tmpdir.path,
env,
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const profiles = getCpuProfiles(tmpdir.path);
assert.deepStrictEqual(profiles, [file]);
verifyFrames(output, file, 'fibonacci.js');
Expand All @@ -51,7 +47,7 @@ const {
const profName = 'CPU.${pid}.cpuprofile';
const dir = tmpdir.path;

const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
'--cpu-prof',
'--cpu-prof-interval',
kCpuProfInterval,
Expand All @@ -63,12 +59,6 @@ const {
env,
});

if (output.status !== 0) {
console.error(output.stderr.toString());
}

assert.strictEqual(output.status, 0);

const expectedFile = path.join(dir, `CPU.${output.pid}.cpuprofile`);
assert.ok(fs.existsSync(expectedFile), `Expected file ${expectedFile} not found.`);

Expand Down
8 changes: 2 additions & 6 deletions test/sequential/test-cpu-prof-worker-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fixtures = require('../common/fixtures');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
const {
Expand All @@ -19,7 +19,7 @@ const {

{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
fixtures.path('workload', 'fibonacci-worker-argv.js'),
], {
cwd: tmpdir.path,
Expand All @@ -28,10 +28,6 @@ const {
CPU_PROF_INTERVAL: kCpuProfInterval,
},
});
if (output.status !== 0) {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const profiles = getCpuProfiles(tmpdir.path);
assert.strictEqual(profiles.length, 1);
verifyFrames(output, profiles[0], 'fibonacci.js');
Expand Down
Loading