Skip to content

tribou/jest-serializer-path

Repository files navigation

jest-serializer-path

npm version Linux Build Status Windows Build Status Coverage Status Project Status: Active - The project has reached a stable, usable state and is being actively developed. bitHound Code

Remove absolute paths and normalize paths across all platforms in your Jest snapshots.

Quick Start

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:

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 => <PROJECT_ROOT>/lib

/path/to/os-temp/nested/temp => <TEMP_DIR>/nested/temp

/path/to/user-home/nested/home => <HOME_DIR>/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.

# Install
npm run yarn

# Run tests
npm run test