src,test: fix config file parsing for flags defaulted to true · nodejs/node@ef89c2f

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -55,6 +55,10 @@ ParseResult ConfigReader::ProcessOptionValue(

5555

if (result) {

5656

// If the value is true, we need to set the flag

5757

output->push_back(option_name);

58+

} else {

59+

// Ensure negation is made putting the "--no-" prefix

60+

output->push_back("--no-" +

61+

option_name.substr(2, option_name.size() - 2));

5862

}

5963
6064

break;

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,5 @@

1+

{

2+

"nodeOptions": {

3+

"warnings": false

4+

}

5+

}

Original file line numberDiff line numberDiff line change

@@ -60,6 +60,17 @@ test('should parse boolean flag', async () => {

6060

strictEqual(result.code, 0);

6161

});

6262
63+

test('should parse boolean flag defaulted to true', async () => {

64+

const result = await spawnPromisified(process.execPath, [

65+

'--experimental-config-file',

66+

fixtures.path('rc/warnings-false.json'),

67+

'-p', 'process.emitWarning("A warning")',

68+

]);

69+

strictEqual(result.stderr, '');

70+

strictEqual(result.stdout, 'undefined\n');

71+

strictEqual(result.code, 0);

72+

});

73+
6374

test('should throw an error when a flag is declared twice', async () => {

6475

const result = await spawnPromisified(process.execPath, [

6576

'--no-warnings',