1. jest-serializer-path
Remove absolute paths from your Jest snapshots
jest-serializer-path
Package: jest-serializer-path
Created by: tribou
Last modified: Sun, 19 Jun 2022 04:13:49 GMT
Version: 0.1.15
License: Apache-2.0
Downloads: 43,689
Repository: https://github.com/tribou/jest-serializer-path

Install

npm install jest-serializer-path
yarn add jest-serializer-path

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code