Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(vitest): run the FR23 benchmark alone in a later project group (#9948)

Cindy Zhang76298e4154e6
diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjs
index 889583add1..9f1b28022c 100644
--- a/.github/scripts/ci-test-routing.test.mjs
+++ b/.github/scripts/ci-test-routing.test.mjs
@@ -155,16 +155,31 @@ describe.each(Object.entries(WORKFLOWS))(
const suites = job.steps.filter(
step =>
!specReaderRun(step) &&
- expandScripts(step.run ?? '').includes('--project ui'),
- );
- // The two package scripts every lane calls: the parallel suite without
- // FR23, and FR23 alone with no file parallelism.
- expect(rootScripts['test:ui']).toBe(
- `vitest run --project ui --exclude ${benchmark}`,
+ /--project (ui|perf)\b/.test(expandScripts(step.run ?? '')),
);
+ // The two package scripts every lane calls: the parallel UI project, and
+ // the `perf` project with no file parallelism.
+ expect(rootScripts['test:ui']).toBe('vitest run --project ui');
expect(rootScripts['test:ui:isolated']).toBe(
- `vitest run --project ui ${benchmark} --no-file-parallelism`,
+ 'vitest run --project perf --no-file-parallelism',
+ );
+ // The benchmark is the `perf` project's only file, and `ui` excludes it.
+ // No other project sets a group, so `perf` starts after all of them.
+ const config = read('vitest.config.ts');
+ const projectBlock = name => {
+ const start = config.indexOf(`name: '${name}',`);
+ return config.slice(start, config.indexOf("name: '", start + 1));
+ };
+ const named = /const helperOverheadBenchmark =\s*'([^']+)';/.exec(config);
+ expect(named?.[1]).toBe(benchmark);
+ expect(projectBlock('ui')).toContain(
+ 'exclude: [...configDefaults.exclude, helperOverheadBenchmark]',
+ );
+ expect(projectBlock('perf')).toContain(
+ 'include: [helperOverheadBenchmark]',
);
+ expect(projectBlock('perf')).toContain('sequence: {groupOrder: 1}');
+ expect(config.match(/groupOrder/g)).toHaveLength(1);
expect(job['continue-on-error']).not.toBe(true);
for (const suite of suites) {
expect(suite['continue-on-error']).not.toBe(true);
@@ -279,14 +294,12 @@ describe.each(Object.entries(WORKFLOWS))(
!specReaderRun(step) &&
/--project \w+/.test(expandScripts(step.run ?? '')),
);
- // The one step that is not sharded is the isolated FR23 benchmark.
+ // The one step that is not sharded is the `perf` project's benchmark.
const unsharded = suites.filter(
step => !step.run.includes(SHARD_ARG),
);
for (const step of unsharded) {
- expect(expandScripts(step.run)).toContain(
- 'Markdown.fr23.perf.test.ts',
- );
+ expect(expandScripts(step.run)).toContain('--project perf');
}
expect(suites.length - unsharded.length).toBe(1);
}
diff --git a/package.json b/package.json
index 818229d6a0..cda8fd854e 100644
--- a/package.json
+++ b/package.json
@@ -24,8 +24,8 @@
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest --coverage",
- "test:ui": "vitest run --project ui --exclude packages/core/src/Markdown/Markdown.fr23.perf.test.ts",
- "test:ui:isolated": "vitest run --project ui packages/core/src/Markdown/Markdown.fr23.perf.test.ts --no-file-parallelism",
+ "test:ui": "vitest run --project ui",
+ "test:ui:isolated": "vitest run --project perf --no-file-parallelism",
"test:node": "vitest run --project node",
"test:build": "vitest run packages/build/src/packed-consumer.test.mjs --project node --maxWorkers=1 && pnpm -F @astryxdesign/build build && node .github/scripts/theme-layer-cascade.js && ASTRYX_STYLEX_BROWSER=1 vitest run scripts/stylex-module-resolution.browser.test.mjs --project node --maxWorkers=1 && ASTRYX_TURBOPACK_E2E=1 vitest run packages/build/src/next.turbopack.test.mjs --project node --maxWorkers=1",
"test:theme-family": "pnpm -F @astryxdesign/core build && pnpm -F @astryxdesign/sandbox generate:theme-family && node .github/scripts/theme-family-cascade.js",
diff --git a/packages/core/src/Markdown/Markdown.fr23.perf.test.ts b/packages/core/src/Markdown/Markdown.fr23.perf.test.ts
index 6da111e0a3..fa7d7ef650 100644
--- a/packages/core/src/Markdown/Markdown.fr23.perf.test.ts
+++ b/packages/core/src/Markdown/Markdown.fr23.perf.test.ts
@@ -11,10 +11,11 @@
* a time, and only asserts on what that process reports.
*
* A fresh process isolates engine state left by other plugin configurations,
- * but it still shares CPU and memory with other Vitest workers. CI and Deploy
- * exclude this file from the parallel UI suite, then run it alone after those
- * workers exit, as the spec's isolated-process-and-runner protocol requires.
- * Local measurements need the same isolation from other test and build work.
+ * but it still shares CPU and memory with other Vitest workers. So this file
+ * is the only one in the `perf` Vitest project. That project starts after
+ * every other project's files finish, as the spec's isolated-process-and-runner
+ * protocol requires. Local measurements need the same isolation from other
+ * test and build work.
*
* The timed region inside each process is the spec's protocol, unsmoothed:
* ten untimed warmups, then one median of nine alternating paired rounds,
diff --git a/vitest.config.ts b/vitest.config.ts
index 1c53fa3e8d..4975778922 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -3,9 +3,10 @@
/**
* @file vitest.config.ts
* @input Uses vitest/config, @vitejs/plugin-react
- * @output Vitest configuration with jsdom, coverage, test setup, the two
- * test projects (`ui`, `node`), and the sequencer that splits `--shard` legs
- * @position Root test config and the actual test entry point. The two projects
+ * @output Vitest configuration with jsdom, coverage, test setup, the three
+ * test projects (`ui`, `perf`, `node`), and the sequencer that splits
+ * `--shard` legs
+ * @position Root test config and the actual test entry point. The projects
* under `test.projects` decide which files run where via their per-project
* include lists. The root-level `test` options (globals, environment,
* coverage, setupFiles, pool sizing) are inherited by projects that set
@@ -26,6 +27,11 @@ import DurationShardSequencer from './scripts/vitest-shard-sequencer.mjs';
const rootDir = path.resolve(__dirname, '.');
const coreSrc = path.resolve(__dirname, 'packages/core/src');
+// Times the Markdown helper pipeline against the empty one on the CPU clock.
+// CPU time still includes cache and memory-bandwidth contention from other
+// work, so this file runs alone in the `perf` project.
+const helperOverheadBenchmark =
+ 'packages/core/src/Markdown/Markdown.fr23.perf.test.ts';
export default defineConfig({
plugins: [
@@ -101,6 +107,8 @@ export default defineConfig({
// + packages/vega — need jsdom, the StyleX babel
// transform, and the jest-dom setup; inherit all of that from
// the root config via `extends: true`.
+ // - `perf` = the helper-overhead benchmark, which `ui` excludes. It
+ // inherits the root config too, and runs in a later group.
// - `node` = everything else (CLI, build tooling, scripts, internal
// utils, and app-level suites that need no DOM) — no DOM, no
// StyleX/babel transform, no jest-dom
@@ -133,6 +141,19 @@ export default defineConfig({
'packages/richtext/src/**/*.test.{ts,tsx,mjs}',
'packages/vega/src/**/*.test.{ts,tsx,mjs}',
],
+ exclude: [...configDefaults.exclude, helperOverheadBenchmark],
+ },
+ },
+ {
+ extends: true,
+ test: {
+ name: 'perf',
+ // Groups run in order, so this one starts only after the other
+ // projects' files finish.
+ sequence: {groupOrder: 1},
+ testTimeout: 30_000,
+ hookTimeout: 30_000,
+ include: [helperOverheadBenchmark],
},
},
{