diff --git a/.changeset/quiet-tests-fail.md b/.changeset/quiet-tests-fail.md new file mode 100644 index 0000000..0221b52 --- /dev/null +++ b/.changeset/quiet-tests-fail.md @@ -0,0 +1,5 @@ +--- +"@bomb.sh/tools": patch +--- + +`test` CLI command respects internal `vitest` call and passes the exit code to the user. diff --git a/src/commands/test.test.ts b/src/commands/test.test.ts new file mode 100644 index 0000000..6bb6465 --- /dev/null +++ b/src/commands/test.test.ts @@ -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 { + 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); + }); +}); diff --git a/src/commands/test.ts b/src/commands/test.ts index 9a71fe3..dfa00fd 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -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); }