node/test/parallel/test-snapshot-child-process-sync.js
Antoine du Hamel d2af881997
Some checks failed
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Find inactive collaborators / find (push) Has been cancelled
test: use unusual chars in the path to ensure our tests are robust
PR-URL: https://github.com/nodejs/node/pull/48409
Reviewed-By: Jacob Smith <jacob@frende.me>
2024-12-30 00:17:44 +00:00

56 lines
1.4 KiB
JavaScript

'use strict';
// This tests that process.cwd() is accurate when
// restoring state from a snapshot
const { isInsideDirWithUnusualChars } = require('../common');
const { spawnSyncAndAssert } = 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',
...(isInsideDirWithUnusualChars ? [] : ['From child process execSync']),
'From child process execFileSync',
];
{
// Create the snapshot.
spawnSyncAndAssert(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot',
file,
], {
cwd: tmpdir.path,
env: { ...process.env, DIRNAME_CONTAINS_SHELL_UNSAFE_CHARS: isInsideDirWithUnusualChars ? 'TRUE' : '' },
}, {
trim: true,
stdout(output) {
assert.deepStrictEqual(output.split('\n'), expected);
return true;
}
});
}
{
spawnSyncAndAssert(process.execPath, [
'--snapshot-blob',
blobPath,
file,
], {
cwd: tmpdir.path,
env: { ...process.env, DIRNAME_CONTAINS_SHELL_UNSAFE_CHARS: isInsideDirWithUnusualChars ? 'TRUE' : '' },
}, {
trim: true,
stdout(output) {
assert.deepStrictEqual(output.split('\n'), expected);
return true;
}
});
}