Skip to content

Jest/Vitest snapshot path-serializer, e.g: replace "/usr/packages" with `<ROOT>/packages`

License

Notifications You must be signed in to change notification settings

rspack-contrib/path-serializer

Repository files navigation

path-serializer

npm latest version

  1. stabilize pnpm dependencies path and update dependencies smoothly
  2. transform win32 path to posix path and more...
// __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" : "<ROOT>/node_modules/<PNPM_INNER>/css-loader/utils.ts"
}

Usage

// 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

Showcases

Rslib

Rsbuild

Rspack

About

Jest/Vitest snapshot path-serializer, e.g: replace "/usr/packages" with `<ROOT>/packages`

Topics

Resources

License

Stars

Watchers

Forks