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:
JJ Kasper 2022-03-09 06:49:58 -06:00 committed by GitHub
parent 6646ffad75
commit acbd54322f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View file

@ -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,

View file

@ -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({

View file

@ -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'

View file

@ -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')