mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
src,test: fix config file parsing for flags defaulted to true
PR-URL: https://github.com/nodejs/node/pull/59110 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
c8d5b394e4
commit
ab694d5661
3 changed files with 20 additions and 0 deletions
|
@ -55,6 +55,10 @@ ParseResult ConfigReader::ProcessOptionValue(
|
|||
if (result) {
|
||||
// If the value is true, we need to set the flag
|
||||
output->push_back(option_name);
|
||||
} else {
|
||||
// Ensure negation is made putting the "--no-" prefix
|
||||
output->push_back("--no-" +
|
||||
option_name.substr(2, option_name.size() - 2));
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
5
test/fixtures/rc/warnings-false.json
vendored
Normal file
5
test/fixtures/rc/warnings-false.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"nodeOptions": {
|
||||
"warnings": false
|
||||
}
|
||||
}
|
|
@ -60,6 +60,17 @@ test('should parse boolean flag', async () => {
|
|||
strictEqual(result.code, 0);
|
||||
});
|
||||
|
||||
test('should parse boolean flag defaulted to true', async () => {
|
||||
const result = await spawnPromisified(process.execPath, [
|
||||
'--experimental-config-file',
|
||||
fixtures.path('rc/warnings-false.json'),
|
||||
'-p', 'process.emitWarning("A warning")',
|
||||
]);
|
||||
strictEqual(result.stderr, '');
|
||||
strictEqual(result.stdout, 'undefined\n');
|
||||
strictEqual(result.code, 0);
|
||||
});
|
||||
|
||||
test('should throw an error when a flag is declared twice', async () => {
|
||||
const result = await spawnPromisified(process.execPath, [
|
||||
'--no-warnings',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue