Skip to content

Commit 044d69a

Browse files
marco-ippolitonodejs-github-bot
authored andcommitted
test: add more coverage to node_config_file
PR-URL: #57170 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
1 parent 56773ba commit 044d69a

5 files changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"inspect-port
4+
}
5+
}

test/fixtures/rc/broken.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"nodeOptions": "string"
3+
}

test/fixtures/rc/non-object-root.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

test/parallel/test-config-file.js

+50
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,53 @@ test('should not allow users to sneak in a flag', async () => {
254254
strictEqual(result.stdout, '');
255255
strictEqual(result.code, 9);
256256
});
257+
258+
test('non object root', async () => {
259+
const result = await spawnPromisified(process.execPath, [
260+
'--no-warnings',
261+
'--experimental-config-file',
262+
fixtures.path('rc/non-object-root.json'),
263+
'-p', '"Hello, World!"',
264+
]);
265+
match(result.stderr, /Root value unexpected not an object for/);
266+
strictEqual(result.stdout, '');
267+
strictEqual(result.code, 9);
268+
});
269+
270+
test('non object node options', async () => {
271+
const result = await spawnPromisified(process.execPath, [
272+
'--no-warnings',
273+
'--experimental-config-file',
274+
fixtures.path('rc/non-object-node-options.json'),
275+
'-p', '"Hello, World!"',
276+
]);
277+
match(result.stderr, /"nodeOptions" value unexpected for/);
278+
strictEqual(result.stdout, '');
279+
strictEqual(result.code, 9);
280+
});
281+
282+
test('should throw correct error when a json is broken', async () => {
283+
const result = await spawnPromisified(process.execPath, [
284+
'--no-warnings',
285+
'--experimental-config-file',
286+
fixtures.path('rc/broken.json'),
287+
'-p', '"Hello, World!"',
288+
]);
289+
match(result.stderr, /Can't parse/);
290+
match(result.stderr, /broken\.json: invalid content/);
291+
strictEqual(result.stdout, '');
292+
strictEqual(result.code, 9);
293+
});
294+
295+
test('broken value in node_options', async () => {
296+
const result = await spawnPromisified(process.execPath, [
297+
'--no-warnings',
298+
'--experimental-config-file',
299+
fixtures.path('rc/broken-node-options.json'),
300+
'-p', '"Hello, World!"',
301+
]);
302+
match(result.stderr, /Can't parse/);
303+
match(result.stderr, /broken-node-options\.json: invalid content/);
304+
strictEqual(result.stdout, '');
305+
strictEqual(result.code, 9);
306+
});

0 commit comments

Comments
 (0)