If you are not using CommonJS on NodeJS and having problems with the intellisense for getting into modules.
- Install
module-alias
andmodule-alias-jest
- Configure your
package.json
file with your aliases:
{
"_moduleAliases": {
"$root": ".",
"$src": "./src",
}
}
-
Add the package your very first index module:
require('module-alias/register');
-
Configure your
jest.config
file like this below:
const aliases = require('module-alias-jest/register');
const jestConfig = {
testEnvironment: 'jest-environment-node',
testEnvironmentOptions: {
NODE_ENV: 'test'
},
coveragePathIgnorePatterns: ['node_modules', 'src/index.js', 'test'],
coverageReporters: ['text', 'lcov', 'clover', 'html'],
testMatch: ['**/*.spec.js'],
restoreMocks: true,
verbose: true,
moduleNameMapper: aliases.jest
};
module.exports = jestConfig;
- Creates a jsonconfig.json file on your root and place the JSON below:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"baseUrl": "./",
"paths": {
"$root/*": ["./*"],
"$src/*": ["./src/*"],
"$services/*": ["./src/services/*"],
"$clients/*": ["./src/clients/*"],
}
},
"exclude": ["node_modules", "**/node_modules/*"]
}
Thank you. this helped me.