Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c714cda

Browse filesBrowse files
authored
test: add spawnSyncAndAssert util
PR-URL: #52132 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent f69946b commit c714cda
Copy full SHA for c714cda
Expand file treeCollapse file tree

21 files changed

+77
-72
lines changed
Open diff view settings
Collapse file

‎test/common/README.md‎

Copy file name to clipboardExpand all lines: test/common/README.md
+7-3Lines changed: 7 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ gathering more information about test failures coming from child processes.
7070
* `stderr` [\<string>][<string>] The output from the child process to stderr.
7171
* `stdout` [\<string>][<string>] The output from the child process to stdout.
7272

73-
### `spawnSyncAndExitWithoutError(command[, args][, spawnOptions], expectations)`
73+
### `spawnSyncAndExitWithoutError(command[, args][, spawnOptions])`
7474

7575
Similar to `expectSyncExit()` with the `status` expected to be 0 and
76-
`signal` expected to be `null`. Any other optional options are passed
77-
into `expectSyncExit()`.
76+
`signal` expected to be `null`.
77+
78+
### `spawnSyncAndAssert(command[, args][, spawnOptions], expectations)`
79+
80+
Similar to `spawnSyncAndExitWithoutError()`, but with an additional
81+
`expectations` parameter.
7882

7983
## Common Module API
8084

Collapse file

‎test/common/child_process.js‎

Copy file name to clipboardExpand all lines: test/common/child_process.js
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,15 @@ function spawnSyncAndExit(...args) {
119119
}
120120

