diff --git a/test/fixtures/run-script/cannot-find-script/package.json b/test/fixtures/run-script/cannot-find-script/package.json new file mode 100644 index 00000000000000..73ddbdfc179e2e --- /dev/null +++ b/test/fixtures/run-script/cannot-find-script/package.json @@ -0,0 +1,3 @@ +{ + "types" : "" +} diff --git a/test/fixtures/run-script/cannot-parse/package.json b/test/fixtures/run-script/cannot-parse/package.json new file mode 100644 index 00000000000000..53ef3e3a3e4099 --- /dev/null +++ b/test/fixtures/run-script/cannot-parse/package.json @@ -0,0 +1 @@ +{ "non-parsable package.json" diff --git a/test/parallel/test-node-run.js b/test/parallel/test-node-run.js index 75f9343c2aa716..5f9b95d2ef9148 100644 --- a/test/parallel/test-node-run.js +++ b/test/parallel/test-node-run.js @@ -113,4 +113,26 @@ describe('node --run [command]', () => { assert.strictEqual(child.stderr, ''); assert.strictEqual(child.code, 0); }); + + it('returns error on unparsable file', async () => { + const child = await common.spawnPromisified( + process.execPath, + [ '--no-warnings', '--run', 'test'], + { cwd: fixtures.path('run-script/cannot-parse') }, + ); + assert.match(child.stderr, /Can't parse package\.json/); + assert.strictEqual(child.stdout, ''); + assert.strictEqual(child.code, 1); + }); + + it('returns error when there is no "scripts" field file', async () => { + const child = await common.spawnPromisified( + process.execPath, + [ '--no-warnings', '--run', 'test'], + { cwd: fixtures.path('run-script/cannot-find-script') }, + ); + assert.match(child.stderr, /Can't find "scripts" field in package\.json/); + assert.strictEqual(child.stdout, ''); + assert.strictEqual(child.code, 1); + }); });