Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5a21fa4

Browse filesBrowse files
marco-ippolitotargos
authored andcommitted
test: add more coverage to node_config_file
PR-URL: #57170 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 433657d commit 5a21fa4
Copy full SHA for 5a21fa4

File tree

Expand file treeCollapse file tree

5 files changed

+60
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+60
-0
lines changed
Open diff view settings
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"inspect-port
4+
}
5+
}
Collapse file

‎test/fixtures/rc/broken.json‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{
Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"nodeOptions": "string"
3+
}
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Collapse file

‎test/parallel/test-config-file.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-config-file.js
+50Lines changed: 50 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.