chore: restore options to opt-in for server-side transpilation (#55010)

### 🧐 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>
This commit is contained in:
Damien Simonin Feugas 2023-09-05 13:55:10 +01:00 committed by GitHub
parent 3a62a30649
commit 39a66d5a08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View file

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

View file

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

View file

@ -237,6 +237,7 @@ function getEmotionOptions(
}
export function getJestSWCOptions({
isServer,
filename,
esm,
modularizeImports,
@ -247,6 +248,7 @@ export function getJestSWCOptions({
pagesDir,
hasServerComponents,
}: {
isServer: boolean
filename: string
esm: boolean
modularizeImports?: NextConfig['modularizeImports']
@ -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)