@bestcodetools/jest-tsconfig-paths-mapper
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@bestcodetools/jest-tsconfig-paths-mapper

A utility library for generating Jest's moduleNameMapper based on TypeScript's tsconfig.json path mappings.

Installation

Install the package using npm:

npm install @bestcodetools/jest-tsconfig-paths-mapper

Usage

  1. Create a jest.config.js file in the root of your project if you don't have one already.

  2. Import the generateModuleNameMapper function from the @bestcodetools/jest-tsconfig-paths-mapper package at the top of your jest.config.js file:

const { generateModuleNameMapper } = require('@bestcodetools/jest-tsconfig-paths-mapper');
  1. Define the moduleNameMapper property in the module.exports object of your jest.config.js file:
module.exports = {
  // Other Jest configuration options...

  moduleNameMapper: generateModuleNameMapper(),
};
  1. Save the changes to the jest.config.js file.

The generateModuleNameMapper function automatically reads the tsconfig.json file located in the root of your project and generates the moduleNameMapper object based on the path mappings defined in the compilerOptions section.

Now, when you run your Jest tests, the module name mappings will be resolved correctly based on the tsconfig.json paths.

Custom tsconfig.json Path

If your tsconfig.json file is located in a different directory or has a different name, you can provide the path as an argument to the generateModuleNameMapper function:

module.exports = {
  // Other Jest configuration options...

  moduleNameMapper: generateModuleNameMapper('/path/to/custom/tsconfig.json'),
};

Make sure to replace /path/to/custom/tsconfig.json with the actual path to your custom tsconfig.json file.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Feel free to customize the README.md file further to include additional sections or provide more detailed instructions as needed.

Dependents (0)

Package Sidebar

Install

npm i @bestcodetools/jest-tsconfig-paths-mapper

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

5.43 kB

Total Files

5

Last publish

Collaborators

  • kamikai