-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
abe9052
commit aee01ff
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const { | ||
setDeserializeMainFunction, | ||
isBuildingSnapshot | ||
} = require('v8').startupSnapshot; | ||
|
||
function spawn() { | ||
const { spawnSync, execFileSync, execSync } = require('child_process'); | ||
spawnSync(process.execPath, [ __filename, 'spawnSync' ], { stdio: 'inherit' }); | ||
execSync(`"${process.execPath}" "${__filename}" "execSync"`, { stdio: 'inherit' }); | ||
execFileSync(process.execPath, [ __filename, 'execFileSync' ], { stdio: 'inherit' }); | ||
} | ||
|
||
if (process.argv[2] !== undefined) { | ||
console.log('From child process', process.argv[2]); | ||
} else { | ||
spawn(); | ||
} | ||
|
||
if (isBuildingSnapshot()) { | ||
setDeserializeMainFunction(() => { | ||
spawn(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
// This tests that process.cwd() is accurate when | ||
// restoring state from a snapshot | ||
|
||
require('../common'); | ||
const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
|
||
tmpdir.refresh(); | ||
const blobPath = tmpdir.resolve('snapshot.blob'); | ||
const file = fixtures.path('snapshot', 'child-process-sync.js'); | ||
const expected = [ | ||
'From child process spawnSync', | ||
'From child process execSync', | ||
'From child process execFileSync', | ||
]; | ||
|
||
{ | ||
// Create the snapshot. | ||
spawnSyncAndExitWithoutError(process.execPath, [ | ||
'--snapshot-blob', | ||
blobPath, | ||
'--build-snapshot', | ||
file, | ||
], { | ||
cwd: tmpdir.path, | ||
}, { | ||
trim: true, | ||
stdout(output) { | ||
assert.deepStrictEqual(output.split('\n'), expected); | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
{ | ||
spawnSyncAndExitWithoutError(process.execPath, [ | ||
'--snapshot-blob', | ||
blobPath, | ||
file, | ||
], { | ||
cwd: tmpdir.path, | ||
}, { | ||
trim: true, | ||
stdout(output) { | ||
assert.deepStrictEqual(output.split('\n'), expected); | ||
return true; | ||
} | ||
}); | ||
} |