Skip to content

Commit

Permalink
test(e2e): for pathsToModuleNameMapper in esm project
Browse files Browse the repository at this point in the history
  • Loading branch information
jjangga0214 committed Sep 4, 2022
1 parent b9e977c commit 1749456
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions e2e/__tests__/native-esm-ts.test.ts
Expand Up @@ -8,7 +8,7 @@ onNodeVersions('>=12.16.0', () => {
})

expect(exitCode).toBe(0)
expect(json.numTotalTests).toBe(3)
expect(json.numPassedTests).toBe(3)
expect(json.numTotalTests).toBe(4)
expect(json.numPassedTests).toBe(4)
})
})
7 changes: 6 additions & 1 deletion e2e/native-esm-ts/__tests__/native-esm-ts.spec.ts
@@ -1,6 +1,7 @@
import { test, expect } from '@jest/globals'

import { double } from '../double'
import { double } from '../double.js'
import { quadruple } from '../quadruple/index.js'
import { triple } from '../triple.mjs'

test('double', () => {
Expand All @@ -11,6 +12,10 @@ test('triple', () => {
expect(triple(2)).toBe(6)
})

test('quadruple', () => {
expect(quadruple(2)).toBe(8)
})

test('import.meta', () => {
expect(typeof import.meta.url).toBe('string')
})
8 changes: 4 additions & 4 deletions e2e/native-esm-ts/jest-isolated.config.js
@@ -1,7 +1,7 @@
/** @type {import('../../dist').InitialOptionsTsJest} */
module.exports = {
extensionsToTreatAsEsm: ['.ts'],
resolver: '<rootDir>/mjs-resolver.ts',
import config from './jest.config.js'

export default {
...config,
transform: {
'^.+\\.m?tsx?$': [
'<rootDir>/../../legacy.js',
Expand Down
23 changes: 23 additions & 0 deletions e2e/native-esm-ts/jest.config.js
@@ -0,0 +1,23 @@
import { pathsToModuleNameMapper } from '../../dist/index.js'
import { createRequire } from 'module'

const require = createRequire(import.meta.url)
const tsConfig = require('./tsconfig.json')

/** @type {import('../../dist').InitialOptionsTsJest} */
export default {
extensionsToTreatAsEsm: ['.ts'],
resolver: '<rootDir>/mjs-resolver.ts',
moduleNameMapper: pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
prefix: '<rootDir>',
removeJsExtension: true,
}),
transform: {
'^.+\\.m?tsx?$': [
'<rootDir>/../../legacy.js',
{
useESM: true,
},
],
},
}
9 changes: 0 additions & 9 deletions e2e/native-esm-ts/package.json
Expand Up @@ -2,14 +2,5 @@
"type": "module",
"devDependencies": {
"@jest/globals": "^29.0.2"
},
"jest": {
"extensionsToTreatAsEsm": [".ts"],
"resolver": "<rootDir>/mjs-resolver.ts",
"transform": {
"^.+\\.m?tsx?$": ["<rootDir>/../../legacy.js", {
"useESM": true
}]
}
}
}
2 changes: 2 additions & 0 deletions e2e/native-esm-ts/quadruple/calculate.ts
@@ -0,0 +1,2 @@
const calculate = (x: number) => x * 4
export default calculate
1 change: 1 addition & 0 deletions e2e/native-esm-ts/quadruple/index.ts
@@ -0,0 +1 @@
export { default as quadruple } from '@quadruple/calculate.js'
5 changes: 4 additions & 1 deletion e2e/native-esm-ts/tsconfig.json
Expand Up @@ -3,6 +3,9 @@
"module": "Node16",
"target": "ESNext",
"moduleResolution": "Node16",
"esModuleInterop": true
"esModuleInterop": true,
"paths": {
"@quadruple/*": ["quadruple/*"]
}
}
}

0 comments on commit 1749456

Please sign in to comment.