121121
function spawnSyncAndExitWithoutError(...args) {
122-
const spawnArgs = args.slice(0, args.length);
123-
const expectations = args[args.length - 1];
124-
const child = spawnSync(...spawnArgs);
122+
return expectSyncExit(spawnSync(...args), {
123+
status: 0,
124+
signal: null,
125+
});
126+
}
127+
128+
function spawnSyncAndAssert(...args) {
129+
const expectations = args.pop();
130+
const child = spawnSync(...args);
125131
return expectSyncExit(child, {
126132
status: 0,
127133
signal: null,
@@ -134,6 +140,7 @@ module.exports = {
134140
logAfterTime,
135141
kExpiringChildRunTime,
136142
kExpiringParentTimer,
143+
spawnSyncAndAssert,
137144
spawnSyncAndExit,
138145
spawnSyncAndExitWithoutError,
139146
};
Collapse file

‎test/common/sea.js‎

Copy file name to clipboardExpand all lines: test/common/sea.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow
9292

9393
if (process.platform === 'darwin') {
9494
try {
95-
spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ], {});
96-
spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ], {});
95+
spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ]);
96+
spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ]);
9797
} catch (e) {
9898
const message = `Cannot sign ${targetExecutable}: ${inspect(e)}`;
9999
if (verifyWorkflow) {
@@ -104,7 +104,7 @@ function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow
104104
console.log(`Signed ${targetExecutable}`);
105105
} else if (process.platform === 'win32') {
106106
try {
107-
spawnSyncAndExitWithoutError('where', [ 'signtool' ], {});
107+
spawnSyncAndExitWithoutError('where', [ 'signtool' ]);
108108
} catch (e) {
109109
const message = `Cannot find signtool: ${inspect(e)}`;
110110
if (verifyWorkflow) {
@@ -114,8 +114,8 @@ function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow
114114
}
115115
let stderr;
116116
try {
117-
({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {}));
118-
spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {});
117+
({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ]));
118+
spawnSyncAndExitWithoutError('signtool', ['verify', '/pa', 'SHA256', targetExecutable]);
119119
} catch (e) {
120120
const message = `Cannot sign ${targetExecutable}: ${inspect(e)}\n${stderr}`;
121121
if (verifyWorkflow) {
Collapse file

‎test/common/wasi.js‎

Copy file name to clipboardExpand all lines: test/common/wasi.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test version set to preview1
22
'use strict';
33

4-
const { spawnSyncAndExitWithoutError } = require('./child_process');
4+
const { spawnSyncAndAssert } = require('./child_process');
55
const fixtures = require('./fixtures');
66
const childPath = fixtures.path('wasi-preview-1.js');
77

@@ -15,7 +15,7 @@ function testWasiPreview1(args, spawnArgs = {}, expectations = {}) {
1515
spawnArgs.env = newEnv;
1616

1717
console.log('Testing with --turbo-fast-api-calls:', ...args);
18-
spawnSyncAndExitWithoutError(
18+
spawnSyncAndAssert(
1919
process.execPath, [
2020
'--turbo-fast-api-calls',
2121
childPath,
@@ -26,7 +26,7 @@ function testWasiPreview1(args, spawnArgs = {}, expectations = {}) {
2626
);
2727

2828
console.log('Testing with --no-turbo-fast-api-calls:', ...args);
29-
spawnSyncAndExitWithoutError(
29+
spawnSyncAndAssert(
3030
process.execPath,
3131
[
3232
'--no-turbo-fast-api-calls',
Collapse file

‎test/embedding/test-embedding.js‎

Copy file name to clipboardExpand all lines: test/embedding/test-embedding.js
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fixtures = require('../common/fixtures');
44
const tmpdir = require('../common/tmpdir');
55
const assert = require('assert');
66
const {
7+
spawnSyncAndAssert,
78
spawnSyncAndExit,
89
spawnSyncAndExitWithoutError,
910
} = require('../common/child_process');
@@ -23,15 +24,15 @@ function resolveBuiltBinary(binary) {
2324

2425
const binary = resolveBuiltBinary('embedtest');
2526

26-
spawnSyncAndExitWithoutError(
27+
spawnSyncAndAssert(
2728
binary,
2829
['console.log(42)'],
2930
{
3031
trim: true,
3132
stdout: '42',
3233
});
3334

34-
spawnSyncAndExitWithoutError(
35+
spawnSyncAndAssert(
3536
binary,
3637
['console.log(embedVars.nön_ascıı)'],
3738
{
@@ -111,9 +112,8 @@ for (const extraSnapshotArgs of [
111112
spawnSyncAndExitWithoutError(
112113
binary,
113114
[ '--', ...buildSnapshotArgs ],
114-
{ cwd: tmpdir.path },
115-
{});
116-
spawnSyncAndExitWithoutError(
115+
{ cwd: tmpdir.path });
116+
spawnSyncAndAssert(
117117
binary,
118118
[ '--', ...runSnapshotArgs ],
119119
{ cwd: tmpdir.path },
@@ -145,11 +145,9 @@ for (const extraSnapshotArgs of [
145145
spawnSyncAndExitWithoutError(
146146
binary,
147147
[ '--', ...buildSnapshotArgs ],
148-
{ cwd: tmpdir.path },
149-
{});
148+
{ cwd: tmpdir.path });
150149
spawnSyncAndExitWithoutError(
151150
binary,
152151
[ '--', ...runEmbeddedArgs ],
153-
{ cwd: tmpdir.path },
154-
{});
152+
{ cwd: tmpdir.path });
155153
}
Collapse file

‎test/parallel/test-error-prepare-stack-trace.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-error-prepare-stack-trace.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ if (process.argv[2] !== 'child') {
2626
// enabled.
2727
spawnSyncAndExitWithoutError(
2828
process.execPath,
29-
['--enable-source-maps', __filename, 'child'],
30-
{});
29+
['--enable-source-maps', __filename, 'child']);
3130
}
Collapse file

‎test/parallel/test-snapshot-api.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-snapshot-api.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require('../common');
66
const assert = require('assert');
77
const tmpdir = require('../common/tmpdir');
88
const fixtures = require('../common/fixtures');
9-
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
9+
const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process');
1010
const fs = require('fs');
1111

1212
const v8 = require('v8');
@@ -41,7 +41,7 @@ const entry = fixtures.path('snapshot', 'v8-startup-snapshot-api.js');
4141
}
4242

4343
{
44-
spawnSyncAndExitWithoutError(process.execPath, [
44+
spawnSyncAndAssert(process.execPath, [
4545
'--snapshot-blob',
4646
blobPath,
4747
'book1',
Collapse file

‎test/parallel/test-snapshot-basic.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-snapshot-basic.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const assert = require('assert');
88
const tmpdir = require('../common/tmpdir');
99
const fixtures = require('../common/fixtures');
1010
const {
11-
spawnSyncAndExitWithoutError,
11+
spawnSyncAndAssert,
1212
spawnSyncAndExit,
13+
spawnSyncAndExitWithoutError,
1314
} = require('../common/child_process');
1415
const fs = require('fs');
1516

@@ -65,7 +66,7 @@ const blobPath = tmpdir.resolve('my-snapshot.blob');
6566

6667
{
6768
// Check --help.
68-
spawnSyncAndExitWithoutError(process.execPath, [
69+
spawnSyncAndAssert(process.execPath, [
6970
'--snapshot-blob',
7071
blobPath,
7172
'--help',
@@ -78,7 +79,7 @@ const blobPath = tmpdir.resolve('my-snapshot.blob');
7879

7980
{
8081
// Check -c.
81-
spawnSyncAndExitWithoutError(process.execPath, [
82+
spawnSyncAndAssert(process.execPath, [
8283
'--snapshot-blob',
8384
blobPath,
8485
'-c',
Collapse file

‎test/parallel/test-snapshot-child-process-sync.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-snapshot-child-process-sync.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// restoring state from a snapshot
55

66
require('../common');
7-
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
7+
const { spawnSyncAndAssert } = require('../common/child_process');
88
const tmpdir = require('../common/tmpdir');
99
const fixtures = require('../common/fixtures');
1010
const assert = require('assert');
@@ -20,7 +20,7 @@ const expected = [
2020

2121
{
2222
// Create the snapshot.
23-
spawnSyncAndExitWithoutError(process.execPath, [
23+
spawnSyncAndAssert(process.execPath, [
2424
'--snapshot-blob',
2525
blobPath,
2626
'--build-snapshot',
@@ -37,7 +37,7 @@ const expected = [
3737
}
3838

3939
{
40-
spawnSyncAndExitWithoutError(process.execPath, [
40+
spawnSyncAndAssert(process.execPath, [
4141
'--snapshot-blob',
4242
blobPath,
4343
file,
Collapse file

‎test/parallel/test-snapshot-config.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-snapshot-config.js
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
require('../common');
66
const assert = require('assert');
77
const {
8-
spawnSyncAndExitWithoutError,
8+
spawnSyncAndAssert,
99
spawnSyncAndExit,
10+
spawnSyncAndExitWithoutError,
1011
} = require('../common/child_process');
1112
const tmpdir = require('../common/tmpdir');
1213
const fixtures = require('../common/fixtures');
@@ -84,7 +85,7 @@ let sizeWithCache;
8485
configPath,
8586
], {
8687
cwd: tmpdir.path
87-
}, {});
88+
});
8889
const stats = fs.statSync(blobPath);
8990
assert(stats.isFile());
9091
sizeWithCache = stats.size;
@@ -115,14 +116,14 @@ let sizeWithoutCache;
115116
NODE_DEBUG_NATIVE: 'CODE_CACHE'
116117
},
117118
cwd: tmpdir.path
118-
}, {});
119+
});
119120
const stats = fs.statSync(blobPath);
120121
assert(stats.isFile());
121122
sizeWithoutCache = stats.size;
122123
assert(sizeWithoutCache < sizeWithCache,
123124
`sizeWithoutCache = ${sizeWithoutCache} >= sizeWithCache ${sizeWithCache}`);
124125
// Check the snapshot.
125-
spawnSyncAndExitWithoutError(process.execPath, [
126+
spawnSyncAndAssert(process.execPath, [
126127
'--snapshot-blob',
127128
blobPath,
128129
checkFile,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.