0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-snapshot-cwd.js
Antoine du Hamel c714cda9a7
test: add spawnSyncAndAssert util
PR-URL: https://github.com/nodejs/node/pull/52132
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2024-03-20 19:44:14 +01:00

48 lines
911 B
JavaScript

'use strict';
// This tests that process.cwd() is accurate when
// restoring state from a snapshot
require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const fs = require('fs');
tmpdir.refresh();
const blobPath = tmpdir.resolve('snapshot.blob');
const file = fixtures.path('snapshot', 'cwd.js');
const subdir = tmpdir.resolve('foo');
fs.mkdirSync(subdir);
{
// Create the snapshot.
spawnSyncAndAssert(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot',
file,
], {
cwd: tmpdir.path,
encoding: 'utf8'
}, {
status: 0,
});
}
{
spawnSyncAndAssert(process.execPath, [
'--snapshot-blob',
blobPath,
file,
], {
cwd: subdir,
encoding: 'utf8'
}, {
status: 0,
trim: true,
stdout: subdir,
});
}