An open source design system that's fully customizable and agent ready
TypeScript
test(cli): stabilize the vitest suite to kill spawn-test flakiness (#4431)
Joey1e0a706c8fd1
diff --git a/internal/test-utils/src/setup.ts b/internal/test-utils/src/setup.tsindex cfcfe9cfde..20e0100144 100644--- a/internal/test-utils/src/setup.ts+++ b/internal/test-utils/src/setup.ts@@ -11,6 +11,19 @@/// <reference types="@testing-library/jest-dom" />import '@testing-library/jest-dom/vitest';+import {configure} from '@testing-library/react';++// Text queries (getByText/findByText/…) target VISIBLE text. Astryx's+// `useAnnounce` renders a visually-hidden aria-live region+// (`data-astryx-live-region`) that MIRRORS visible labels for screen readers —+// used by ~17 components (Calendar, Pagination, Typeahead, Switch, …). So a bare+// `getByText('January 2026')` can match BOTH the label and its announcement, and+// whether both are present is timing-dependent (the region updates on an effect+// after interaction). That makes such assertions liable to flaky "found multiple+// elements" failures under load. Ignore live regions in text matching (tests+// that assert an announcement query the region directly, e.g. by role="status").+// Keeps the jsdom defaults (script, style).+configure({defaultIgnore: 'script, style, [data-astryx-live-region]'});// Polyfill for matchMedia (not supported in jsdom)if (typeof window !== 'undefined' && !window.matchMedia) {diff --git a/scripts/build-css.test.mjs b/scripts/build-css.test.mjsindex 8bfe3f838d..06a7c93208 100644--- a/scripts/build-css.test.mjs+++ b/scripts/build-css.test.mjs@@ -12,7 +12,7 @@ import {describe, it, expect, beforeAll} from 'vitest';import fs from 'node:fs/promises';import path from 'node:path';import {fileURLToPath} from 'node:url';-import {execSync} from 'node:child_process';+import {ensureCoreBuilt} from '../packages/cli/cli/commands/ensure-core-built.mjs';const __dirname = path.dirname(fileURLToPath(import.meta.url));const ROOT = path.resolve(__dirname, '..');@@ -49,8 +49,13 @@ describe('build-css astryx.css', () => {let astryxCss;beforeAll(async () => {- console.log('Running pnpm build...');- execSync('pnpm build', {cwd: ROOT, stdio: 'pipe', timeout: 120_000});+ // Core — including its `build:css` step that emits astryx.css — is built+ // ONCE by the node project's globalSetup (vitest.global-setup.node.mjs →+ // ensureCoreBuilt). This call is an idempotent, race-safe no-op that just+ // guarantees dist is present. Do NOT run a full `pnpm build` here: it+ // launched a whole-monorepo build (all cores, ~2min) concurrently with the+ // rest of the suite, starving other tests into nondeterministic timeouts.+ ensureCoreBuilt();astryxCss = await fs.readFile(path.join(CORE_DIST, 'astryx.css'), 'utf8');}, 180_000);diff --git a/vitest.config.ts b/vitest.config.tsindex ff315a9fc0..074b405f89 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -110,6 +110,16 @@ export default defineConfig({name: 'node',globals: true,environment: 'node',+ // Several CLI suites spawn a fresh `node bin/astryx.mjs` per assertion+ // (real process boundary). Under the forks pool these cold-starts can+ // run long on a busy box; the 5s default testTimeout then flakes+ // non-deterministically (every failure was "timed out in 5000ms").+ // Give spawn-backed tests + their fixture hooks a real budget so a+ // slow-but-correct run never trips the timeout. (The other half of the+ // fix was removing a full `pnpm build` that scripts/build-css.test ran+ // in-suite, which hogged every core and starved these — see that file.)+ testTimeout: 30_000,+ hookTimeout: 30_000,// Build @astryxdesign/core once before workers fork. The build-theme// suites need a compiled core; doing it here (not per-suite in// parallel workers) avoids concurrent `rimraf dist && build`