Skip to content

Commit c75bc27

Browse files
marco-ippolitoaduh95
authored andcommitted
test: add more coverage to node_config_file
PR-URL: #57170 Backport-PR-URL: #57958 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
1 parent c4d59a6 commit c75bc27

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
Lines 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+
}

test/fixtures/rc/broken.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"nodeOptions": "string"
3+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

test/parallel/test-config-file.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ test('should override env-file', async () => {
8080
test('should not override NODE_OPTIONS', async () => {
8181
const result = await spawnPromisified(process.execPath, [
8282
'--no-warnings',
83+
'--experimental-strip-types',
8384
'--experimental-config-file',
8485
fixtures.path('rc/transform-types.json'),
8586
fixtures.path('typescript/ts/transformation/test-enum.ts'),
@@ -254,3 +255,53 @@ test('should not allow users to sneak in a flag', async () => {
254255
strictEqual(result.stdout, '');
255256
strictEqual(result.code, 9);
256257
});
258+
259+
test('non object root', async () => {
260+
const result = await spawnPromisified(process.execPath, [
261+
'--no-warnings',
262+
'--experimental-config-file',
263+
fixtures.path('rc/non-object-root.json'),
264+
'-p', '"Hello, World!"',
265+
]);
266+
match(result.stderr, /Root value unexpected not an object for/);
267+
strictEqual(result.stdout, '');
268+
strictEqual(result.code, 9);
269+
});
270+
271+
test('non object node options', async () => {
272+
const result = await spawnPromisified(process.execPath, [
273+
'--no-warnings',
274+
'--experimental-config-file',
275+
fixtures.path('rc/non-object-node-options.json'),
276+
'-p', '"Hello, World!"',
277+
]);
278+
match(result.stderr, /"nodeOptions" value unexpected for/);
279+
strictEqual(result.stdout, '');
280+
strictEqual(result.code, 9);
281+
});
282+
283+
test('should throw correct error when a json is broken', async () => {
284+
const result = await spawnPromisified(process.execPath, [
285+
'--no-warnings',
286+
'--experimental-config-file',
287+
fixtures.path('rc/broken.json'),
288+
'-p', '"Hello, World!"',
289+
]);
290+
match(result.stderr, /Can't parse/);
291+
match(result.stderr, /broken\.json: invalid content/);
292+
strictEqual(result.stdout, '');
293+
strictEqual(result.code, 9);
294+
});
295+
296+
test('broken value in node_options', async () => {
297+
const result = await spawnPromisified(process.execPath, [
298+
'--no-warnings',
299+
'--experimental-config-file',
300+
fixtures.path('rc/broken-node-options.json'),
301+
'-p', '"Hello, World!"',
302+
]);
303+
match(result.stderr, /Can't parse/);
304+
match(result.stderr, /broken-node-options\.json: invalid content/);
305+
strictEqual(result.stdout, '');
306+
strictEqual(result.code, 9);
307+
});

0 commit comments

Comments
 (0)