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 aee01ff

Browse filesBrowse files
joyeecheungRafaelGSS
authored andcommitted
test: test syncrhnous methods of child_process in snapshot
These currently work in snapshot builder scripts. Asynchronous methods are not supported yet. PR-URL: #50943 Refs: #50924 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent abe9052 commit aee01ff
Copy full SHA for aee01ff

File tree

Expand file treeCollapse file tree

2 files changed

+78
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+78
-0
lines changed
Open diff view settings
Collapse file
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const {
4+
setDeserializeMainFunction,
5+
isBuildingSnapshot
6+
} = require('v8').startupSnapshot;
7+
8+
function spawn() {
9+
const { spawnSync, execFileSync, execSync } = require('child_process');
10+
spawnSync(process.execPath, [ __filename, 'spawnSync' ], { stdio: 'inherit' });
11+
execSync(`"${process.execPath}" "${__filename}" "execSync"`, { stdio: 'inherit' });
12+
execFileSync(process.execPath, [ __filename, 'execFileSync' ], { stdio: 'inherit' });
13+
}
14+
15+
if (process.argv[2] !== undefined) {
16+
console.log('From child process', process.argv[2]);
17+
} else {
18+
spawn();
19+
}
20+
21+
if (isBuildingSnapshot()) {
22+
setDeserializeMainFunction(() => {
23+
spawn();
24+
});
25+
}
Collapse file
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
// This tests that process.cwd() is accurate when
4+
// restoring state from a snapshot
5+
6+
require('../common');
7+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
8+
const tmpdir = require('../common/tmpdir');
9+
const fixtures = require('../common/fixtures');
10+
const assert = require('assert');
11+
12+
tmpdir.refresh();
13+
const blobPath = tmpdir.resolve('snapshot.blob');
14+
const file = fixtures.path('snapshot', 'child-process-sync.js');
15+
const expected = [
16+
'From child process spawnSync',
17+
'From child process execSync',
18+
'From child process execFileSync',
19+
];
20+
21+
{
22+
// Create the snapshot.
23+
spawnSyncAndExitWithoutError(process.execPath, [
24+
'--snapshot-blob',
25+
blobPath,
26+
'--build-snapshot',
27+
file,
28+
], {
29+
cwd: tmpdir.path,
30+
}, {
31+
trim: true,
32+
stdout(output) {
33+
assert.deepStrictEqual(output.split('\n'), expected);
34+
return true;
35+
}
36+
});
37+
}
38+
39+
{
40+
spawnSyncAndExitWithoutError(process.execPath, [
41+
'--snapshot-blob',
42+
blobPath,
43+
file,
44+
], {
45+
cwd: tmpdir.path,
46+
}, {
47+
trim: true,
48+
stdout(output) {
49+
assert.deepStrictEqual(output.split('\n'), expected);
50+
return true;
51+
}
52+
});
53+
}

0 commit comments

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