Skip to content

Commit 5c7731a

Browse files
refackMylesBorins
authored andcommitted
test: split test-cli-node-options
* partitioning the subprocess groups * use `-e` instead of module * reduce maxBuffer PR-URL: #14195 Fixes: #14191 Reviewed-By: Rich Trott <[email protected]>
1 parent d2499ca commit 5c7731a

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (process.config.variables.node_without_node_options)
4+
common.skip('missing NODE_OPTIONS support');
5+
6+
// Test options specified by env variable.
7+
8+
const assert = require('assert');
9+
const exec = require('child_process').execFile;
10+
11+
common.refreshTmpDir();
12+
process.chdir(common.tmpDir);
13+
14+
disallow('--version');
15+
disallow('-v');
16+
disallow('--help');
17+
disallow('-h');
18+
disallow('--eval');
19+
disallow('-e');
20+
disallow('--print');
21+
disallow('-p');
22+
disallow('-pe');
23+
disallow('--check');
24+
disallow('-c');
25+
disallow('--interactive');
26+
disallow('-i');
27+
disallow('--v8-options');
28+
disallow('--');
29+
disallow('--no_warnings'); // Node options don't allow '_' instead of '-'.
30+
31+
function disallow(opt) {
32+
const env = Object.assign({}, process.env, { NODE_OPTIONS: opt });
33+
exec(process.execPath, { env }, common.mustCall(function(err) {
34+
const message = err.message.split(/\r?\n/)[1];
35+
const expect = `${process.execPath}: ${opt} is not allowed in NODE_OPTIONS`;
36+
37+
assert.strictEqual(err.code, 9);
38+
assert.strictEqual(message, expect);
39+
}));
40+
}

test/parallel/test-cli-node-options.js

+9-45
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,7 @@ const exec = require('child_process').execFile;
1111
common.refreshTmpDir();
1212
process.chdir(common.tmpDir);
1313

14-
disallow('--version');
15-
disallow('-v');
16-
disallow('--help');
17-
disallow('-h');
18-
disallow('--eval');
19-
disallow('-e');
20-
disallow('--print');
21-
disallow('-p');
22-
disallow('-pe');
23-
disallow('--check');
24-
disallow('-c');
25-
disallow('--interactive');
26-
disallow('-i');
27-
disallow('--v8-options');
28-
disallow('--');
29-
disallow('--no_warnings'); // Node options don't allow '_' instead of '-'.
30-
31-
function disallow(opt) {
32-
const options = { env: Object.assign({}, process.env,
33-
{ NODE_OPTIONS: opt }) };
34-
exec(process.execPath, options, common.mustCall(function(err) {
35-
const message = err.message.split(/\r?\n/)[1];
36-
const expect = `${process.execPath}: ${opt} is not allowed in NODE_OPTIONS`;
37-
38-
assert.strictEqual(err.code, 9);
39-
assert.strictEqual(message, expect);
40-
}));
41-
}
42-
43-
const printA = require.resolve('../fixtures/printA.js');
44-
45-
expect(`-r ${printA}`, 'A\nB\n');
14+
expect(`-r ${require.resolve('../fixtures/printA.js')}`, 'A\nB\n');
4615
expect('--no-deprecation', 'B\n');
4716
expect('--no-warnings', 'B\n');
4817
expect('--trace-warnings', 'B\n');
@@ -54,33 +23,28 @@ expect('--track-heap-objects', 'B\n');
5423
expect('--throw-deprecation', 'B\n');
5524
expect('--zero-fill-buffers', 'B\n');
5625
expect('--v8-pool-size=10', 'B\n');
26+
5727
if (common.hasCrypto) {
5828
expect('--use-openssl-ca', 'B\n');
5929
expect('--use-bundled-ca', 'B\n');
6030
expect('--openssl-config=_ossl_cfg', 'B\n');
6131
}
6232

6333
// V8 options
64-
expect('--abort-on-uncaught-exception', 'B\n');
65-
expect('--abort_on_uncaught_exception', 'B\n');
6634
expect('--abort_on-uncaught_exception', 'B\n');
67-
expect('--max_old_space_size=0', 'B\n');
68-
expect('--max-old_space-size=0', 'B\n');
6935
expect('--max-old-space-size=0', 'B\n');
7036

7137
function expect(opt, want) {
72-
const printB = require.resolve('../fixtures/printB.js');
73-
const argv = [printB];
38+
const argv = ['-e', 'console.log("B")'];
7439
const opts = {
7540
env: Object.assign({}, process.env, { NODE_OPTIONS: opt }),
76-
maxBuffer: 1000000000,
41+
maxBuffer: 1e6,
7742
};
78-
exec(process.execPath, argv, opts, common.mustCall(function(err, stdout) {
43+
exec(process.execPath, argv, opts, common.mustCall((err, stdout) => {
7944
assert.ifError(err);
80-
if (!RegExp(want).test(stdout)) {
81-
console.error('For %j, failed to find %j in: <\n%s\n>',
82-
opt, want, stdout);
83-
assert.fail(`Expected ${want}`);
84-
}
45+
if (stdout.includes(want)) return;
46+
47+
const o = JSON.stringify(opt);
48+
assert.fail(`For ${o}, failed to find ${want} in: <\n${stdout}\n>`);
8549
}));
8650
}

0 commit comments

Comments
 (0)