Skip to content

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

TypeScript

ci: test lanes call root test scripts instead of raw commands (#8389)

Cindy Zhanga19e396520fb
diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjs
index 95b7a17729..15fa832082 100644
--- a/.github/scripts/ci-test-routing.test.mjs
+++ b/.github/scripts/ci-test-routing.test.mjs
@@ -18,6 +18,9 @@
* holds if every project has a lane in every workflow: a third project added
* to the config with no job to run it would be collected by nobody and fail
* nothing — the first failure again, one level up.
+ *
+ * The lanes call root package scripts (`pnpm test:ui`, `pnpm test:node`), so
+ * the commands are checked with each script expanded to its body.
*/
import fs from 'node:fs';
@@ -78,10 +81,23 @@ function load(file) {
return yaml.parse(read(`.github/workflows/${file}`));
}
+const rootScripts = JSON.parse(read('package.json')).scripts;
+
+/**
+ * A run block with each `pnpm <root script>` replaced by the script's body,
+ * recursively; arguments after the script name stay after its body.
+ */
+function expandScripts(run) {
+ return run.replace(/\bpnpm ([a-z][\w:-]*)(?=\s|$)/g, (whole, name) =>
+ Object.hasOwn(rootScripts, name) ? expandScripts(rootScripts[name]) : whole,
+ );
+}
+
function runLines(job) {
return (job?.steps ?? [])
.map(step => step.run)
.filter(Boolean)
+ .map(expandScripts)
.join('\n');
}
@@ -126,7 +142,15 @@ describe.each(Object.entries(WORKFLOWS))(
const benchmark = 'packages/core/src/Markdown/Markdown.fr23.perf.test.ts';
const job = workflow.jobs['test-ui'];
const suites = job.steps.filter(step =>
- step.run?.includes('--project ui'),
+ 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}`,
+ );
+ expect(rootScripts['test:ui:isolated']).toBe(
+ `vitest run --project ui ${benchmark} --no-file-parallelism`,
);
expect(job['continue-on-error']).not.toBe(true);
for (const suite of suites) {
@@ -139,8 +163,8 @@ describe.each(Object.entries(WORKFLOWS))(
// ignored exits.
expect(suites).toHaveLength(1);
expect(suites[0].run.trim().split('\n')).toEqual([
- `pnpm vitest run --project ui --exclude ${benchmark}`,
- `pnpm vitest run --project ui ${benchmark} --no-file-parallelism`,
+ 'pnpm test:ui',
+ 'pnpm test:ui:isolated',
]);
return;
}
@@ -149,12 +173,8 @@ describe.each(Object.entries(WORKFLOWS))(
// runs FR23 in a later step on the same runner, after its share exited.
expect(suites).toHaveLength(2);
const [share, isolated] = suites;
- expect(share.run.trim()).toBe(
- `pnpm vitest run --project ui --exclude ${benchmark} ${SHARD_ARG}`,
- );
- expect(isolated.run.trim()).toBe(
- `pnpm vitest run --project ui ${benchmark} --no-file-parallelism`,
- );
+ expect(share.run.trim()).toBe(`pnpm test:ui ${SHARD_ARG}`);
+ expect(isolated.run.trim()).toBe('pnpm test:ui:isolated');
expect(job.steps.indexOf(isolated)).toBeGreaterThan(
job.steps.indexOf(share),
);
@@ -174,14 +194,16 @@ describe.each(Object.entries(WORKFLOWS))(
expect(Object.keys(job.strategy.matrix)).toEqual(['shard']);
expect(job.strategy['fail-fast']).toBe(false);
const suites = job.steps.filter(step =>
- /--project \w+/.test(step.run ?? ''),
+ /--project \w+/.test(expandScripts(step.run ?? '')),
);
// The one step that is not sharded is the isolated FR23 benchmark.
const unsharded = suites.filter(
step => !step.run.includes(SHARD_ARG),
);
for (const step of unsharded) {
- expect(step.run).toContain('Markdown.fr23.perf.test.ts');
+ expect(expandScripts(step.run)).toContain(
+ 'Markdown.fr23.perf.test.ts',
+ );
}
expect(suites.length - unsharded.length).toBe(1);
}
@@ -190,12 +212,15 @@ describe.each(Object.entries(WORKFLOWS))(
it('gives no lane the whole suite', () => {
// A bare `pnpm test` runs every project in one job — the shape that hit
- // the wall.
+ // the wall. Checked on the steps as written: expanded, it is just
+ // `vitest run`.
for (const lane of lanes) {
- expect(
- runLines(workflow.jobs[lane]),
- `${lane} runs the whole suite`,
- ).not.toMatch(/^\s*pnpm test\s*$/m);
+ const raw = (workflow.jobs[lane]?.steps ?? [])
+ .map(step => step.run ?? '')
+ .join('\n');
+ expect(raw, `${lane} runs the whole suite`).not.toMatch(
+ /^\s*pnpm test\s*$/m,
+ );
}
});
@@ -247,7 +272,9 @@ describe.each(Object.entries(WORKFLOWS))(
for (const lane of lanes) {
expect(workflow.jobs[lane].if).toContain('always()');
const steps = workflow.jobs[lane].steps;
- const suite = steps.find(step => step.run?.includes('--project'));
+ const suite = steps.find(step =>
+ expandScripts(step.run ?? '').includes('--project'),
+ );
expect(suite.if, `${lane} suite is unconditional`).toContain(
"docsite_only != 'true'",
);
diff --git a/.github/scripts/ci-tooling-routing.test.mjs b/.github/scripts/ci-tooling-routing.test.mjs
index 5561eb4f5a..d41a10962e 100644
--- a/.github/scripts/ci-tooling-routing.test.mjs
+++ b/.github/scripts/ci-tooling-routing.test.mjs
@@ -72,7 +72,7 @@ describe('Node-tooling CI routing', () => {
it('runs the Node project and required lint owners for tooling', () => {
const nodeSuite = ci.jobs['test-node'].steps.find(candidate =>
- candidate.run?.includes('--project node'),
+ /^pnpm test:node\b/.test(candidate.run ?? ''),
);
expect(nodeSuite.if).not.toContain('tooling_only');
expect(
@@ -88,7 +88,7 @@ describe('Node-tooling CI routing', () => {
it('skips UI/browser owners but keeps an explicit component N/A reporter', () => {
const uiSuite = ci.jobs['test-ui'].steps.find(candidate =>
- candidate.run?.includes('--project ui'),
+ /^pnpm test:ui\b/.test(candidate.run ?? ''),
);
expect(uiSuite.if).toContain(TOOLING_FALSE);
expect(ci.jobs['check-components'].if).not.toContain(TOOLING_FALSE);
@@ -101,33 +101,36 @@ describe('Node-tooling CI routing', () => {
expect(ci.jobs['test-build'].if).toBe(
`github.event_name != 'workflow_dispatch' && ${BROAD_ONLY}`,
);
- expect(step(ci.jobs['test-build'], 'Build the Vite plugin').run).toBe(
- 'pnpm -F @astryxdesign/build build',
+ expect(step(ci.jobs['test-build'], 'Run Build package contracts').run).toBe(
+ 'pnpm test:build',
);
- expect(
- step(ci.jobs['test-build'], 'Run Build CSS-layer cascade guard').run,
- ).toBe('node .github/scripts/theme-layer-cascade.js');
+ // The Build package's owner keeps its contracts, in order: the plugin is
+ // built before the cascade guard imports it.
+ const rootScripts = JSON.parse(
+ fs.readFileSync(path.join(root, 'package.json'), 'utf8'),
+ ).scripts;
+ const buildCommands = rootScripts['test:build'].split(' && ');
+ expect(buildCommands).toEqual([
+ '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',
+ ]);
expect(ci.jobs['fixture-contrast'].if).toContain(TOOLING_FALSE);
// The merge-base size build is heavy build work and stays off the
// Node-tooling, docsite, and spec lanes.
expect(ci.jobs['size-base'].if).toContain(BROAD_ONLY);
+ expect(rootScripts['test:theme-family'].split(' && ')).toEqual([
+ 'pnpm -F @astryxdesign/core build',
+ 'pnpm -F @astryxdesign/sandbox generate:theme-family',
+ 'node .github/scripts/theme-family-cascade.js',
+ ]);
const familyCommands = new Map([
[
'Install Playwright for theme-family contract',
'npx playwright install chromium',
],
- [
- 'Build theme-family compiler dependencies',
- 'pnpm -F @astryxdesign/core build',
- ],
- [
- 'Generate the maintained theme-family fixture',
- 'pnpm -F @astryxdesign/sandbox generate:theme-family',
- ],
- [
- 'Run theme family cascade guard',
- 'node .github/scripts/theme-family-cascade.js',
- ],
+ ['Run the theme-family contract', 'pnpm test:theme-family'],
]);
for (const [name, command] of familyCommands) {
const ownerStep = step(ci.jobs['test-node'], name);
diff --git a/.github/scripts/prebuilt-data-routing.test.mjs b/.github/scripts/prebuilt-data-routing.test.mjs
index cd9a909608..8e7c0dc434 100644
--- a/.github/scripts/prebuilt-data-routing.test.mjs
+++ b/.github/scripts/prebuilt-data-routing.test.mjs
@@ -17,11 +17,12 @@ describe('prebuilt data-variable browser routing', () => {
const install = steps.findIndex(
step => step.run === 'npx playwright install chromium',
);
- const guard = steps.findIndex(
- step => step.run === 'node .github/scripts/theme-layer-cascade.js',
- );
+ const guard = steps.findIndex(step => step.run === 'pnpm test:build');
expect(install).toBeGreaterThanOrEqual(0);
expect(guard).toBeGreaterThan(install);
+ expect(JSON.parse(read('package.json')).scripts['test:build']).toContain(
+ 'node .github/scripts/theme-layer-cascade.js',
+ );
const source = read('.github/scripts/theme-layer-cascade.js');
expect(source).toContain('scripts/build-css.data-tokens.browser.test.mjs');
expect(source).toContain("ASTRYX_PREBUILT_DATA_BROWSER: '1'");
diff --git a/.github/scripts/visual-gate/workflow-concurrency.test.mjs b/.github/scripts/visual-gate/workflow-concurrency.test.mjs
index ed2c969861..be40ced61e 100644
--- a/.github/scripts/visual-gate/workflow-concurrency.test.mjs
+++ b/.github/scripts/visual-gate/workflow-concurrency.test.mjs
@@ -253,7 +253,7 @@ describe('PR report and deployment workflow contracts', () => {
expect(workflow('vibe-screenshots.yml')).not.toContain('gh-pages');
const main = workflow('deploy.yml');
expect(main).toContain('name: Main');
- expect(main).toContain('pnpm vitest run --project ui');
+ expect(main).toContain('pnpm test:ui');
expect(main).not.toContain('deploy-storybook');
expect(main).not.toContain('gh-pages');
});
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2fbed8aa7e..ba4a8f7d05 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -666,14 +666,14 @@ jobs:
run: pnpm lab:readiness:check
- name: Run this shard of the UI tests
- run: pnpm vitest run --project ui --exclude packages/core/src/Markdown/Markdown.fr23.perf.test.ts --shard=${{ matrix.shard }}/${{ strategy.job-total }}
+ run: pnpm test:ui --shard=${{ matrix.shard }}/${{ strategy.job-total }}
if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
# A child process isolates engine state, not CPU or memory contention.
# FR23 must wait until this runner's other UI workers have exited
# (AST-036); the other shards run on other machines.
- name: Run the isolated Markdown benchmark
- run: pnpm vitest run --project ui packages/core/src/Markdown/Markdown.fr23.perf.test.ts --no-file-parallelism
+ run: pnpm test:ui:isolated
if: matrix.shard == 1 && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
test-node:
@@ -708,7 +708,7 @@ jobs:
- uses: ./.github/actions/setup
if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true'
- - run: pnpm vitest run --project node --shard=${{ matrix.shard }}/${{ strategy.job-total }}
+ - run: pnpm test:node --shard=${{ matrix.shard }}/${{ strategy.job-total }}
if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true'
# Theme-family compilation is owned by `theme-build`, not Build. Until
@@ -719,17 +719,9 @@ jobs:
if: matrix.shard == 1 && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
run: npx playwright install chromium
- - name: Build theme-family compiler dependencies
+ - name: Run the theme-family contract
if: matrix.shard == 1 && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
- run: pnpm -F @astryxdesign/core build
-
- - name: Generate the maintained theme-family fixture
- if: matrix.shard == 1 && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
- run: pnpm -F @astryxdesign/sandbox generate:theme-family
-
- - name: Run theme family cascade guard
- if: matrix.shard == 1 && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
- run: node .github/scripts/theme-family-cascade.js
+ run: pnpm test:theme-family
# Native Swift: the Swift packages of the experimental, canary-only
# @astryxdesign/native (AST-082) build and test only on macOS. They are
@@ -3762,27 +3754,14 @@ jobs:
- uses: ./.github/actions/setup
- - name: Verify packed consumer dependency contract
- run: pnpm vitest run packages/build/src/packed-consumer.test.mjs --project node --maxWorkers=1
-
- name: Install Playwright
run: npx playwright install chromium
- # The guard imports the plugin's build artifact, the same one a consumer
- # installs.
- - name: Build the Vite plugin
- run: pnpm -F @astryxdesign/build build
-
- - name: Run Build CSS-layer cascade guard
- run: node .github/scripts/theme-layer-cascade.js
-
- # A compile-time ancestor selector on another workspace package's marker
- # (lab's rule on core's indicatorScope) matches in a real browser: see
- # scripts/stylex-module-resolution.cjs.
- - name: Run cross-package StyleX marker browser check
- env:
- ASTRYX_STYLEX_BROWSER: '1'
- run: pnpm vitest run scripts/stylex-module-resolution.browser.test.mjs --project node --maxWorkers=1
+ # The Build package's contracts: the packed consumer's dependencies, the
+ # production CSS-layer cascade, and cross-package StyleX markers in a
+ # real browser. `pnpm test:build` owns the list.
+ - name: Run Build package contracts
+ run: pnpm test:build
# Guest token boundaries cross portals and the host light/dark cascade. This
# requires a production browser render; source and jsdom checks cannot prove
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 2e92172d01..130d6be5f9 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -57,8 +57,8 @@ jobs:
# Match the PR gate: FR23 needs an idle test runner, not just a new process.
- name: Run UI tests and isolated Markdown benchmark
run: |
- pnpm vitest run --project ui --exclude packages/core/src/Markdown/Markdown.fr23.perf.test.ts
- pnpm vitest run --project ui packages/core/src/Markdown/Markdown.fr23.perf.test.ts --no-file-parallelism
+ pnpm test:ui
+ pnpm test:ui:isolated
test-node:
# Vitest runs one test file per CPU beyond the first, so the 2-core runner
@@ -73,7 +73,7 @@ jobs:
- uses: ./.github/actions/setup
- - run: pnpm vitest run --project node
+ - run: pnpm test:node
# The typecheck mirroring the PR `build` job in ci.yml. ci.yml only runs
# on pull_request/merge_group, so a typecheck error can land on main (its
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 282d1e3f7a..19d555e975 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -480,6 +480,11 @@ pnpm test:watch
# Specific package
pnpm -F @astryxdesign/core test
+# One Vitest project, as CI runs it (CI shards each across legs)
+pnpm test:ui # the ui project, without the FR23 benchmark
+pnpm test:ui:isolated # the FR23 benchmark alone, as test-ui leg 1 runs it
+pnpm test:node
+
# With coverage
pnpm test:coverage
diff --git a/package.json b/package.json
index e8a522cce2..8c0f8298c7 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,11 @@
"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: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",
+ "test:theme-family": "pnpm -F @astryxdesign/core build && pnpm -F @astryxdesign/sandbox generate:theme-family && node .github/scripts/theme-family-cascade.js",
"test:a11y-contract": "playwright test --config playwright.config.ts --project chromium",
"test:docsite-browser": "playwright test --config apps/docsite/playwright.config.ts",
"typecheck": "pnpm -r --no-bail --workspace-concurrency=1 --if-present --filter \"!@astryxdesign/docsite\" --filter \"!@astryxdesign/sandbox\" run typecheck",
diff --git a/scripts/stylex-module-resolution.test.mjs b/scripts/stylex-module-resolution.test.mjs
index 2bbdaff667..c74ac50894 100644
--- a/scripts/stylex-module-resolution.test.mjs
+++ b/scripts/stylex-module-resolution.test.mjs
@@ -182,15 +182,15 @@ describe('the browser check', () => {
const install = steps.findIndex(
step => step.run === 'npx playwright install chromium',
);
- const check = steps.findIndex(
- step => step.name === 'Run cross-package StyleX marker browser check',
- );
+ const check = steps.findIndex(step => step.run === 'pnpm test:build');
expect(install).toBeGreaterThanOrEqual(0);
expect(check).toBeGreaterThan(install);
- expect(steps[check].env).toEqual({ASTRYX_STYLEX_BROWSER: '1'});
- expect(steps[check].run).toContain(
- 'scripts/stylex-module-resolution.browser.test.mjs',
- );
expect(steps[check]['continue-on-error']).toBeUndefined();
+ const {scripts} = JSON.parse(
+ fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'),
+ );
+ expect(scripts['test:build']).toContain(
+ 'ASTRYX_STYLEX_BROWSER=1 vitest run scripts/stylex-module-resolution.browser.test.mjs',
+ );
});
});