path-serializer
npm install path-serializer
1. stabilize pnpm dependencies path in snapshot
2. transform win32 path to posix path
3. escapeEOL \r\n -> \n
and more...
``ts`
// __snapshots__/index.test.ts.snap
// 😭 bad
{
"loader" : "D:\\user\\rspack\\node_modules\\.pnpm\\css-loader@6.11.0_@rspack+core@packages+rspack_webpack@5.94.0_@swc+core@1.4.0_@swc+helpers@0._jlcdgjlw2ezzhg43ml3d627wdu\\node_modules\\css-loader\\utils.ts"
}
//😎👍🏻 good
{
"loader" : "
}
`typescript
// vitest.setup.ts
import { createSnapshotSerializer } from 'path-serializer';
expect.addSnapshotSerializer(
createSnapshotSerializer({
root: path.join(__dirname, '..'),
}),
);
``
More features can be found in ./src/types.ts