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 7732a86
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { divide } from '~'
import { divide as _divide } from '~/divide'

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

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

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

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

export { divide }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import multiply from 'lodash/multiply'

export { multiply }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import subtract from 'lodash/subtract'

export { subtract }
Original file line number Diff line number Diff line change
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 7732a86

Please sign in to comment.