Skip to content

Commit 76f8fe9

Browse files
committed
Modularity ++
1 parent d485f39 commit 76f8fe9

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

src/tools/percy-snapshot-utils/constants.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,35 @@ export const EXCLUDED_DIRS = new Set([
480480
"packages",
481481
".nuget",
482482
]);
483+
484+
export const backendIndicators = [
485+
/import\s+requests/,
486+
/requests\.(get|post|put|delete|patch)/,
487+
/@pytest\.mark\.(api|backend|integration)/,
488+
/BASE_URL\s*=/,
489+
/\.status_code/,
490+
/\.json\(\)/,
491+
/TestClient/,
492+
/Bearer\s+/,
493+
/Authorization.*Bearer/,
494+
];
495+
496+
export const strongUIIndicators = [
497+
// Browser automation with specific context
498+
/(driver|browser|page)\.(click|type|fill|screenshot|wait)/,
499+
/webdriver\.(Chrome|Firefox|Safari|Edge)/,
500+
/(selenium|playwright|puppeteer|cypress).*import/,
501+
// CSS/XPath selectors
502+
/By\.(ID|CLASS_NAME|XPATH|CSS_SELECTOR)/,
503+
/\$\(['"#[.][^'"]*['"]\)/, // $(".class") or $("#id")
504+
// Page Object Model
505+
/class.*Page.*:/,
506+
/class.*PageObject/,
507+
// UI test markers
508+
/@(ui|web|e2e|browser)_?test/,
509+
/@pytest\.mark\.(ui|web|e2e|browser)/,
510+
// Browser navigation
511+
/\.goto\s*\(['"]https?:/,
512+
/\.visit\s*\(['"]https?:/,
513+
/\.navigate\(\)\.to\(/,
514+
];

src/tools/percy-snapshot-utils/detect-test-files.ts

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
import {
1111
EXCLUDED_DIRS,
1212
TEST_FILE_DETECTION,
13+
backendIndicators,
14+
strongUIIndicators,
1315
} from "../percy-snapshot-utils/constants.js";
1416

1517
import { DetectionConfig } from "../percy-snapshot-utils/types.js";
@@ -70,45 +72,9 @@ async function batchRegexCheck(
7072
async function isLikelyUITest(filePath: string): Promise<boolean> {
7173
try {
7274
const content = await fs.promises.readFile(filePath, "utf8");
73-
74-
// Quick backend test elimination
75-
const backendIndicators = [
76-
/import\s+requests/,
77-
/requests\.(get|post|put|delete|patch)/,
78-
/@pytest\.mark\.(api|backend|integration)/,
79-
/BASE_URL\s*=/,
80-
/\.status_code/,
81-
/\.json\(\)/,
82-
/TestClient/,
83-
/Bearer\s+/,
84-
/Authorization.*Bearer/,
85-
];
86-
8775
if (backendIndicators.some((pattern) => pattern.test(content))) {
8876
return false;
8977
}
90-
91-
// UI-specific patterns that require context
92-
const strongUIIndicators = [
93-
// Browser automation with specific context
94-
/(driver|browser|page)\.(click|type|fill|screenshot|wait)/,
95-
/webdriver\.(Chrome|Firefox|Safari|Edge)/,
96-
/(selenium|playwright|puppeteer|cypress).*import/,
97-
// CSS/XPath selectors
98-
/By\.(ID|CLASS_NAME|XPATH|CSS_SELECTOR)/,
99-
/\$\(['"#[.][^'"]*['"]\)/, // $(".class") or $("#id")
100-
// Page Object Model
101-
/class.*Page.*:/,
102-
/class.*PageObject/,
103-
// UI test markers
104-
/@(ui|web|e2e|browser)_?test/,
105-
/@pytest\.mark\.(ui|web|e2e|browser)/,
106-
// Browser navigation
107-
/\.goto\s*\(['"]https?:/,
108-
/\.visit\s*\(['"]https?:/,
109-
/\.navigate\(\)\.to\(/,
110-
];
111-
11278
return strongUIIndicators.some((pattern) => pattern.test(content));
11379
} catch {
11480
return false;

0 commit comments

Comments
 (0)