@patrikelfstrom/apsrt
v0.0.2
Published
Automated Property-based Snapshot Regression Testing
Readme
APSRT
Automated Property-based Snapshot Regression Testing
APSRT is a TypeScript tool for automated regression testing. It analyzes exported functions, generates property-based input samples from their types, and snapshots the results through Vitest.
Usage
Install APSRT in the project you want to test:
npm install --save-dev @patrikelfstrom/apsrtOr run it without adding it to package.json:
npx @patrikelfstrom/apsrtBy default it will use your local tsconfig.json.
# Use a specific tsconfig file
npx apsrt --tsconfig tsconfig.app.json
# Update snapshots
npx apsrt --update
# Watch for changes and re-run tests
npx apsrt --watchSnapshots are stored in .apsrt/__snapshots__/runtime.test.js.snap inside the project you run APSRT from.
If APSRT detects a likely nondeterministic function such as one using Math.random(), it will stop and ask you to add an @apsrt-ignore annotation to that export.
Developer
Clone the repository and install dependencies:
git clone [email protected]:PatrikElfstrom/apsrt.git
cd apsrt
npm installCommon development commands:
npm run build
npm test
npm run typecheckFeatures
- Generates runtime snapshot tests for exported TypeScript functions
- Uses fast-check to create deterministic sample inputs
- Uses Vitest snapshots to detect regressions
- Uses ts-morph and the TypeScript compiler to inspect function signatures
How it works
- APSRT loads a TypeScript config file from the current working directory.
- It analyzes included
.tsfiles and finds exported functions. - It creates input arbitraries based on parameter type text.
- It runs each exported function with deterministic samples.
- It snapshots the collected input/output pairs.
Project Structure
src/- CLI entry, packaged runtime entry, and core implementationsrc/core/- Type analysis, arbitrary creation, cache, and config loadingtest/unit/- Direct unit tests for core modulestest/integration/- Fixture-based runtime flow coveragetest/fixtures/- Sample exported functions used as test inputs
Environment Variables
APSRT_TSCONFIG: overrides the TypeScript config file name to loadAPSRT_ENABLE_CACHE=false: disables the on-disk analysis cache
Tech Stack
License
MIT
