Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rspack-contrib/path-serializer
Jest/Vitest snapshot path-serializer, e.g: replace "/usr/packages" with `<ROOT>/packages`
https://github.com/rspack-contrib/path-serializer
Last synced: about 1 month ago
JSON representation
Jest/Vitest snapshot path-serializer, e.g: replace "/usr/packages" with `<ROOT>/packages`
- Host: GitHub
- URL: https://github.com/rspack-contrib/path-serializer
- Owner: rspack-contrib
- License: mit
- Created: 2024-08-06T14:48:17.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-11-28T11:09:40.000Z (about 2 months ago)
- Last Synced: 2024-11-28T11:12:34.135Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 163 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# path-serializer
[![npm latest version](https://img.shields.io/npm/v/path-serializer?style=flat-square&color=98c379)](https://www.npmjs.com/package/path-serializer)
1. stabilize pnpm dependencies path and update dependencies smoothly
2. transform win32 path to posix path
and more...```ts
// __snapshots__/index.test.ts.snap
// 😭 bad
{
"loader" : "D:\\user\\rspack\\node_modules\\.pnpm\\[email protected]_@rspack+core@[email protected]_@[email protected]_@swc+helpers@0._jlcdgjlw2ezzhg43ml3d627wdu\\node_modules\\css-loader\\utils.ts"
}
//😎👍🏻 good
{
"loader" : "/node_modules//css-loader/utils.ts"
}
```## Usage
```typescript
// vitest.setup.ts
import { createSnapshotSerializer } from 'path-serializer';expect.addSnapshotSerializer(
createSnapshotSerializer({
root: path.join(__dirname, '..'),
}),
);
```The specific usage can be found in [./src/types.ts](https://github.com/rspack-contrib/path-serializer/blob/main/src/types.ts)
## Showcases
[Rslib](https://github.com/web-infra-dev/rslib/blob/3ff6859eb38171c731e447a1364afc021f8c501a/tests/setupVitestTests.ts)
[Rsbuild](https://github.com/web-infra-dev/rsbuild/blob/a50eafa3519caaa66ecd6b0ccb2897a8194781ff/scripts/test-helper/vitest.setup.ts)
[Rspack](https://github.com/web-infra-dev/rspack/blob/5a6162c/packages/rspack-test-tools/src/helper/expect/placeholder.ts)