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:
Edy Silva authored and Antoine du Hamel committed 2025-07-21 10:59:02 +02:00
1 parent 1a44265810
commit ef89c2fac9
3 files changed
+20

No files matched your search

+4
View File
@@ -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
View File
@@ -0,0 +1,5 @@
{
"nodeOptions": {
"warnings": false
}
}
+11
View File
@@ -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',