Skip to content

Commit 235a0ba

Browse files
ganjanggejangaduh95
authored andcommitted
test: use common/child_process spawnSync helpers
Replace manual spawnSync() result assertions with test/common/child_process helper functions. Signed-off-by: Junsoo Ha <junsoo2018@naver.com> PR-URL: #65377 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 96b91dc commit 235a0ba

12 files changed

Lines changed: 45 additions & 67 deletions

‎test/parallel/test-crypto-key-store-pkcs11.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const {
3434
verify,
3535
}=require('crypto');
3636
consttmpdir=require('../common/tmpdir');
37+
const{ spawnSyncAndExitWithoutError }=require('../common/child_process');
3738

3839
const{ subtle }=globalThis.crypto;
3940
constkData=Buffer.from(
@@ -65,15 +66,14 @@ function softhsmOptions() {
6566

6667
functionrunInChild(){
6768
const{ cwd, env }=softhsmOptions();
68-
constchild=spawnSync(process.execPath,[
69+
spawnSyncAndExitWithoutError(process.execPath,[
6970
`--openssl-config=${kOpenSSLConfig}`,
7071
__filename,
7172
],{
7273
cwd,
7374
env: { ...process.env, ...env,NODE_TEST_PKCS11_CHILD: '1'},
7475
stdio: 'inherit',
7576
});
76-
assert.strictEqual(child.status,0);
7777
}
7878

7979
functionprivateKeyUrl(label){

‎test/parallel/test-experimental-shared-value-conveyor.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22
constcommon=require('../common');
33
constassert=require('assert');
4-
const{ spawnSync }=require('child_process');
54
const{ Worker, parentPort }=require('worker_threads');
5+
const{ spawnSyncAndAssert }=require('../common/child_process');
66

77
if(process.env.TEST_CHILD_PROCESS==='1'){
88
// Do not use isMainThread so that this test itself can be run inside a Worker.
@@ -29,10 +29,10 @@ if (process.env.TEST_CHILD_PROCESS === '1') {
2929

3030
constargs=['--harmony-struct',__filename];
3131
constoptions={env: {TEST_CHILD_PROCESS: '1', ...process.env}};
32-
constchild=spawnSync(process.execPath,args,options);
3332

34-
assert.strictEqual(child.stderr.toString().trim(),'');
35-
assert.strictEqual(child.stdout.toString().trim(),'');
36-
assert.strictEqual(child.status,0);
37-
assert.strictEqual(child.signal,null);
33+
spawnSyncAndAssert(process.execPath,args,options,{
34+
stdout: '',
35+
stderr: '',
36+
trim: true
37+
});
3838
}

‎test/parallel/test-heap-prof-basic.js‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const fixtures = require('../common/fixtures');
99
common.skipIfInspectorDisabled();
1010

1111
constassert=require('assert');
12-
const{spawnSync}=require('child_process');
12+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1313

1414
consttmpdir=require('../common/tmpdir');
1515

@@ -20,18 +20,13 @@ const {
2020

2121
{
2222
tmpdir.refresh();
23-
constoutput=spawnSync(process.execPath,[
23+
spawnSyncAndExitWithoutError(process.execPath,[
2424
'--heap-prof',
2525
fixtures.path('workload','allocation.js'),
2626
],{
2727
cwd: tmpdir.path,
2828
env
2929
});
30-
if(output.status!==0){
31-
console.log(output.stderr.toString());
32-
console.log(output);
33-
}
34-
assert.strictEqual(output.status,0);
3530
constprofiles=getHeapProfiles(tmpdir.path);
3631
assert.strictEqual(profiles.length,1);
3732
}

‎test/parallel/test-heap-prof-exec-argv.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const fixtures = require('../common/fixtures');
99
common.skipIfInspectorDisabled();
1010

1111
constassert=require('assert');
12-
const{spawnSync}=require('child_process');
12+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1313

1414
consttmpdir=require('../common/tmpdir');
1515

@@ -20,7 +20,7 @@ const {
2020

2121
{
2222
tmpdir.refresh();
23-
constoutput=spawnSync(process.execPath,[
23+
const{child: output}=spawnSyncAndExitWithoutError(process.execPath,[
2424
fixtures.path('workload','allocation-worker-argv.js'),
2525
],{
2626
cwd: tmpdir.path,
@@ -29,10 +29,6 @@ const {
2929
HEAP_PROF_INTERVAL: '128'
3030
}
3131
});
32-
if(output.status!==0){
33-
console.log(output.stderr.toString());
34-
}
35-
assert.strictEqual(output.status,0);
3632
constprofiles=getHeapProfiles(tmpdir.path);
3733
assert.strictEqual(profiles.length,1);
3834
verifyFrames(output,profiles[0],'runAllocation');

‎test/parallel/test-heap-prof-loop-drained.js‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const fixtures = require('../common/fixtures');
88
common.skipIfInspectorDisabled();
99

1010
constassert=require('assert');
11-
const{spawnSync}=require('child_process');
11+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1212

1313
consttmpdir=require('../common/tmpdir');
1414

@@ -21,7 +21,7 @@ const {
2121

2222
{
2323
tmpdir.refresh();
24-
constoutput=spawnSync(process.execPath,[
24+
const{child: output}=spawnSyncAndExitWithoutError(process.execPath,[
2525
'--heap-prof',
2626
'--heap-prof-interval',
2727
kHeapProfInterval,
@@ -30,11 +30,6 @@ const {
3030
cwd: tmpdir.path,
3131
env
3232
});
33-
if(output.status!==0){
34-
console.log(output.stderr.toString());
35-
console.log(output);
36-
}
37-
assert.strictEqual(output.status,0);
3833
constprofiles=getHeapProfiles(tmpdir.path);
3934
assert.strictEqual(profiles.length,1);
4035
verifyFrames(output,profiles[0],'runAllocation');

‎test/parallel/test-inspect-address-in-use.js‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
constcommon=require('../common');
33
common.skipIfInspectorDisabled();
44

5-
const{spawnSync}=require('child_process');
5+
const{spawnSyncAndExit}=require('../common/child_process');
66
const{ createServer }=require('http');
77
constassert=require('assert');
88
consttmpdir=require('../common/tmpdir');
@@ -25,19 +25,18 @@ function testOnServerListen(fn) {
2525
functiontestChildProcess(getArgs,exitCode,options){
2626
testOnServerListen(common.mustCall((server)=>{
2727
const{ port }=server.address();
28-
constchild=spawnSync(process.execPath,getArgs(port),options);
29-
conststderr=child.stderr.toString().trim();
30-
conststdout=child.stdout.toString().trim();
31-
console.log('[STDERR]');
32-
console.log(stderr);
33-
console.log('[STDOUT]');
34-
console.log(stdout);
35-
constmatch=stderr.match(
36-
/Startinginspectoron127\.0\.0\.1:(\d+)failed:addressalreadyinuse/
37-
);
38-
assert.notStrictEqual(match,null);
39-
assert.strictEqual(match[1],port+'');
40-
assert.strictEqual(child.status,exitCode);
28+
spawnSyncAndExit(process.execPath,getArgs(port),options,{
29+
status: exitCode,
30+
signal: null,
31+
trim: true,
32+
stderr: function(str){
33+
constmatch=str.match(
34+
/Startinginspectoron127\.0\.0\.1:(\d+)failed:addressalreadyinuse/
35+
);
36+
assert.notStrictEqual(match,null);
37+
assert.strictEqual(match[1],port+'');
38+
},
39+
});
4140
}));
4241
}
4342

‎test/parallel/test-os-homedir-no-envvar.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22
constcommon=require('../common');
33
constassert=require('assert');
4-
constcp=require('child_process');
54
constos=require('os');
65
constpath=require('path');
6+
const{ spawnSyncAndExitWithoutError }=require('../common/child_process');
77

88

99
if(process.argv[2]==='child'){
@@ -22,9 +22,7 @@ if (process.argv[2] === 'child') {
2222
else
2323
deleteprocess.env.HOME;
2424

25-
constchild=cp.spawnSync(process.execPath,[__filename,'child'],{
25+
spawnSyncAndExitWithoutError(process.execPath,[__filename,'child'],{
2626
env: process.env
2727
});
28-
29-
assert.strictEqual(child.status,0);
3028
}

‎test/parallel/test-process-execpath.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (common.isWindows)
44
common.skip('symlinks are weird on windows');
55

66
constassert=require('assert');
7-
constchild_process=require('child_process');
7+
const{ spawnSyncAndAssert }=require('../common/child_process');
88
constfs=require('fs');
99

1010
assert.strictEqual(process.execPath,fs.realpathSync(process.execPath));
@@ -19,8 +19,8 @@ if (process.argv[2] === 'child') {
1919
constsymlinkedNode=tmpdir.resolve('symlinked-node');
2020
fs.symlinkSync(process.execPath,symlinkedNode);
2121

22-
constproc=child_process.spawnSync(symlinkedNode,[__filename,'child']);
23-
assert.strictEqual(proc.stderr.toString(),'');
24-
assert.strictEqual(proc.stdout.toString(),`${process.execPath}\n`);
25-
assert.strictEqual(proc.status,0);
22+
spawnSyncAndAssert(symlinkedNode,[__filename,'child'],{
23+
stdout: `${process.execPath}\n`,
24+
stderr: ''
25+
});
2626
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22
require('../common');
33
constfixtures=require('../common/fixtures');
4-
constassert=require('node:assert');
5-
const{ spawnSync }=require('node:child_process');
4+
const{ spawnSyncAndExitWithoutError }=require('../common/child_process');
65
const{ test }=require('node:test');
76

87
test('mock timers do not break test timeout cleanup',async()=>{
98
constfixture=fixtures.path('test-runner','mock-timers-with-timeout.js');
10-
constcp=spawnSync(process.execPath,['--test',fixture],{
9+
spawnSyncAndExitWithoutError(process.execPath,['--test',fixture],{
1110
timeout: 30_000,
1211
});
13-
assert.strictEqual(cp.status,0,`Test failed:\nstdout: ${cp.stdout}\nstderr: ${cp.stderr}`);
1412
});

‎test/parallel/test-v8-stop-coverage.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const fixtures = require('../common/fixtures');
55
consttmpdir=require('../common/tmpdir');
66
constassert=require('assert');
77
constfs=require('fs');
8-
const{spawnSync}=require('child_process');
8+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
99

1010
common.skipIfInspectorDisabled();
1111

1212
tmpdir.refresh();
1313
constintervals=20;
1414

1515
{
16-
constoutput=spawnSync(process.execPath,[
16+
const{ child }=spawnSyncAndExitWithoutError(process.execPath,[
1717
'-r',
1818
fixtures.path('v8-coverage','stop-coverage'),
1919
'-r',
@@ -27,8 +27,7 @@ const intervals = 20;
2727
TEST_INTERVALS: intervals
2828
},
2929
});
30-
console.log(output.stderr.toString());
31-
assert.strictEqual(output.status,0);
30+
console.log(child.stderr.toString());
3231
constcoverageFiles=fs.readdirSync(tmpdir.path);
3332
assert.strictEqual(coverageFiles.length,0);
3433
}

0 commit comments

Comments
 (0)