mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
src: improve parsing of boolean options
PR-URL: https://github.com/nodejs/node/pull/58039 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
304f164f52
commit
130eaa20a4
4 files changed
+40
-2
No files matched your search
@@ -59,8 +59,12 @@ ParseResult ConfigReader::ParseNodeOptions(
|
||||
FPrintF(stderr, "Invalid value for %s\n", it->first.c_str());
|
||||
return ParseResult::InvalidContent;
|
||||
}
|
||||
node_options_.push_back(it->first + "=" +
|
||||
(result ? "true" : "false"));
|
||||
|
||||
if (result) {
|
||||
// If the value is true, we need to set the flag
|
||||
node_options_.push_back(it->first);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// String array can allow both string and array types
|
||||
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"nodeOptions": {
|
||||
"inspect": false
|
||||
}
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"nodeOptions": {
|
||||
"inspect": true
|
||||
}
|
||||
}
|
||||
@@ -232,6 +232,30 @@ test('host port flag should be parsed correctly', { skip: !process.features.insp
|
||||
strictEqual(result.code, 0);
|
||||
});
|
||||
|
||||
test('--inspect=true should be parsed correctly', { skip: !process.features.inspector }, async () => {
|
||||
const result = await spawnPromisified(process.execPath, [
|
||||
'--no-warnings',
|
||||
'--experimental-config-file',
|
||||
fixtures.path('rc/inspect-true.json'),
|
||||
'-p', 'require("node:inspector").url()',
|
||||
]);
|
||||
match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/);
|
||||
match(result.stdout, /ws:\/\/[^\s]+/);
|
||||
strictEqual(result.code, 0);
|
||||
});
|
||||
|
||||
test('--inspect=false should be parsed correctly', { skip: !process.features.inspector }, async () => {
|
||||
const result = await spawnPromisified(process.execPath, [
|
||||
'--no-warnings',
|
||||
'--experimental-config-file',
|
||||
fixtures.path('rc/inspect-false.json'),
|
||||
'-p', 'require("node:inspector").url()',
|
||||
]);
|
||||
strictEqual(result.stderr, '');
|
||||
strictEqual(result.stdout, 'undefined\n');
|
||||
strictEqual(result.code, 0);
|
||||
});
|
||||
|
||||
test('no op flag should throw', async () => {
|
||||
const result = await spawnPromisified(process.execPath, [
|
||||
'--no-warnings',
|
||||
|
||||
Reference in new issue
Block a user