Unverified Commit acbd5432 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure mjs files are transformed with jest (#34698)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 6646ffad
...@@ -100,7 +100,7 @@ export default function nextJest(options: { dir?: string } = {}) { ...@@ -100,7 +100,7 @@ export default function nextJest(options: { dir?: string } = {}) {
transform: { transform: {
// Use SWC to compile tests // Use SWC to compile tests
'^.+\\.(js|jsx|ts|tsx)$': [ '^.+\\.(js|jsx|ts|tsx|mjs)$': [
require.resolve('../swc/jest-transformer'), require.resolve('../swc/jest-transformer'),
{ {
nextConfig, nextConfig,
......
...@@ -37,10 +37,6 @@ const isSupportEsm = 'Module' in vm ...@@ -37,10 +37,6 @@ const isSupportEsm = 'Module' in vm
module.exports = { module.exports = {
createTransformer: (inputOptions) => ({ createTransformer: (inputOptions) => ({
process(src, filename, jestOptions) { process(src, filename, jestOptions) {
if (!/\.[jt]sx?$/.test(filename)) {
return src
}
const jestConfig = getJestConfig(jestOptions) const jestConfig = getJestConfig(jestOptions)
let swcTransformOpts = getJestSWCOptions({ let swcTransformOpts = getJestSWCOptions({
......
...@@ -80,6 +80,21 @@ describe('next/jest', () => { ...@@ -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': ` 'test/mock.test.js': `
import router from 'next/router' import router from 'next/router'
......
/* eslint-env jest */ /* eslint-env jest */
describe('jest next-swc preset', () => { describe('jest next-swc preset', () => {
it('should have correct env', async () => { it('should have correct env', async () => {
expect(process.env.NODE_ENV).toBe('test') expect(process.env.NODE_ENV).toBe('test')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment