Skip to content

Commit 6bcbfcd

Browse files
sungpakstargos
authored andcommitted
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: #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>
1 parent a5a320c commit 6bcbfcd

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"types" : ""
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "non-parsable package.json"

test/parallel/test-node-run.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,26 @@ describe('node --run [command]', () => {
113113
assert.strictEqual(child.stderr, '');
114114
assert.strictEqual(child.code, 0);
115115
});
116+
117+
it('returns error on unparsable file', async () => {
118+
const child = await common.spawnPromisified(
119+
process.execPath,
120+
[ '--no-warnings', '--run', 'test'],
121+
{ cwd: fixtures.path('run-script/cannot-parse') },
122+
);
123+
assert.match(child.stderr, /Can't parse package\.json/);
124+
assert.strictEqual(child.stdout, '');
125+
assert.strictEqual(child.code, 1);
126+
});
127+
128+
it('returns error when there is no "scripts" field file', async () => {
129+
const child = await common.spawnPromisified(
130+
process.execPath,
131+
[ '--no-warnings', '--run', 'test'],
132+
{ cwd: fixtures.path('run-script/cannot-find-script') },
133+
);
134+
assert.match(child.stderr, /Can't find "scripts" field in package\.json/);
135+
assert.strictEqual(child.stdout, '');
136+
assert.strictEqual(child.code, 1);
137+
});
116138
});

0 commit comments

Comments
 (0)