Skip to content

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

TypeScript

ci: the scope-overlap check ignores unit-test-only changes (#10700)

Cindy Zhangb4744d2c72ac
diff --git a/.github/scripts/a11y-scope-overlap.mjs b/.github/scripts/a11y-scope-overlap.mjs
index 9f4b46b5dd..a6ddb77bdc 100644
--- a/.github/scripts/a11y-scope-overlap.mjs
+++ b/.github/scripts/a11y-scope-overlap.mjs
@@ -33,6 +33,17 @@ import {isA11ySpecFile} from './lib/a11y-spec-files.mjs';
export const VERSION = 1;
+/**
+ * Whether a changed path can change what a browser spec sees: a unit test
+ * (`*.test.*`) or a spec file (`*.spec.*`) renders nothing in the Storybook
+ * build the specs read. Shared fixtures under `__tests__/` that stories import
+ * still count.
+ * @param {string} file
+ */
+export function renders(file) {
+ return !/\.(?:test|spec)\.[^/]+$/.test(file);
+}
+
/**
* The components a pull request's changed paths touch: each changed source
* file's component folder, and the component its file is named for.
@@ -100,9 +111,10 @@ export function selectingScope(
*/
export function overlappingSpecs(
changedOnMain,
- changedPaths,
+ allChangedPaths,
{primitives, importers, labelled = false},
) {
+ const changedPaths = allChangedPaths.filter(renders);
const routings = changedOnMain.map(spec => ({
...spec,
routing: parseRouting(spec.mainSource),
diff --git a/.github/scripts/a11y-scope-overlap.test.mjs b/.github/scripts/a11y-scope-overlap.test.mjs
index b16dc97632..687349c14c 100644
--- a/.github/scripts/a11y-scope-overlap.test.mjs
+++ b/.github/scripts/a11y-scope-overlap.test.mjs
@@ -19,6 +19,7 @@ import {describe, expect, it} from 'vitest';
import {
overlappingSpecs,
+ renders,
selectingScope,
touchedComponents,
VERSION,
@@ -185,6 +186,51 @@ describe('overlappingSpecs', () => {
).toEqual([{path: always, reason: 'changed-on-main', scope: 'always'}]);
});
+ it('leaves out every spec for a change to unit tests only', () => {
+ // A Layout spec whose scope names the Table folder, added on main.
+ const corners =
+ 'packages/core/src/Layout/__tests__/ContainerCorners.a11y.chromium.spec.ts';
+ const added = {
+ path: corners,
+ status: 'added',
+ mainSource:
+ '// @pr-a11y scope ^(packages/core/src/(Layout|Table)/|apps/storybook/stories/ContainerCorners\\.stories)\n',
+ headSource: null,
+ };
+ expect(
+ overlappingSpecs(
+ [added],
+ [
+ 'packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx',
+ 'packages/core/src/Table/__tests__/TableTree.a11y.chromium.spec.ts',
+ ],
+ GRAPH,
+ ),
+ ).toEqual([]);
+ expect(
+ overlappingSpecs([added], ['packages/core/src/Table/Table.tsx'], GRAPH),
+ ).toMatchObject([{path: corners, reason: 'added-on-main'}]);
+ expect(renders('packages/core/src/Table/Table.tsx')).toBe(true);
+ // A shared fixture under __tests__/ that stories import still counts.
+ const tableSpec =
+ 'packages/core/src/Table/__tests__/Table.a11y.chromium.spec.ts';
+ expect(
+ overlappingSpecs(
+ [
+ {
+ path: tableSpec,
+ status: 'changed',
+ mainSource: '// @pr-a11y scope ^packages/core/src/Table/\n',
+ headSource: 'older\n',
+ },
+ ],
+ ['packages/core/src/Table/__tests__/Table.a11y.renders.tsx'],
+ GRAPH,
+ ),
+ ).toMatchObject([{path: tableSpec, reason: 'changed-on-main'}]);
+ expect(renders('apps/storybook/stories/Table.stories.tsx')).toBe(true);
+ });
+
it('reads the touched components from changed source, never from a record', () => {
expect(touchedComponents(TREE_CHANGE)).toEqual(['core/Table']);
expect(