Skip to content

Commit 1ca92e8

Browse files
chore(e2e): add pathsToModuleNameMapper test cases
1 parent fe45ad7 commit 1ca92e8

8 files changed

Lines changed: 48 additions & 1 deletion

File tree

e2e/__external-repos__/simple-project-references/jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/** @type {import('@jest/types').Config.InitialOptions} */
22
/** @typedef {import('ts-jest')} */
33

4+
const { pathsToModuleNameMapper } = require('ts-jest/utils');
5+
const { compilerOptions } = require('./tsconfig-base');
6+
47
module.exports = {
58
preset: 'ts-jest',
69
testEnvironment: 'node',
710
// Ignore the TS project `outDir`
811
// https://github.com/kulshekhar/ts-jest/issues/765
912
testPathIgnorePatterns: ['<rootDir>/target/'],
13+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
1014
globals: {
1115
'ts-jest': {
1216
isolatedModules: true,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { divide } from '~'
2+
import { divide as _divide } from '~/divide'
3+
4+
test('imported same divide function', () => {
5+
expect(_divide).toBe(divide)
6+
})
7+
8+
test('divides 3 / 2 to equal 1.5', () => {
9+
expect(divide(3, 2)).toBe(1.5)
10+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { multiply } from '@/multiply'
2+
3+
test('multiplies 2 * 2 to equal 4', () => {
4+
expect(multiply(2, 2)).toBe(4)
5+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { subtract } from '@/subtract'
2+
3+
test('subtracts 3 - 1 to equal 2', () => {
4+
expect(subtract(3, 1)).toBe(2)
5+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import divide from 'lodash/divide'
2+
3+
export { divide }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import multiply from 'lodash/multiply'
2+
3+
export { multiply }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {multiply} from '@/multiply';
2+
import subtract from 'lodash/subtract'
3+
4+
export { subtract, multiply }

e2e/__external-repos__/simple-project-references/tsconfig-base.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111
"rootDir": "./src/",
1212
"types": [],
1313
"allowSyntheticDefaultImports": true,
14-
"esModuleInterop": true
14+
"esModuleInterop": true,
15+
"baseUrl": ".",
16+
"paths": {
17+
"@/*": [
18+
"src/nested/*",
19+
"src/nested/src/*"
20+
],
21+
"~": [
22+
"src/math/divide.ts"
23+
],
24+
"~/*": [
25+
"src/math/*"
26+
]
27+
}
1528
}
1629
}

0 commit comments

Comments
 (0)