Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add mts e2e test #3753

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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