mono/packages/xblox/tests/unit/multi-root-wait.test.ts
2026-04-07 19:41:32 +02:00

31 lines
1015 B
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { readFile } from 'node:fs/promises';
import { executeRoots } from '../../src/engine/execute-block.js';
import { blocksFileSchema } from '../../src/schema/blocks-file.js';
import { fixture } from '../test-commons.js';
describe('multiple roots + wait', () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it('runs each top-level block in order; wait(ms) is async (5000ms)', async () => {
const raw = JSON.parse(await readFile(fixture('multi-root-wait.json'), 'utf8'));
const file = blocksFileSchema.parse(raw);
const ctx = Object.assign(Object.create(null), file.context) as { steps: string[] };
const run = executeRoots(file.roots, ctx);
await vi.advanceTimersByTimeAsync(5000);
const out = await run;
expect(out.results).toEqual(['a', undefined, 'b']);
expect(out.result).toBe('b');
expect(ctx.steps).toEqual(['a', 'b']);
});
});