Skip to content

Commit aee01ff

Browse 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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent abe9052 commit aee01ff

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines 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+
functionspawn(){
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+
}
Lines 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+
consttmpdir=require('../common/tmpdir');
9+
constfixtures=require('../common/fixtures');
10+
constassert=require('assert');
11+
12+
tmpdir.refresh();
13+
constblobPath=tmpdir.resolve('snapshot.blob');
14+
constfile=fixtures.path('snapshot','child-process-sync.js');
15+
constexpected=[
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+
returntrue;
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+
returntrue;
51+
}
52+
});
53+
}

0 commit comments

Comments
(0)