@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.
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-mapperUsage
Create a
jest.config.jsfile in the root of your project if you don't have one already.Import the
generateModuleNameMapperfunction from the@bestcodetools/jest-tsconfig-paths-mapperpackage at the top of yourjest.config.jsfile:
const { generateModuleNameMapper } = require('@bestcodetools/jest-tsconfig-paths-mapper');- Define the
moduleNameMapperproperty in themodule.exportsobject of yourjest.config.jsfile:
module.exports = {
// Other Jest configuration options...
moduleNameMapper: generateModuleNameMapper(),
};- Save the changes to the
jest.config.jsfile.
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.
