From 4b7ec22720f9fbbcc12a92f70ae7ff93707b6580 Mon Sep 17 00:00:00 2001 From: Nate Fischer Date: Fri, 9 May 2025 00:38:34 -0700 Subject: [PATCH] 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. --- test/shjs.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/shjs.js b/test/shjs.js index fd9897d..90bda47 100644 --- a/test/shjs.js +++ b/test/shjs.js @@ -11,6 +11,11 @@ function runWithShjs(name, ...args) { const execPath = process.platform === 'win32' ? `${JSON.stringify(shell.config.execPath)} ` : ''; + if (!name) { + return shell.exec(`${execPath}${binPath}`, { + silent: true + }); + } const script = path.resolve(__dirname, 'resources', 'shjs', name); let argString = args.map(arg => JSON.stringify(arg)).join(' '); if (argString) { @@ -83,3 +88,17 @@ test('disallow require-ing', t => { { instanceOf: Error }, 'Executable-only module should not be required'); }); + +test('Script file does not exist', t => { + const result = runWithShjs('fake-file.js'); + t.is(result.code, 1); + t.regex(result.stdout, /^ShellJS: script not found.*fake-file\.js.*/); + t.falsy(result.stderr); +}); + +test('Missing script file name argument', t => { + const result = runWithShjs(); + t.is(result.code, 1); + t.regex(result.stdout, /^ShellJS: missing argument \(script name\).*/); + t.falsy(result.stderr); +});