mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: test syncrhnous methods of child_process in snapshot
These currently work in snapshot builder scripts. Asynchronous methods are not supported yet. PR-URL: https://github.com/nodejs/node/pull/50943 Refs: https://github.com/nodejs/node/issues/50924 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
25
test/fixtures/snapshot/child-process-sync.js
vendored
Normal file
25
test/fixtures/snapshot/child-process-sync.js
vendored
Normal file
@@ -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();
|
||||
});
|
||||
}
|
||||
53
test/parallel/test-snapshot-child-process-sync.js
Normal file
53
test/parallel/test-snapshot-child-process-sync.js
Normal file
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user