Skip to content

Commit

Permalink
update(jest-paths): resolve paths from tsconfig.json
Browse files Browse the repository at this point in the history
issue #105
  • Loading branch information
sabertazimi committed Aug 4, 2021
1 parent 91bc504 commit 1f41e63
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion notes/web/javascript/javascriptAdvancedNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7393,6 +7393,12 @@ npm i -D jest ts-jest @types/jest react-test-renderer
`jest.config.js`:
```js
const { compilerOptions } = require('./tsconfig.json');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const paths = pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
});

module.exports = {
roots: ['<rootDir>/src'],
transform: {
Expand All @@ -7401,7 +7407,14 @@ module.exports = {
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleNameMapper: {
'^Components/(.*)': '<rootDir>/src/components/$1',
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/jest.mock.js',
...paths,
'^@components/(.*)$': '<rootDir>/src/components/$1',
'^@hooks/(.*)$': '<rootDir>/src/hooks/$1',
'^@layouts/(.*)$': '<rootDir>/src/layouts/$1',
'^@types/(.*)$': '<rootDir>/src/types/$1',
},
globals: {
window: {},
Expand Down

0 comments on commit 1f41e63

Please sign in to comment.