test: add subtests to test-node-run

Added two subtests to test-node-run. First one is about unparsable
package.json file, and the second one is about there is no "script"
fields in package.json

PR-URL: https://github.com/nodejs/node/pull/54204
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
sungpaks 2024-08-06 15:47:52 +00:00 committed by GitHub
parent e1e7a417da
commit 359b4284bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{
"types" : ""
}

View File

@ -0,0 +1 @@
{ "non-parsable package.json"

View File

@ -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);
});
});