@autotests/playwright-impact
v0.1.5
Published
Core impacted-test selection library for changed POM/method analysis
Downloads
607
Readme
Playwright Spec Impact
If you use Playwright + POM and your CI runs are slow, this library selects only specs affected by your changes.
It reads changed files, finds impacted specs, and helps you run only what matters.
Install
// npm
npm i @autotests/playwright-impact
// pnpm
pnpm add @autotests/playwright-impactQuick Start (Copy & Run)
Minimal working code
Create impact.js in your repo root:
const { analyzeImpactedSpecs } = require('@autotests/playwright-impact');
const result = analyzeImpactedSpecs({
repoRoot: process.cwd(),
profile: {
testsRootRelative: 'tests',
changedSpecPrefix: 'tests/',
isRelevantPomPath: (filePath) =>
(filePath.startsWith('src/pages/') || filePath.startsWith('src/utils/')) &&
(filePath.endsWith('.ts') || filePath.endsWith('.tsx')),
},
});
if (!result.hasAnythingToRun) {
console.log('No impacted specs found');
process.exit(0);
}
for (const spec of result.selectedSpecsRelative) {
console.log(spec);
}Save as impact.js
Run: node impact.js
Use output paths in your Playwright CLI
What you need to change
You only need to adjust:
testsRootRelative: folder where your Playwright specs live.changedSpecPrefix: prefix used to detect directly changed specs.isRelevantPomPath: rule for which source files are treated as POM/utility inputs.
Example output
Example output:
tests/auth/login.spec.ts
tests/cart/cart.spec.tsIf nothing is impacted:
No impacted specs foundMinimal CI Script
Use this when your branch is compared to origin/main.
const { analyzeImpactedSpecs } = require('@autotests/playwright-impact');
const result = analyzeImpactedSpecs({
repoRoot: process.cwd(),
baseRef: 'origin/main',
profile: {
testsRootRelative: 'tests',
changedSpecPrefix: 'tests/',
isRelevantPomPath: (filePath) =>
(filePath.startsWith('src/pages/') || filePath.startsWith('src/utils/')) &&
(filePath.endsWith('.ts') || filePath.endsWith('.tsx')),
},
});
if (!result.hasAnythingToRun) {
console.log('No impacted specs found');
process.exit(0);
}
console.log(result.selectedSpecsRelative.join(' '));Typical CI Usage
- Compare current branch with
origin/main. - Compute impacted specs.
- Exit with
0if nothing should run. - Pass
selectedSpecsRelativeto your Playwright runner.
How It Works (High Level)
- Read changed files from Git.
- Include directly changed specs.
- Detect impacted specs from changed POM/utility code.
- Return a final spec list.
Advanced Config
Required:
repoRootprofile.testsRootRelativeprofile.changedSpecPrefixprofile.isRelevantPomPath(filePath)
Optional:
analysisRootsRelativefixturesTypesRelativebaseRefincludeUntrackedSpecsincludeWorkingTreeWithBasefileExtensionsselectionBias
Advanced Diagnostics
warningsselectionReasonscoverageStats.uncertainCallSitescoverageStats.statusFallbackHitschangedEntriesBySource
Reason Codes
direct-changed-specmatched-precisematched-uncertain-fail-openretained-no-bindings
