Skip to content

Commit

Permalink
chore: restore options to opt-in for server-side transpilation (#55010)
Browse files Browse the repository at this point in the history
### 🧐 What's in there?

As discussed with @huozhi, it's restoring code from #52393 which I forgot to restore in #54891.
It is unlikely to make a difference, but we'll set globalWindow based on the desired test environment. This will not make any difference for most people.

### 🧪 How to test?

Once you've rebuilt your local version of Next, `pnpm testheadless jest/rsc` 

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
  • Loading branch information
feugy and huozhi authored Sep 5, 2023
1 parent 3a62a30 commit 39a66d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 1 addition & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ const createJestConfig = nextJest()
// Any custom config you want to pass to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
testMatch: [
'**/*.test.js',
'**/*.test.ts',
'**/*.test.tsx',
'**/jest/**/*.test.jsx',
'**/jest/**/*.test.tsx',
],
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.jsx', '**/*.test.tsx'],
setupFilesAfterEnv: ['<rootDir>/jest-setup-after-env.ts'],
verbose: true,
rootDir: 'test',
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/build/swc/jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const createTransformer: TransformerCreator<
const jestConfig = getJestConfig(jestOptions)

const swcTransformOpts = getJestSWCOptions({
isServer:
jestConfig.testEnvironment === 'node' ||
jestConfig.testEnvironment.includes('jest-environment-node'),
filename,
jsConfig: inputOptions?.jsConfig,
resolvedBaseUrl: inputOptions?.resolvedBaseUrl,
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/build/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ function getEmotionOptions(
}

export function getJestSWCOptions({
isServer,
filename,
esm,
modularizeImports,
Expand All @@ -247,6 +248,7 @@ export function getJestSWCOptions({
pagesDir,
hasServerComponents,
}: {
isServer: boolean
filename: string
esm: boolean
modularizeImports?: NextConfig['modularizeImports']
Expand All @@ -262,13 +264,15 @@ export function getJestSWCOptions({
jest: true,
development: false,
hasReactRefresh: false,
globalWindow: true,
globalWindow: !isServer,
modularizeImports,
swcPlugins,
compilerOptions,
jsConfig,
hasServerComponents,
resolvedBaseUrl,
// Don't apply server layer transformations for Jest
isServerLayer: false,
})

const isNextDist = nextDistPath.test(filename)
Expand Down

0 comments on commit 39a66d5

Please sign in to comment.