Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Node arguments to be configured
Supports `nodeArguments` configuration and `--node-arguments` on the CLI. Fixes #2090. Co-authored-by: Mark Wubben <mark@novemberborn.net>
- Loading branch information
1 parent
ad27246
commit 7b20f6c
Showing
15 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
const arrgv = require('arrgv'); | ||
|
||
function normalizeNodeArguments(fromConf = [], fromArgv = '') { | ||
let parsedArgv = []; | ||
if (fromArgv !== '') { | ||
try { | ||
parsedArgv = arrgv(fromArgv); | ||
} catch { | ||
throw new Error('Could not parse `--node-arguments` value. Make sure all strings are closed and backslashes are used correctly.'); | ||
} | ||
} | ||
|
||
return [...process.execArgv, ...fromConf, ...parsedArgv]; | ||
} | ||
|
||
module.exports = normalizeNodeArguments; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const test = require('../..'); | ||
|
||
test('exec arguments includes --throw-deprecation and --zero-fill-buffers', t => { | ||
t.plan(2); | ||
t.truthy(process.execArgv.includes('--throw-deprecation')); | ||
t.truthy(process.execArgv.includes('--zero-fill-buffers')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"ava": { | ||
"nodeArguments": [ | ||
"--require", | ||
"./setup.js" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.SETUP_CALLED = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const test = require('../../..'); | ||
|
||
test('works', t => { | ||
t.plan(2); | ||
t.truthy(global.SETUP_CALLED, 'setup variable set'); | ||
t.truthy(process.execArgv.some(argv => argv.startsWith('--require')), 'require passed'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
const {test} = require('tap'); | ||
const {execCli} = require('../helper/cli'); | ||
|
||
test('passes node arguments to workers', t => { | ||
t.plan(1); | ||
execCli(['--node-arguments="--throw-deprecation --zero-fill-buffers"', 'node-arguments.js'], | ||
(err, stdout, stderr) => t.ifError(err, null, {stdout, stderr})); | ||
}); | ||
|
||
test('reads node arguments from config', t => { | ||
t.plan(1); | ||
execCli(['test.js'], { | ||
dirname: 'fixture/node-arguments' | ||
}, (err, stdout, stderr) => t.ifError(err, null, {stdout, stderr})); | ||
}); | ||
|
||
test('detects incomplete --node-arguments', t => { | ||
t.plan(2); | ||
execCli(['--node-arguments="--foo=\'bar"', 'node-arguments.js'], (err, stdout, stderr) => { | ||
t.ok(err); | ||
t.match(stderr, /Could not parse `--node-arguments` value. Make sure all strings are closed and backslashes are used correctly./); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const {test} = require('tap'); | ||
const normalizeNodeArguments = require('../lib/node-arguments'); | ||
|
||
test('combines arguments', async t => { | ||
t.deepEqual( | ||
await normalizeNodeArguments(['--require setup.js'], '--throw-deprecation --zero-fill-buffers'), | ||
[...process.execArgv, '--require setup.js', '--throw-deprecation', '--zero-fill-buffers'] | ||
); | ||
t.end(); | ||
}); |