@bestcodetools/jest-tsconfig-paths-mapper
v1.0.2
Published
A utility library for generating Jest's moduleNameMapper based on TypeScript's tsconfig.json path mappings.
Downloads
6
Maintainers
Readme
@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
Create a
jest.config.js
file in the root of your project if you don't have one already.Import the
generateModuleNameMapper
function from the@bestcodetools/jest-tsconfig-paths-mapper
package at the top of yourjest.config.js
file:
const { generateModuleNameMapper } = require('@bestcodetools/jest-tsconfig-paths-mapper');
- Define the
moduleNameMapper
property in themodule.exports
object of yourjest.config.js
file:
module.exports = {
// Other Jest configuration options...
moduleNameMapper: generateModuleNameMapper(),
};
- 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.