Skip to content

Commit

Permalink
fix(47299): allow testing pages with metadata in jsdom test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Aug 4, 2023
1 parent f04dc5a commit 808b3fc
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 110 deletions.
1 change: 0 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
"image-size": "1.0.0",
"is-docker": "2.0.0",
"is-wsl": "2.2.0",
"jest-docblock": "29.4.3",
"jest-worker": "27.0.0-next.5",
"json5": "2.2.3",
"jsonwebtoken": "9.0.0",
Expand Down
19 changes: 2 additions & 17 deletions packages/next/src/build/swc/jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ DEALINGS IN THE SOFTWARE.
import vm from 'vm'
import { transformSync } from './index'
import { getJestSWCOptions } from './options'
import * as docblock from 'next/dist/compiled/jest-docblock'
import type {
TransformerCreator,
TransformOptions,
Expand Down Expand Up @@ -77,30 +76,16 @@ function isEsm(
)
}

function getTestEnvironment(
src: string,
jestConfig: Config.ProjectConfig
): string {
const docblockPragmas = docblock.parse(docblock.extract(src))
const pragma = docblockPragmas['jest-environment']
const environment =
(Array.isArray(pragma) ? pragma[0] : pragma) ?? jestConfig.testEnvironment
return environment
}

const createTransformer: TransformerCreator<
SyncTransformer<JestTransformerConfig>,
JestTransformerConfig
> = (inputOptions) => ({
process(src, filename, jestOptions) {
const jestConfig = getJestConfig(jestOptions)
const testEnvironment = getTestEnvironment(src, jestConfig)

const swcTransformOpts = getJestSWCOptions({
// When target is node it's similar to the server option set in SWC.
isServer:
testEnvironment === 'node' ||
testEnvironment.includes('jest-environment-node'),
// Always target server when compiling during test, to pass server-only validations and allow testing pages with metadatas
isServer: true,
filename,
jsConfig: inputOptions?.jsConfig,
resolvedBaseUrl: inputOptions?.resolvedBaseUrl,
Expand Down
21 changes: 0 additions & 21 deletions packages/next/src/compiled/jest-docblock/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/src/compiled/jest-docblock/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/src/compiled/jest-docblock/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/next/src/compiled/sass-loader/cjs.js

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2179,15 +2179,6 @@ export async function ncc_https_proxy_agent(task, opts) {
.target('src/compiled/https-proxy-agent')
}

// eslint-disable-next-line camelcase
externals['jest-docblock'] = 'next/dist/compiled/jest-docblock'
export async function ncc_jest_docblock(task, opts) {
await task
.source(relative(__dirname, require.resolve('jest-docblock')))
.ncc({ packageName: 'jest-docblock', externals })
.target('src/compiled/jest-docblock')
}

export async function precompile(task, opts) {
await task.parallel(
[
Expand Down Expand Up @@ -2322,7 +2313,6 @@ export async function ncc(task, opts) {
'ncc_opentelemetry_api',
'ncc_http_proxy_agent',
'ncc_https_proxy_agent',
'ncc_jest_docblock',
'ncc_mini_css_extract_plugin',
],
opts
Expand Down
5 changes: 0 additions & 5 deletions packages/next/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,3 @@ declare module 'next/dist/compiled/@opentelemetry/api' {
import * as m from '@opentelemetry/api'
export = m
}

declare module 'next/dist/compiled/jest-docblock' {
import m from 'jest-docblock'
export = m
}
Loading

0 comments on commit 808b3fc

Please sign in to comment.