Skip to content

Commit 0925de1

Browse files
authored
Update tests for Turbopack (#59354)
## What? - Add support for `experimental.externalDir` -- Was already supported, just makes Turbopack not fail on that config option - Skipped `with-babel` test because it tests Babel - Skipped `swc-warnings` test because it tests Babel - Skipped `config-resolve-alias` as it tests webpack config - Skipped `undefined-webpack-config` as it tests webpack config <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> Closes NEXT-1817
1 parent d4d9dc4 commit 0925de1

File tree

5 files changed

+92
-71
lines changed

5 files changed

+92
-71
lines changed

packages/next/src/lib/turbopack-warning.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const supportedTurbopackNextConfigOptions = [
6969
'experimental.useLightningcss',
7070
'experimental.windowHistorySupport',
7171
'experimental.instrumentationHook',
72+
'experimental.externalDir',
7273

7374
// Experimental options that don't affect compilation
7475
'experimental.ppr',
@@ -131,7 +132,6 @@ const supportedTurbopackNextConfigOptions = [
131132
// 'experimental.craCompat',
132133
// 'experimental.disablePostcssPresetEnv',
133134
// 'experimental.esmExternals',
134-
// 'experimental.externalDir',
135135
// This is used to force swc-loader to run regardless of finding Babel.
136136
// 'experimental.forceSwcTransforms',
137137
// 'experimental.fullySpecified',
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import { createNextDescribe } from 'e2e-utils'
22

3-
createNextDescribe(
4-
'with babel',
5-
{
6-
files: __dirname,
7-
skipDeployment: true,
8-
},
9-
({ next, isNextStart }) => {
10-
it('should support babel in app dir', async () => {
11-
const $ = await next.render$('/')
12-
expect($('h1').text()).toBe('hello')
13-
})
14-
15-
if (isNextStart) {
16-
it('should contain og package files in middleware', async () => {
17-
const middleware = await next.readFile('.next/server/middleware.js')
18-
// @vercel/og default font should be bundled
19-
expect(middleware).not.toContain('noto-sans-v27-latin-regular.ttf')
3+
// Tests Babel, not needed for Turbopack
4+
;(process.env.TURBOPACK ? describe.skip : describe)('with babel', () => {
5+
createNextDescribe(
6+
'with babel',
7+
{
8+
files: __dirname,
9+
skipDeployment: true,
10+
},
11+
({ next, isNextStart }) => {
12+
it('should support babel in app dir', async () => {
13+
const $ = await next.render$('/')
14+
expect($('h1').text()).toBe('hello')
2015
})
16+
17+
if (isNextStart) {
18+
it('should contain og package files in middleware', async () => {
19+
const middleware = await next.readFile('.next/server/middleware.js')
20+
// @vercel/og default font should be bundled
21+
expect(middleware).not.toContain('noto-sans-v27-latin-regular.ttf')
22+
})
23+
}
2124
}
22-
}
23-
)
25+
)
26+
})

test/e2e/swc-warnings/index.test.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,39 @@ import { createNext } from 'e2e-utils'
22
import { NextInstance } from 'test/lib/next-modes/base'
33
import { renderViaHTTP } from 'next-test-utils'
44

5-
describe('swc warnings by default', () => {
6-
let next: NextInstance
5+
// Tests Babel, not needed for Turbopack
6+
;(process.env.TURBOPACK ? describe.skip : describe)(
7+
'swc warnings by default',
8+
() => {
9+
let next: NextInstance
710

8-
beforeAll(async () => {
9-
next = await createNext({
10-
files: {
11-
'pages/index.js': `
11+
beforeAll(async () => {
12+
next = await createNext({
13+
files: {
14+
'pages/index.js': `
1215
export default function Page() {
1316
return <p>hello world</p>
1417
}
1518
`,
16-
'.babelrc': `
19+
'.babelrc': `
1720
{
1821
"presets": ["next/babel"]
1922
}
2023
`,
21-
},
22-
dependencies: {},
24+
},
25+
dependencies: {},
26+
})
2327
})
24-
})
25-
afterAll(() => next.destroy())
28+
afterAll(() => next.destroy())
2629

27-
it('should have warning', async () => {
28-
await renderViaHTTP(next.url, '/')
29-
expect(next.cliOutput).toContain(
30-
'Disabled SWC as replacement for Babel because of custom Babel configuration'
31-
)
32-
})
33-
})
30+
it('should have warning', async () => {
31+
await renderViaHTTP(next.url, '/')
32+
expect(next.cliOutput).toContain(
33+
'Disabled SWC as replacement for Babel because of custom Babel configuration'
34+
)
35+
})
36+
}
37+
)
3438

3539
describe('can force swc', () => {
3640
let next: NextInstance

test/integration/config-resolve-alias/test/index.test.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
import { join } from 'path'
44
import { runNextCommand } from 'next-test-utils'
55

6-
describe('Invalid resolve alias', () => {
7-
it('should show relevant error when webpack resolve alias is wrong', async () => {
8-
const { stderr } = await runNextCommand(['build', join(__dirname, '..')], {
9-
stderr: true,
10-
})
6+
// Skip in Turbopack as it does not support `config.resolve.alias` from webpack.
7+
;(process.env.TURBOPACK ? describe.skip : describe)(
8+
'Invalid resolve alias',
9+
() => {
10+
it('should show relevant error when webpack resolve alias is wrong', async () => {
11+
const { stderr } = await runNextCommand(
12+
['build', join(__dirname, '..')],
13+
{
14+
stderr: true,
15+
}
16+
)
1117

12-
expect(stderr).toMatch(
13-
'webpack config.resolve.alias was incorrectly overridden. https://'
14-
)
15-
})
16-
})
18+
expect(stderr).toMatch(
19+
'webpack config.resolve.alias was incorrectly overridden. https://'
20+
)
21+
})
22+
}
23+
)

test/integration/undefined-webpack-config/test/index.test.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,36 @@ const appDir = join(__dirname, '../')
77
const expectedErr =
88
/Webpack config is undefined. You may have forgot to return properly from within the "webpack" method of your next.config.js/
99

10-
describe('undefined webpack config error', () => {
11-
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
12-
it.skip('should show in production mode', async () => {
13-
const result = await nextBuild(appDir, [], {
14-
stdout: true,
15-
stderr: true,
16-
})
17-
expect(result.stderr || '' + result.stdout || '').toMatch(expectedErr)
18-
})
19-
})
10+
// Tests webpack, not needed for Turbopack
11+
;(process.env.TURBOPACK ? describe.skip : describe)(
12+
'undefined webpack config error',
13+
() => {
14+
;(process.env.TURBOPACK ? describe.skip : describe)(
15+
'production mode',
16+
() => {
17+
it.skip('should show in production mode', async () => {
18+
const result = await nextBuild(appDir, [], {
19+
stdout: true,
20+
stderr: true,
21+
})
22+
expect(result.stderr || '' + result.stdout || '').toMatch(expectedErr)
23+
})
24+
}
25+
)
2026

21-
it('should show in dev mode', async () => {
22-
let output = ''
27+
it('should show in dev mode', async () => {
28+
let output = ''
2329

24-
await launchApp(appDir, await findPort(), {
25-
onStderr(msg) {
26-
output += msg || ''
27-
},
28-
ontStdout(msg) {
29-
output += msg || ''
30-
},
31-
})
30+
await launchApp(appDir, await findPort(), {
31+
onStderr(msg) {
32+
output += msg || ''
33+
},
34+
ontStdout(msg) {
35+
output += msg || ''
36+
},
37+
})
3238

33-
expect(output).toMatch(expectedErr)
34-
})
35-
})
39+
expect(output).toMatch(expectedErr)
40+
})
41+
}
42+
)

0 commit comments

Comments
 (0)