Skip to content

Commit

Permalink
test: add subtests to test-node-run
Browse files Browse the repository at this point in the history
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: #54204
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
sungpaks authored and targos committed Aug 14, 2024
1 parent a5a320c commit 6bcbfcd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/run-script/cannot-find-script/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"types" : ""
}
1 change: 1 addition & 0 deletions test/fixtures/run-script/cannot-parse/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "non-parsable package.json"
22 changes: 22 additions & 0 deletions test/parallel/test-node-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 6bcbfcd

Please sign in to comment.