diff --git a/test/fixtures/rc/broken-node-options.json b/test/fixtures/rc/broken-node-options.json new file mode 100644 index 00000000000..beea3f7143f --- /dev/null +++ b/test/fixtures/rc/broken-node-options.json @@ -0,0 +1,5 @@ +{ + "nodeOptions": { + "inspect-port + } +} diff --git a/test/fixtures/rc/broken.json b/test/fixtures/rc/broken.json new file mode 100644 index 00000000000..98232c64fce --- /dev/null +++ b/test/fixtures/rc/broken.json @@ -0,0 +1 @@ +{ diff --git a/test/fixtures/rc/non-object-node-options.json b/test/fixtures/rc/non-object-node-options.json new file mode 100644 index 00000000000..5dc596e4673 --- /dev/null +++ b/test/fixtures/rc/non-object-node-options.json @@ -0,0 +1,3 @@ +{ + "nodeOptions": "string" +} diff --git a/test/fixtures/rc/non-object-root.json b/test/fixtures/rc/non-object-root.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/test/fixtures/rc/non-object-root.json @@ -0,0 +1 @@ +[] diff --git a/test/parallel/test-config-file.js b/test/parallel/test-config-file.js index 49960e262ba..a53de3be8ed 100644 --- a/test/parallel/test-config-file.js +++ b/test/parallel/test-config-file.js @@ -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); +});