2019-02-08 11:22:37 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// This tests that process.argv is the same in the preloaded module
|
|
|
|
// and the user module.
|
|
|
|
|
2019-03-05 08:56:16 -05:00
|
|
|
require('../common');
|
2019-02-08 11:22:37 +08:00
|
|
|
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { spawnSync } = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
tmpdir.refresh();
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
2023-08-15 22:45:44 +09:00
|
|
|
tmpdir.resolve('preload.js'),
|
2019-02-08 11:22:37 +08:00
|
|
|
'console.log(JSON.stringify(process.argv));',
|
|
|
|
'utf-8');
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
2023-08-15 22:45:44 +09:00
|
|
|
tmpdir.resolve('main.js'),
|
2019-02-08 11:22:37 +08:00
|
|
|
'console.log(JSON.stringify(process.argv));',
|
|
|
|
'utf-8');
|
|
|
|
|
2019-03-05 08:56:16 -05:00
|
|
|
const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js'],
|
|
|
|
{ cwd: tmpdir.path });
|
2019-02-08 11:22:37 +08:00
|
|
|
|
|
|
|
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]));
|