fix(pregate): linear Playwright import scan; comments and no-space imports detected

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
garrytanandcapy-ai[bot] committed 2026-10-31 19:22:28 +00:00
1 parent de9b69038a
commit ae35fffb62
2 files changed
+11 -7

No files matched your search

+5 -3
View File
@@ -180,9 +180,11 @@ function packageRunner(repoRoot: string, dir: string, env: NodeJS.ProcessEnv): {
* fixture body that mentions the import mid-line do not count.
*/
function importsPlaywright(text: string): boolean {
if (/^[\t ]*(?:import[\t ]*|(?:const|let|var)\b[^=\n]*=[\t ]*require\([\t ]*)['"]@playwright\/test['"]/m.test(text)) return true;
for (const m of text.matchAll(/^[\t ]*import[\t ]+(type[\t ]+)?([^'"`;]*?)\s*\bfrom[\t ]*['"]@playwright\/test['"]/gm)) {
if (!m[1] && m[2]!.replace(/[{}]/g, '').split(',').some(s => s.trim() && !/^type\s/.test(s.trim()))) return true;
const code = text.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, '');
if (/^[\t ]*(?:import[\t ]*|(?:const|let|var)\b[^=\n]*=[\t ]*require\([\t ]*)['"]@playwright\/test['"]/m.test(code)) return true;
for (const m of code.matchAll(/^[\t ]*import(?=[\s{*])([^'"`;]*?)\bfrom[\t ]*['"]@playwright\/test['"]/gm)) {
const spec = m[1]!.trim();
if (!/^type(?=[\s{*])/.test(spec) && spec.replace(/[{}]/g, '').split(',').some(s => s.trim() && !/^type\s/.test(s.trim()))) return true;
}
return false;
}
+6 -4
View File
@@ -847,12 +847,14 @@ describe('nested JS packages run their own runner from their own directory', ()
const ctx = ctxFor(repo, pmShim(repo));
write(repo.work, 'package.json', JSON.stringify({ name: 'fixture', devDependencies: { vitest: '^3.2.0', '@playwright/test': '^1.48.0' } }) + '\n');
write(repo.work, 'tests/e2e/home.spec.ts', "import { expect, test } from '@playwright/test';\ntest('home', async ({ page }) => expect(page).toBeTruthy());\n");
write(repo.work, 'app/e2e/app.spec.ts', "import {\n test,\n} from \"@playwright/test\";\ntest('app', () => {});\n");
write(repo.work, 'app/e2e/app.spec.ts', "import {\n test, // the runner's fixture\n /* it's */ expect,\n} from \"@playwright/test\";\ntest('app', () => {});\n");
write(repo.work, 'tests/e2e/tight.spec.ts', "import{test}from'@playwright/test';\ntest('tight', () => {});\n");
write(repo.work, 'test/pad.test.js', 'import' + ' '.repeat(5_000) + '\n');
write(repo.work, 'test/util.test.js', "import { test } from 'vitest';\nimport type { Page } from '@playwright/test';\nimport type {\n Locator,\n} from '@playwright/test';\nimport { type BrowserContext } from '@playwright/test';\nconst spec = \"import { test } from '@playwright/test';\";\ntest('fixture text and type imports only', () => {});\n");
expect(planRuns(ctx, ['tests/e2e/home.spec.ts', 'test/util.test.js', 'app/src/sum.test.ts', 'app/e2e/app.spec.ts'])).toEqual({ groups: [
{ runner: 'npx vitest run {files}', cwd: '', files: ['test/util.test.js'] },
expect(planRuns(ctx, ['tests/e2e/home.spec.ts', 'tests/e2e/tight.spec.ts', 'test/util.test.js', 'test/pad.test.js', 'app/src/sum.test.ts', 'app/e2e/app.spec.ts'])).toEqual({ groups: [
{ runner: 'npx vitest run {files}', cwd: '', files: ['test/util.test.js', 'test/pad.test.js'] },
{ runner: 'pnpm exec vitest run {files}', cwd: 'app', files: ['src/sum.test.ts'] },
{ runner: 'npx playwright test --reporter=list {files}', cwd: '', files: ['tests/e2e/home.spec.ts'] },
{ runner: 'npx playwright test --reporter=list {files}', cwd: '', files: ['tests/e2e/home.spec.ts', 'tests/e2e/tight.spec.ts'] },
{ runner: 'pnpm exec playwright test --reporter=list {files}', cwd: 'app', files: ['e2e/app.spec.ts'] },
], unclaimed: [], missing: [], noPubspec: [] });
// A declared runner still takes every file, Playwright specs included.