Skip to content

Commit 2dd88c3

Browse files
committed
test: Add "smoke test" that all sub-modules can be loaded.
Before the test suite failed to catch a failure that would be obvious to a user that the "--help" command doesn't work, because no test checked simply that all modules could be loaded, which --help happens to do.
1 parent fcb7e83 commit 2dd88c3

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/cli-smoke.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {describe, test} from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import {execFile} from 'node:child_process';
4+
import {fileURLToPath} from 'node:url';
5+
import {dirname, join} from 'node:path';
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
const cliPath = join(__dirname, '..', 'bin', 'cli.js');
9+
10+
function runCLI(args) {
11+
return new Promise((resolve) => {
12+
execFile('node', [cliPath, ...args], {timeout: 10000}, (error, stdout, stderr) => {
13+
resolve({
14+
exitCode: error ? error.code : 0,
15+
stdout,
16+
stderr
17+
});
18+
});
19+
});
20+
}
21+
22+
describe('CLI smoke test', function () {
23+
test('--help loads all commands without errors', async function () {
24+
const result = await runCLI(['--help']);
25+
26+
assert.strictEqual(result.exitCode, 0, `CLI exited with code ${result.exitCode}.\nstderr: ${result.stderr}`);
27+
assert.strictEqual(result.stderr, '', `Unexpected stderr output: ${result.stderr}`);
28+
assert.ok(result.stdout.includes('Commands:') || result.stdout.includes('Usage:'),
29+
'Expected help output to contain usage information');
30+
});
31+
});

0 commit comments

Comments
 (0)