storebound/tests/ci-status.test.ts

12 lines
950 B
TypeScript

import { expect, test } from 'bun:test';
import { testState } from '../tools/ci-status';
const t = (name: string, status: string, run: number, sha: string) => ({ id: 1, name, run_number: run, workflow_id: 'ci.yml', head_sha: sha, status });
const url = (n: number) => `run/${n}`;
test('background test state: newest commit with test jobs; a cancelled run falls back to the older commit', () => {
expect(testState([t('ci', 'success', 2, 'b'), t('acceptance (bun)', 'failure', 2, 'b'), t('linux', 'success', 2, 'b')], ['b'], url)).toEqual({ sha: 'b', run: 'run/2', state: 'red', failed: ['acceptance (bun)'], running: [] });
expect(testState([t('ci', 'cancelled', 3, 'c'), t('ci', 'success', 2, 'b')], ['c', 'b'], url).state).toBe('green');
expect(testState([t('ci', 'running', 3, 'c')], ['c'], url)).toMatchObject({ state: 'running', running: ['ci'] });
expect(testState([t('linux', 'success', 3, 'c')], ['c'], url).state).toBe('none');
});