1'use strict';
2
3// This tests that process.argv is the same in the preloaded module
4// and the user module.
5
6require('../common');
7
8const tmpdir = require('../common/tmpdir');
9const assert = require('assert');
10const { join } = require('path');
11const { spawnSync } = require('child_process');
12const fs = require('fs');
13
14tmpdir.refresh();
15
16fs.writeFileSync(
17  join(tmpdir.path, 'preload.js'),
18  'console.log(JSON.stringify(process.argv));',
19  'utf-8');
20
21fs.writeFileSync(
22  join(tmpdir.path, 'main.js'),
23  'console.log(JSON.stringify(process.argv));',
24  'utf-8');
25
26const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js'],
27                        { cwd: tmpdir.path });
28
29if (child.status !== 0) {
30  console.log(child.stderr.toString());
31  assert.strictEqual(child.status, 0);
32}
33
34const lines = child.stdout.toString().trim().split('\n');
35assert.deepStrictEqual(JSON.parse(lines[0]), JSON.parse(lines[1]));
36