Files
node/test/parallel/test-snapshot-child-process-sync.js
T
Joyee Cheung 5fd5c1eca3 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>
2023-12-14 22:11:28 +01:00

54 lines
1.1 KiB
JavaScript

'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;
}
});
}