Skip to content

Commit

Permalink
chore(e2e): add pathsToModuleNameMapper test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
OrkhanAlikhanov committed May 29, 2020
1 parent fe45ad7 commit 1ca92e8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 1 deletion.
@@ -1,12 +1,16 @@
/** @type {import('@jest/types').Config.InitialOptions} */
/** @typedef {import('ts-jest')} */

const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig-base');

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
// Ignore the TS project `outDir`
// https://github.com/kulshekhar/ts-jest/issues/765
testPathIgnorePatterns: ['<rootDir>/target/'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
globals: {
'ts-jest': {
isolatedModules: true,
Expand Down
@@ -0,0 +1,10 @@
import { divide } from '~'
import { divide as _divide } from '~/divide'

test('imported same divide function', () => {
expect(_divide).toBe(divide)
})

test('divides 3 / 2 to equal 1.5', () => {
expect(divide(3, 2)).toBe(1.5)
})
@@ -0,0 +1,5 @@
import { multiply } from '@/multiply'

test('multiplies 2 * 2 to equal 4', () => {
expect(multiply(2, 2)).toBe(4)
})
@@ -0,0 +1,5 @@
import { subtract } from '@/subtract'

test('subtracts 3 - 1 to equal 2', () => {
expect(subtract(3, 1)).toBe(2)
})
@@ -0,0 +1,3 @@
import divide from 'lodash/divide'

export { divide }
@@ -0,0 +1,3 @@
import multiply from 'lodash/multiply'

export { multiply }
@@ -0,0 +1,4 @@
import {multiply} from '@/multiply';
import subtract from 'lodash/subtract'

export { subtract, multiply }
Expand Up @@ -11,6 +11,19 @@
"rootDir": "./src/",
"types": [],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"@/*": [
"src/nested/*",
"src/nested/src/*"
],
"~": [
"src/math/divide.ts"
],
"~/*": [
"src/math/*"
]
}
}
}

0 comments on commit 1ca92e8

Please sign in to comment.