summaryrefslogtreecommitdiff
path: root/test/parallel/test-preload-print-process-argv.js
blob: ace20dfb3947c430bbfdb8d126ca207239f0e5fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';

// This tests that process.argv is the same in the preloaded module
// and the user module.

const common = require('../common');

const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fs = require('fs');

if (!common.isMainThread) {
  common.skip('Cannot chdir to the tmp directory in workers');
}

tmpdir.refresh();

process.chdir(tmpdir.path);
fs.writeFileSync(
  'preload.js',
  'console.log(JSON.stringify(process.argv));',
  'utf-8');

fs.writeFileSync(
  'main.js',
  'console.log(JSON.stringify(process.argv));',
  'utf-8');

const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js']);

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]));