Ensure mjs files are transformed with jest (#34698)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
parent
6646ffad75
commit
acbd54322f
4 changed files with 16 additions and 6 deletions
|
@ -100,7 +100,7 @@ export default function nextJest(options: { dir?: string } = {}) {
|
|||
|
||||
transform: {
|
||||
// Use SWC to compile tests
|
||||
'^.+\\.(js|jsx|ts|tsx)$': [
|
||||
'^.+\\.(js|jsx|ts|tsx|mjs)$': [
|
||||
require.resolve('../swc/jest-transformer'),
|
||||
{
|
||||
nextConfig,
|
||||
|
|
|
@ -37,10 +37,6 @@ const isSupportEsm = 'Module' in vm
|
|||
module.exports = {
|
||||
createTransformer: (inputOptions) => ({
|
||||
process(src, filename, jestOptions) {
|
||||
if (!/\.[jt]sx?$/.test(filename)) {
|
||||
return src
|
||||
}
|
||||
|
||||
const jestConfig = getJestConfig(jestOptions)
|
||||
|
||||
let swcTransformOpts = getJestSWCOptions({
|
||||
|
|
|
@ -80,6 +80,21 @@ describe('next/jest', () => {
|
|||
});
|
||||
});
|
||||
`,
|
||||
'lib/hello.mjs': `
|
||||
import path from 'path'
|
||||
|
||||
export default function hello() {
|
||||
return path.join('hello', 'world')
|
||||
}
|
||||
`,
|
||||
'test/mjs-support.test.js': `
|
||||
import path from 'path'
|
||||
import hello from '../lib/hello.mjs'
|
||||
|
||||
it('should transpile .mjs file correctly', async () => {
|
||||
expect(hello()).toBe(path.join('hello', 'world'))
|
||||
})
|
||||
`,
|
||||
'test/mock.test.js': `
|
||||
import router from 'next/router'
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/* eslint-env jest */
|
||||
|
||||
describe('jest next-swc preset', () => {
|
||||
it('should have correct env', async () => {
|
||||
expect(process.env.NODE_ENV).toBe('test')
|
||||
|
|
Loading…
Reference in a new issue