https://github.com/tribou/jest-serializer-path
Remove absolute paths from your Jest snapshots
https://github.com/tribou/jest-serializer-path
absolute-paths jest jest-serializer jest-serializer-path jest-snapshots snapshot snapshot-testing testing
Last synced: 7 months ago
JSON representation
Remove absolute paths from your Jest snapshots
- Host: GitHub
- URL: https://github.com/tribou/jest-serializer-path
- Owner: tribou
- License: apache-2.0
- Created: 2017-05-05T20:24:05.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T09:17:11.000Z (over 2 years ago)
- Last Synced: 2024-11-01T20:29:21.305Z (8 months ago)
- Topics: absolute-paths, jest, jest-serializer, jest-serializer-path, jest-snapshots, snapshot, snapshot-testing, testing
- Language: JavaScript
- Size: 49.2 MB
- Stars: 19
- Watchers: 3
- Forks: 8
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# jest-serializer-path
[](https://badge.fury.io/js/jest-serializer-path)
[](https://circleci.com/gh/tribou/jest-serializer-path/tree/master)
[](https://ci.appveyor.com/project/tribou/jest-serializer-path/branch/master)
[](https://coveralls.io/github/tribou/jest-serializer-path?branch=master)
[](http://www.repostatus.org/#active)
[](https://www.bithound.io/github/tribou/jest-serializer-path)Remove absolute paths and normalize paths across all platforms in your Jest snapshots.
#### Quick Start
```bash
npm install --save-dev jest-serializer-path
```Add this to your `package.json` Jest config:
```
"jest": {
"snapshotSerializers": [
"jest-serializer-path"
]
}
```Or include only in individual tests:
```js
const serializer = require("jest-serializer-path");expect.addSnapshotSerializer(serializer);
```All absolute paths will now be converted and saved in snapshots like so:
`/path/to/my-proj/lib` => `/lib`
`/path/to/os-temp/nested/temp` => `/nested/temp`
`/path/to/user-home/nested/home` => `/nested/home`
#### Caveats
* All single backslashes (`\`) will be replaced by a forward slash (`/`).
* Any string that looks like a Windows drive letter (`C:\`) will be replaced by a forward slash (`/`).#### Build
This project bundles the yarn executable and the npm/yarn dependencies offline
in the `.npm-packages-offline-cache` directory for faster dependency installs
and better dev/prod parity across including preventing failure if yarn/npm is
offline.```sh
# Install
npm run yarn# Run tests
npm run test
```