test(client): pin the exit codes of the ratchet commands

Every ratchet command hands its check to runCli, which sets the exit
code from the check's result and turns a failure of the check itself
(a missing or broken baseline, a directory that is not there) into a
printed FAIL and exit 1. The test runs runCli in a separate node
process, as CI does, and also pins that an unexpected exception still
ends the run with a non-zero code.
This commit is contained in:
Maurice
2026-10-08 12:07:45 +02:00
parent 724cdd1c0e
commit 7ac20a0b59
+19
View File
@@ -1,3 +1,6 @@
import { spawnSync } from 'node:child_process';
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { afterEach, describe, expect, it } from 'vitest';
import {
countMap,
@@ -79,4 +82,20 @@ describe('scripts/lib/ratchet', () => {
it('RATCHET-008: a file list only loses the files that stopped offending', () => {
expect(lowerList(['a', 'b', 'c'], ['c', 'a', 'new'])).toEqual(['a', 'c']);
});
it('RATCHET-009: a command exits with what its check returns, and 1 when the check itself fails', () => {
const lib = pathToFileURL(resolve('scripts/lib/ratchet.mjs')).href;
const command = (body: string) =>
spawnSync(
process.execPath,
['--input-type=module', '-e', `import { runCli, RatchetError } from '${lib}'; await runCli('lint:x', ${body})`],
{ encoding: 'utf8' }
);
expect(command('() => 0').status).toBe(0);
expect(command('async () => 1').status).toBe(1);
const broken = command("() => { throw new RatchetError('baseline gone') }");
expect(broken.status).toBe(1);
expect(broken.stderr).toContain('FAIL lint:x: baseline gone');
expect(command("() => { throw new Error('bug') }").status).not.toBe(0);
});
});