jest-tutorial icon indicating copy to clipboard operation
jest-tutorial copied to clipboard

pathsToModuleNameMapper 可以直接从 ts-jest 里面引入了

Open nmsn opened this issue 1 year ago • 0 comments

https://kulshekhar.github.io/ts-jest/docs/getting-started/paths-mapping/

const { pathsToModuleNameMapper } = require('ts-jest')
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file
// which contains the path mapping (ie the `compilerOptions.paths` option):
const { compilerOptions } = require('./tsconfig')

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
  // [...]
  roots: ['<rootDir>'],
  modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '<rootDir>/' } */),
}

nmsn avatar Jul 07 '23 07:07 nmsn