Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions scripts/e2e-diagram-scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Module usage:
* import { detectScope } from './e2e-diagram-scope.mjs';
* const spec = detectScope(['packages/mermaid/src/diagrams/flowchart/flowchart.ts']);
* // => 'e2e/rendering/flowchart/**'
* // => 'e2e/rendering/flowchart/'
*/

import { createInterface } from 'readline';
Expand Down Expand Up @@ -221,9 +221,10 @@ export function detectScope(files, options = {}) {
break;
}

// File inside a diagram subfolder → scope to that subfolder.
// File inside a diagram subfolder → scope to that subfolder. Playwright
// treats CLI filters as regular expressions, so keep this glob-free.
const subFolder = rest.slice(0, slashIdx);
directlyChangedSpecs.push(`${specFolderPrefix}${subFolder}/**`);
directlyChangedSpecs.push(`${specFolderPrefix}${subFolder}/`);
continue;
}

Expand Down Expand Up @@ -254,7 +255,8 @@ export function detectScope(files, options = {}) {
return '';
}

// Build spec patterns from diagram names using filesystem discovery
// Build regular-expression-safe spec patterns from diagram names using
// filesystem discovery. A trailing slash matches every file in the folder.
const specs = new Set(directlyChangedSpecs);

/** @type {Set<string> | null} */
Expand All @@ -277,7 +279,7 @@ export function detectScope(files, options = {}) {
for (const name of diagramNames) {
const folder = `${specBaseDir}/${name}`;
if (existsSync(folder)) {
specs.add(`${folder}/**`);
specs.add(`${folder}/`);
} else if (hasFixtures(name)) {
// Fixtures-only diagram (no per-diagram spec subfolder) — the global mmd
// snapshot runner exercises it.
Expand Down
27 changes: 16 additions & 11 deletions scripts/e2e-diagram-scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ describe('detectScope', () => {
]);
expect(result.split(',')).toEqual(
expect.arrayContaining([
`${SPEC_BASE_DIR}/flowchart/**`,
`${SPEC_BASE_DIR}/flowchart/`,
`${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`,
])
);
});

it('returns patterns that Playwright can compile as regular expressions', () => {
const result = detectScope(['packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts']);

for (const pattern of result.split(',')) {
expect(() => new RegExp(pattern, 'gi')).not.toThrow();
}
});

it('falls back to full suite when rendering-util is touched', () => {
expect(
detectScope([
Expand Down Expand Up @@ -66,8 +74,8 @@ describe('detectScope', () => {
]);
expect(result.split(',')).toEqual(
expect.arrayContaining([
`${SPEC_BASE_DIR}/gantt/**`,
`${SPEC_BASE_DIR}/pie/**`,
`${SPEC_BASE_DIR}/gantt/`,
`${SPEC_BASE_DIR}/pie/`,
`${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`,
])
);
Expand All @@ -85,7 +93,7 @@ describe('detectScope', () => {
]);
expect(result.split(',')).toEqual(
expect.arrayContaining([
`${SPEC_BASE_DIR}/flowchart/**`,
`${SPEC_BASE_DIR}/flowchart/`,
`${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`,
])
);
Expand All @@ -112,10 +120,7 @@ describe('detectScope', () => {
it('scopes to the subfolder when a spec file in that subfolder is modified', () => {
const result = detectScope([`${SPEC_BASE_DIR}/gantt/gantt.spec.js`]);
expect(result.split(',')).toEqual(
expect.arrayContaining([
`${SPEC_BASE_DIR}/gantt/**`,
`${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`,
])
expect.arrayContaining([`${SPEC_BASE_DIR}/gantt/`, `${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`])
);
});

Expand All @@ -136,7 +141,7 @@ describe('detectScope', () => {
`${SPEC_BASE_DIR}/gantt/gantt.spec.js`,
]);
// Both point to the same subfolder — should deduplicate
expect(result.split(',').filter((s) => s === `${SPEC_BASE_DIR}/gantt/**`).length).toBe(1);
expect(result.split(',').filter((s) => s === `${SPEC_BASE_DIR}/gantt/`).length).toBe(1);
});
});

Expand Down Expand Up @@ -183,7 +188,7 @@ describe('ignorable files (docs-only, changesets, etc.)', () => {
]);
expect(result.split(',')).toEqual(
expect.arrayContaining([
`${SPEC_BASE_DIR}/flowchart/**`,
`${SPEC_BASE_DIR}/flowchart/`,
`${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`,
])
);
Expand All @@ -196,7 +201,7 @@ describe('ignorable files (docs-only, changesets, etc.)', () => {
]);
expect(result.split(',')).toEqual(
expect.arrayContaining([
`${SPEC_BASE_DIR}/flowchart/**`,
`${SPEC_BASE_DIR}/flowchart/`,
`${SPEC_BASE_DIR}/mmd-snapshots.spec.ts`,
])
);
Expand Down
Loading