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

Ensure mjs files are transformed with jest #34698

Merged
merged 6 commits into from
Mar 9, 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
2 changes: 1 addition & 1 deletion packages/next/build/jest/jest.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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