Skip to content

Commit 3599eeb

Browse files
joyeecheungruyadorno
authored andcommitted
test: use spawnSyncAndExitWithoutError in sea tests
To display more information when the command fails. PR-URL: #49543 Refs: nodejs/reliability#658 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent f79b153 commit 3599eeb

2 files changed

+39
-23
lines changed

test/sequential/test-single-executable-application-snapshot-and-code-cache.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ skipIfSingleExecutableIsNotSupported();
1313

1414
const tmpdir = require('../common/tmpdir');
1515
const { copyFileSync, writeFileSync, existsSync } = require('fs');
16-
const { spawnSync } = require('child_process');
16+
const {
17+
spawnSyncAndExitWithoutError
18+
} = require('../common/child_process');
1719
const { join } = require('path');
1820
const assert = require('assert');
1921

@@ -43,21 +45,24 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' :
4345
}
4446
`);
4547

46-
let child = spawnSync(
48+
spawnSyncAndExitWithoutError(
4749
process.execPath,
4850
['--experimental-sea-config', 'sea-config.json'],
4951
{
5052
cwd: tmpdir.path
51-
});
52-
assert.match(
53-
child.stderr.toString(),
54-
/"useCodeCache" is redundant when "useSnapshot" is true/);
53+
},
54+
{
55+
stderr: /"useCodeCache" is redundant when "useSnapshot" is true/
56+
}
57+
);
5558

5659
assert(existsSync(seaPrepBlob));
5760

5861
copyFileSync(process.execPath, outputFile);
5962
injectAndCodeSign(outputFile, seaPrepBlob);
6063

61-
child = spawnSync(outputFile);
62-
assert.strictEqual(child.stdout.toString().trim(), 'Hello from snapshot');
64+
spawnSyncAndExitWithoutError(outputFile, {
65+
stdout: 'Hello from snapshot',
66+
trim: true,
67+
});
6368
}

test/sequential/test-single-executable-application-snapshot.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ skipIfSingleExecutableIsNotSupported();
1313

1414
const tmpdir = require('../common/tmpdir');
1515
const { copyFileSync, writeFileSync, existsSync } = require('fs');
16-
const { spawnSync } = require('child_process');
16+
const {
17+
spawnSyncAndExit,
18+
spawnSyncAndExitWithoutError
19+
} = require('../common/child_process');
1720
const assert = require('assert');
1821

1922
const configFile = tmpdir.resolve('sea-config.json');
@@ -32,16 +35,17 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se
3235
}
3336
`);
3437

35-
const child = spawnSync(
38+
spawnSyncAndExit(
3639
process.execPath,
3740
['--experimental-sea-config', 'sea-config.json'],
3841
{
3942
cwd: tmpdir.path
43+
},
44+
{
45+
status: 1,
46+
signal: null,
47+
stderr: /snapshot\.js does not invoke v8\.startupSnapshot\.setDeserializeMainFunction\(\)/
4048
});
41-
42-
assert.match(
43-
child.stderr.toString(),
44-
/snapshot\.js does not invoke v8\.startupSnapshot\.setDeserializeMainFunction\(\)/);
4549
}
4650

4751
{
@@ -65,24 +69,31 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se
6569
}
6670
`);
6771

68-
let child = spawnSync(
72+
spawnSyncAndExitWithoutError(
6973
process.execPath,
7074
['--experimental-sea-config', 'sea-config.json'],
7175
{
7276
cwd: tmpdir.path
77+
},
78+
{
79+
stderr: /Single executable application is an experimental feature/
7380
});
74-
assert.match(
75-
child.stderr.toString(),
76-
/Single executable application is an experimental feature/);
7781

7882
assert(existsSync(seaPrepBlob));
7983

8084
copyFileSync(process.execPath, outputFile);
8185
injectAndCodeSign(outputFile, seaPrepBlob);
8286

83-
child = spawnSync(outputFile);
84-
assert.strictEqual(child.stdout.toString().trim(), 'Hello from snapshot');
85-
assert.doesNotMatch(
86-
child.stderr.toString(),
87-
/Single executable application is an experimental feature/);
87+
spawnSyncAndExitWithoutError(
88+
outputFile,
89+
{
90+
trim: true,
91+
stdout: 'Hello from snapshot',
92+
stderr(output) {
93+
assert.doesNotMatch(
94+
output,
95+
/Single executable application is an experimental feature/);
96+
}
97+
}
98+
);
8899
}

0 commit comments

Comments
 (0)