Skip to content

Commit

Permalink
test: add more coverage to node_config_file
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Feb 21, 2025
1 parent 453c339 commit 83e5231
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/rc/broken-node-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"nodeOptions": {
"inspect-port
}
}
1 change: 1 addition & 0 deletions test/fixtures/rc/broken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{
3 changes: 3 additions & 0 deletions test/fixtures/rc/non-object-node-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nodeOptions": "string"
}
1 change: 1 addition & 0 deletions test/fixtures/rc/non-object-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
50 changes: 50 additions & 0 deletions test/parallel/test-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 83e5231

Please sign in to comment.