test: add more coverage to node_config_file · nodejs/node@5a21fa4
@@ -254,3 +254,53 @@ test('should not allow users to sneak in a flag', async () => {
254254strictEqual(result.stdout, '');
255255strictEqual(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+});