Skip to content

Commit

Permalink
test(e2e): add mts e2e test (#3753)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl authored Aug 14, 2022
1 parent 5d5fb0d commit 63a1489
Show file tree
Hide file tree
Showing 8 changed files with 3,609 additions and 4 deletions.
4 changes: 2 additions & 2 deletions e2e/__tests__/native-esm-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ onNodeVersions('>=12.16.0', () => {
})

expect(exitCode).toBe(0)
expect(json.numTotalTests).toBe(2)
expect(json.numPassedTests).toBe(2)
expect(json.numTotalTests).toBe(3)
expect(json.numPassedTests).toBe(3)
})
})
7 changes: 7 additions & 0 deletions e2e/native-esm-ts/__tests__/native-esm-ts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { test, expect } from '@jest/globals'

import { double } from '../double'
import { triple } from '../triple.mjs'

test('double', () => {
expect(double(2)).toBe(4)
})

test('triple', () => {
expect(triple(2)).toBe(6)
})

test('import.meta', () => {
expect(typeof import.meta.url).toBe('string')
})
3 changes: 2 additions & 1 deletion e2e/native-esm-ts/jest-isolated.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
useESM: true,
},
},
resolver: '<rootDir>/mjs-resolver.ts',
transform: {
'^.+.tsx?$': '<rootDir>/../../legacy.js',
'^.+\\.m?tsx?$': '<rootDir>/../../legacy.js',
},
}
15 changes: 15 additions & 0 deletions e2e/native-esm-ts/mjs-resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mjsResolver = (path, options) => {
const mjsExtRegex = /\.mjs$/i
const resolver = options.defaultResolver
if (mjsExtRegex.test(path)) {
try {
return resolver(path.replace(mjsExtRegex, '.mts'), options)
} catch {
// use default resolver
}
}

return resolver(path, options)
}

module.exports = mjsResolver
Loading

0 comments on commit 63a1489

Please sign in to comment.