Core diff parsing and intelligent mapping logic for Cypress test selection
npm install cypress-smart-test-selection-coreCore library for intelligent Cypress test selection based on git diffs. Provides diff parsing, test discovery, and intelligent mapping heuristics.
``bash`
npm install cypress-smart-test-selection-core
This package is organized into subpath exports:
Parse and normalize git diff output.
`typescript
import { parseDiff } from 'cypress-smart-test-selection-core/diff';
const result = parseDiff(gitDiffOutput);
// result.files - array of changed files
// result.warnings - any parsing warnings
`
Discover Cypress test files in a project.
`typescript
import { discoverTests } from 'cypress-smart-test-selection-core/discovery';
const tests = await discoverTests({
projectRoot: process.cwd(),
testPatterns: ['cypress/e2e/*/.spec.ts'], // optional
});
`
Map changed files to relevant test files using intelligent heuristics.
`typescript
import { mapDiffToTests } from 'cypress-smart-test-selection-core/mapper';
import { parseDiff } from 'cypress-smart-test-selection-core/diff';
import { discoverTests } from 'cypress-smart-test-selection-core/discovery';
const diffResult = parseDiff(gitDiffOutput);
const tests = await discoverTests({ projectRoot: process.cwd() });
const mapping = await mapDiffToTests(diffResult.files, tests, {
safetyLevel: 'medium',
config: {
mappings: [
{ src: 'src/components', test: 'cypress/e2e/components' },
],
smoke: {
tags: ['smoke'],
},
},
});
// mapping.selected - array of selected test file paths
// mapping.mappings - detailed scoring information
``
- Diff Parsing: Robust git diff parsing supporting multiple formats
- Test Discovery: Fast glob-based test file discovery
- Intelligent Mapping: 3 heuristics (directory, filename, tags)
- Explicit Mappings: Configure source-to-test path mappings
- Smoke Tests: Always include critical tests
- Configurable Safety: High/moderate/medium/low safety levels with thresholds
- TypeScript: Fully typed with strict mode
See the individual module READMEs for detailed API documentation:
- Diff Module
- Discovery Module
- Mapper Module
MIT