test: add more coverage to node_config_file

PR-URL: https://github.com/nodejs/node/pull/57170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
This commit is contained in:
Marco Ippolito authored and Node.js GitHub Bot committed 2025-02-24 09:54:57 +00:00
1 parent 56773ba50d
commit 044d69a0af
5 files changed
+60

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
{
"nodeOptions": {
"inspect-port
}
}
+1
View File
@@ -0,0 +1 @@
{
+3
View File
@@ -0,0 +1,3 @@
{
"nodeOptions": "string"
}
+1
View File
@@ -0,0 +1 @@
[]
+50
View File
@@ -254,3 +254,53 @@ test('should not allow users to sneak in a flag', async () => {
strictEqual(result.stdout, '');
strictEqual(result.code, 9);
});
test('non object root', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/non-object-root.json'),
'-p', '"Hello, World!"',
]);
match(result.stderr, /Root value unexpected not an object for/);
strictEqual(result.stdout, '');
strictEqual(result.code, 9);
});
test('non object node options', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/non-object-node-options.json'),
'-p', '"Hello, World!"',
]);
match(result.stderr, /"nodeOptions" value unexpected for/);
strictEqual(result.stdout, '');
strictEqual(result.code, 9);
});
test('should throw correct error when a json is broken', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/broken.json'),
'-p', '"Hello, World!"',
]);
match(result.stderr, /Can't parse/);
match(result.stderr, /broken\.json: invalid content/);
strictEqual(result.stdout, '');
strictEqual(result.code, 9);
});
test('broken value in node_options', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/broken-node-options.json'),
'-p', '"Hello, World!"',
]);
match(result.stderr, /Can't parse/);
match(result.stderr, /broken-node-options\.json: invalid content/);
strictEqual(result.stdout, '');
strictEqual(result.code, 9);
});