Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-tests-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bomb.sh/tools": patch
---

`test` CLI command respects internal `vitest` call and passes the exit code to the user.
29 changes: 29 additions & 0 deletions src/commands/test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { fileURLToPath } from 'node:url';
import { x } from 'tinyexec';
import { describe, it, expect } from 'vitest';
import { createFixture } from '../test-utils/index.ts';

const bin = fileURLToPath(new URL('../bin.ts', import.meta.url));

async function runBshTest(assertion: string): Promise<number | undefined> {
const fixture = await createFixture({
'package.json': { name: 'test-pkg', type: 'module' },
'index.test.ts': `import { it, expect } from 'vitest';\nit('case', () => { ${assertion} });\n`,
});
const result = await x(
process.execPath,
['--experimental-strip-types', '--no-warnings', bin, 'test'],
{ nodeOptions: { cwd: fileURLToPath(fixture.root) }, throwOnError: false },
);
return result.exitCode;
}

describe('test command', () => {
it('exits non-zero when a test fails', async () => {
expect(await runBshTest('expect(1).toBe(2);')).toBe(1);
});

it('exits zero when all tests pass', async () => {
expect(await runBshTest('expect(1).toBe(1);')).toBe(0);
});
});
1 change: 1 addition & 0 deletions src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export async function test(ctx: CommandContext) {
for await (const line of stdio) {
console.info(line);
}
if (stdio.exitCode) process.exit(stdio.exitCode);
}
Loading