mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01: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
|
|
@ -55,6 +55,10 @@ ParseResult ConfigReader::ProcessOptionValue(
|
||||||
if (result) {
|
if (result) {
|
||||||
// If the value is true, we need to set the flag
|
// If the value is true, we need to set the flag
|
||||||
output->push_back(option_name);
|
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;
|
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);
|
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 () => {
|
test('should throw an error when a flag is declared twice', async () => {
|
||||||
const result = await spawnPromisified(process.execPath, [
|
const result = await spawnPromisified(process.execPath, [
|
||||||
'--no-warnings',
|
'--no-warnings',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user