Skip to content

Commit 5da3655

Browse files
authored
test(e2e): add typescript paths with preset resolver tests (#1138)
1 parent e3675c7 commit 5da3655

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+178
-36
lines changed

e2e/jest-esm.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
'<rootDir>/async/jest-esm.config.js',
88
'<rootDir>/custom-typings/jest-esm.config.js',
99
'<rootDir>/jest-globals/jest-esm.config.js',
10+
'<rootDir>/path-mapping/jest-esm.config.js',
1011
'<rootDir>/snapshot-serializers/jest-esm.config.js',
1112
'<rootDir>/with-babel/jest-esm.config.js',
1213
],

e2e/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
'<rootDir>/async',
99
'<rootDir>/custom-typings',
1010
'<rootDir>/jest-globals',
11+
'<rootDir>/path-mapping',
1112
'<rootDir>/snapshot-serializers',
1213
'<rootDir>/with-babel',
1314
],
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { bar } from '@bar/bar-constant';
2+
3+
test('path mapping should work without being affected by resolver', async () => {
4+
expect(bar).toBe(1);
5+
await expect(import('@foo/foo-constant')).rejects.toMatchInlineSnapshot(
6+
`[Error: Cannot find module '@foo/foo-constant' from '__tests__/path-mapping.ts']`,
7+
);
8+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { pathsToModuleNameMapper } = require('ts-jest/utils');
2+
const { paths } = require('./tsconfig-esm.json').compilerOptions;
3+
4+
/** @type {import('ts-jest/dist/types').ProjectConfigTsJest} */
5+
module.exports = {
6+
displayName: 'path-mapping',
7+
preset: '<rootDir>/../../node_modules/ts-jest/presets/default-esm',
8+
globals: {
9+
'ts-jest': {
10+
useESM: true,
11+
tsconfig: 'tsconfig-esm.json',
12+
},
13+
},
14+
resolver: '<rootDir>/../../build/resolvers/ng-jest-resolver.js',
15+
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
16+
transform: { '^.+\\.(ts|js|html)$': '<rootDir>/../../build/index.js' },
17+
};

e2e/path-mapping/jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { pathsToModuleNameMapper } = require('ts-jest/utils');
2+
const { paths } = require('./tsconfig.json').compilerOptions;
3+
4+
/** @type {import('ts-jest/dist/types').ProjectConfigTsJest} */
5+
module.exports = {
6+
displayName: 'path-mapping',
7+
globals: {
8+
'ts-jest': {
9+
diagnostics: {
10+
warnOnly: true,
11+
},
12+
},
13+
},
14+
resolver: '<rootDir>/../../build/resolvers/ng-jest-resolver.js',
15+
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
16+
transform: { '^.+\\.(ts|js|html)$': '<rootDir>/../../build/index.js' },
17+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const bar = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 2;

e2e/path-mapping/tsconfig-esm.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig-esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"@bar/*": ["libs/bar/*"],
7+
"@foo/*": ["libs/foo/*"]
8+
}
9+
}
10+
}

e2e/path-mapping/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"@bar/*": ["libs/bar/*"]
7+
}
8+
}
9+
}

examples/example-app-v10/jest-esm.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require('jest-preset-angular/ngcc-jest-processor');
2+
const { pathsToModuleNameMapper } = require('ts-jest/utils');
3+
const { paths } = require('./tsconfig.json').compilerOptions;
24

35
/** @type {import('@jest/types').Config.InitialOptions} */
46
module.exports = {
@@ -10,5 +12,9 @@ module.exports = {
1012
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
1113
},
1214
},
15+
moduleNameMapper: {
16+
...pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
17+
tslib: 'tslib/tslib.es6.js',
18+
},
1319
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
1420
};

0 commit comments

Comments
 (0)