Skip to content

Commit

Permalink
Ensure mjs files are transformed with jest (#34698)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
ijjk and kodiakhq[bot] committed Mar 9, 2022
1 parent 6646ffa commit acbd543
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/jest/jest.ts
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions packages/next/build/swc/jest-transformer.js
Expand Up @@ -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({
Expand Down
15 changes: 15 additions & 0 deletions test/production/next/jest/index.test.ts
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion test/unit/jest-next-swc.test.ts
@@ -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')
Expand Down

0 comments on commit acbd543

Please sign in to comment.