diff --git a/scripts/e2e-diagram-scope.mjs b/scripts/e2e-diagram-scope.mjs index eeba7da5020..43013476e32 100644 --- a/scripts/e2e-diagram-scope.mjs +++ b/scripts/e2e-diagram-scope.mjs @@ -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'; @@ -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; } @@ -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 | null} */ @@ -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. diff --git a/scripts/e2e-diagram-scope.spec.ts b/scripts/e2e-diagram-scope.spec.ts index 5e25eee1923..9e87f00c825 100644 --- a/scripts/e2e-diagram-scope.spec.ts +++ b/scripts/e2e-diagram-scope.spec.ts @@ -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([ @@ -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`, ]) ); @@ -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`, ]) ); @@ -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`]) ); }); @@ -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); }); }); @@ -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`, ]) ); @@ -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`, ]) );