Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

tsconfig-paths-jest

ryohey268.3kMIT0.0.1

load moduleNameMapper from tsconfig

Typescript, Jest

readme

tsconfig-paths-jest

This module loads tsconfig.json's paths and transforms to moduleNameMapper used in jest.config.js

Usage

tsconfig.json

"paths": {
  "@app/*": ["src/*"]
}

jest.config.js

const tsconfig = require("./tsconfig.json")
const moduleNameMapper = require("tsconfig-paths-jest")(tsconfig)

module.exports = {
  transform: {
    "^.+\\.tsx?$": "ts-jest",
  },
  testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
  moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
  moduleNameMapper,
}

Result

moduleNameMapper: {
  "@app/(.*)": "<rootDir>/src/$1"
}

Limitation

This module does not support the following definition that has multiple paths.

"paths": {
  "@app/*": ["src/*", "src/app/*"]
}