Skip to content

Commit 1f085b9

Browse files
authored
fix(test): pass exit code on test command (#62)
* test: cover exit code of bsh test * fix(test): pass exit code on test command * refactor(test): keep stdio variable name
1 parent e6e4cd4 commit 1f085b9

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎.changeset/quiet-tests-fail.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bomb.sh/tools": patch
3+
---
4+
5+
`test` CLI command respects internal `vitest` call and passes the exit code to the user.

‎src/commands/test.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { fileURLToPath } from 'node:url';
2+
import { x } from 'tinyexec';
3+
import { describe, it, expect } from 'vitest';
4+
import { createFixture } from '../test-utils/index.ts';
5+
6+
const bin = fileURLToPath(new URL('../bin.ts', import.meta.url));
7+
8+
async function runBshTest(assertion: string): Promise<number | undefined> {
9+
const fixture = await createFixture({
10+
'package.json': { name: 'test-pkg', type: 'module' },
11+
'index.test.ts': `import { it, expect } from 'vitest';\nit('case', () => { ${assertion} });\n`,
12+
});
13+
const result = await x(
14+
process.execPath,
15+
['--experimental-strip-types', '--no-warnings', bin, 'test'],
16+
{ nodeOptions: { cwd: fileURLToPath(fixture.root) }, throwOnError: false },
17+
);
18+
return result.exitCode;
19+
}
20+
21+
describe('test command', () => {
22+
it('exits non-zero when a test fails', async () => {
23+
expect(await runBshTest('expect(1).toBe(2);')).toBe(1);
24+
});
25+
26+
it('exits zero when all tests pass', async () => {
27+
expect(await runBshTest('expect(1).toBe(1);')).toBe(0);
28+
});
29+
});

‎src/commands/test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ export async function test(ctx: CommandContext) {
2020
for await (const line of stdio) {
2121
console.info(line);
2222
}
23+
if (stdio.exitCode) process.exit(stdio.exitCode);
2324
}

0 commit comments

Comments
 (0)