mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 09:52:21 +00:00

Use the `cwd` option for child_process instead of `process.chdir()` to allow tests to work with worker threads. PR-URL: https://github.com/nodejs/node/pull/26453 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
36 lines
921 B
JavaScript
36 lines
921 B
JavaScript
'use strict';
|
|
|
|
// This tests that process.argv is the same in the preloaded module
|
|
// and the user module.
|
|
|
|
require('../common');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
const assert = require('assert');
|
|
const { join } = require('path');
|
|
const { spawnSync } = require('child_process');
|
|
const fs = require('fs');
|
|
|
|
tmpdir.refresh();
|
|
|
|
fs.writeFileSync(
|
|
join(tmpdir.path, 'preload.js'),
|
|
'console.log(JSON.stringify(process.argv));',
|
|
'utf-8');
|
|
|
|
fs.writeFileSync(
|
|
join(tmpdir.path, 'main.js'),
|
|
'console.log(JSON.stringify(process.argv));',
|
|
'utf-8');
|
|
|
|
const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js'],
|
|
{ cwd: tmpdir.path });
|
|
|
|
if (child.status !== 0) {
|
|
console.log(child.stderr.toString());
|
|
assert.strictEqual(child.status, 0);
|
|
}
|
|
|
|
const lines = child.stdout.toString().trim().split('\n');
|
|
assert.deepStrictEqual(JSON.parse(lines[0]), JSON.parse(lines[1]));
|