Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259/** Tests for the `describe` suite runner. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test';
await describe({ // oxlint-disable-next-line no-restricted-syntax/prefer-describe-function-ref-name -- harness self-test; the function under test IS the local binding, so `describe.name` is circular name: 'describe', children: [ it({ name: 'returns name on success', fn: async () => { const result = await describe({ name: 'inner-suite', children: [ it({ name: 'passing', fn: async () => {}, },), ], },); expect(result.name,).toBe('inner-suite',); }, },),
it({ name: 'runs children concurrently', fn: async () => { const DELAY = 100; const MAX_SEQUENTIAL = 180; const start = performance.now();
await describe({ name: 'concurrent-suite', children: [ it({ name: 'child-a', fn: async () => new Promise(resolve => { setTimeout(resolve, DELAY,); },), },), it({ name: 'child-b', fn: async () => new Promise(resolve => { setTimeout(resolve, DELAY,); },), },), ], },);
const elapsed = performance.now() - start; expect(elapsed,).toBeLessThan(MAX_SEQUENTIAL,); }, },),
it({ name: 'wraps single child failure', fn: async () => { const rejection = describe({ name: 'failing-suite', children: [ it({ name: 'bad', fn: async () => { throw new Error('boom',); }, },), ], },); await expect(rejection,).rejects.toBeInstanceOf(Error,); await expect(rejection,).rejects.toHaveProperty('message', 'failing-suite',); }, },),
it({ name: 'wraps multiple child failures in AggregateError', fn: async () => { const rejection = describe({ name: 'multi-fail-suite', children: [ it({ name: 'bad-1', fn: async () => { throw new Error('one',); }, },), it({ name: 'bad-2', fn: async () => { throw new Error('two',); }, },), ], },); await expect(rejection,).rejects.toBeInstanceOf(Error,); await expect(rejection,).rejects.toHaveProperty('message', 'multi-fail-suite',); }, },),
it({ name: 'empty name re-throws cause directly', fn: async () => { const rejection = describe({ name: '', children: [ it({ name: 'bad', fn: async () => { throw new Error('direct',); }, },), ], },); await expect(rejection,).rejects.toBeInstanceOf(Error,); await expect(rejection,).rejects.toHaveProperty('message', 'bad',); }, },),
it({ name: 'limits concurrency to the given value', fn: async () => { const DELAY = 50; const CHILD_COUNT = 4; const EXPECTED_PEAK = 2; let peak = 0; let active = 0;
await describe({ name: 'concurrency-suite', concurrency: EXPECTED_PEAK, children: Array.from({ length: CHILD_COUNT, }, (_, index,) => it({ name: `limited-${String(index,)}`, fn: async () => { active += 1; if (active > peak) peak = active;
await new Promise(resolve => { setTimeout(resolve, DELAY,); },); active -= 1; }, },),), },);
expect(peak,).toBe(EXPECTED_PEAK,); }, },),
//region inheritance
it({ name: 'nested describe inherits parent concurrency', fn: async () => { const DELAY = 30; const CHILD_COUNT = 4; const EXPECTED_PEAK = 1; let peak = 0; let active = 0;
await describe({ name: 'outer-sequential', concurrency: 1, children: [ describe({ name: 'inner-without-override', children: Array.from({ length: CHILD_COUNT, }, (_, index,) => it({ name: `inherited-${String(index,)}`, fn: async () => { active += 1; if (active > peak) peak = active;
await new Promise(resolve => { setTimeout(resolve, DELAY,); },); active -= 1; }, },),), },), ], },);
expect(peak,).toBe(EXPECTED_PEAK,); }, },),
it({ name: 'nested describe overrides inherited concurrency', fn: async () => { const DELAY = 30; const CHILD_COUNT = 4; const EXPECTED_PEAK = 4; let peak = 0; let active = 0;
await describe({ name: 'outer-sequential-override', concurrency: 1, children: [ describe({ name: 'inner-unbounded', concurrency: Number.POSITIVE_INFINITY, children: Array.from({ length: CHILD_COUNT, }, (_, index,) => it({ name: `overridden-${String(index,)}`, fn: async () => { active += 1; if (active > peak) peak = active;
await new Promise(resolve => { setTimeout(resolve, DELAY,); },); active -= 1; }, },),), },), ], },);
expect(peak,).toBe(EXPECTED_PEAK,); }, },),
//endregion inheritance
it({ name: 'respects suite timeout', fn: async () => { const DELAY = 300; const TIMEOUT = 50; const rejection = describe({ name: 'slow-suite', children: [ it({ name: 'slow', fn: async () => new Promise(resolve => { setTimeout(resolve, DELAY,); },), },), ], timeout: TIMEOUT, },); await expect(rejection,).rejects.toBeInstanceOf(Error,); }, },), ],},);