Skip to content

Commit 175bddc

Browse files
committed
test: coverage for invalid use cases
No change to logic. This adds test coverage for more missing test cases. This covers the invalid cases, like invoking 'shjs' without a script name argument.
1 parent e2dded8 commit 175bddc

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

test/shjs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ function runWithShjs(name, ...args) {
1111
const execPath = process.platform === 'win32'
1212
? `${JSON.stringify(shell.config.execPath)} `
1313
: '';
14+
if (!name) {
15+
return shell.exec(`${execPath}${binPath}`, {
16+
silent: true
17+
});
18+
}
1419
const script = path.resolve(__dirname, 'resources', 'shjs', name);
1520
let argString = args.map(arg => JSON.stringify(arg)).join(' ');
1621
if (argString) {
@@ -83,3 +88,17 @@ test('disallow require-ing', t => {
8388
{ instanceOf: Error },
8489
'Executable-only module should not be required');
8590
});
91+
92+
test('Script file does not exist', t => {
93+
const result = runWithShjs('fake-file.js');
94+
t.is(result.code, 1);
95+
t.regex(result.stdout, /^ShellJS: script not found.*fake-file\.js.*/);
96+
t.falsy(result.stderr);
97+
});
98+
99+
test('Missing script file name argument', t => {
100+
const result = runWithShjs();
101+
t.is(result.code, 1);
102+
t.regex(result.stdout, /^ShellJS: missing argument \(script name\).*/);
103+
t.falsy(result.stderr);
104+
});

0 commit comments

Comments
 (0)