Unverified Commit 0925de11 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

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
parent d4d9dc40
...@@ -69,6 +69,7 @@ const supportedTurbopackNextConfigOptions = [ ...@@ -69,6 +69,7 @@ const supportedTurbopackNextConfigOptions = [
'experimental.useLightningcss', 'experimental.useLightningcss',
'experimental.windowHistorySupport', 'experimental.windowHistorySupport',
'experimental.instrumentationHook', 'experimental.instrumentationHook',
'experimental.externalDir',
// Experimental options that don't affect compilation // Experimental options that don't affect compilation
'experimental.ppr', 'experimental.ppr',
...@@ -131,7 +132,6 @@ const supportedTurbopackNextConfigOptions = [ ...@@ -131,7 +132,6 @@ const supportedTurbopackNextConfigOptions = [
// 'experimental.craCompat', // 'experimental.craCompat',
// 'experimental.disablePostcssPresetEnv', // 'experimental.disablePostcssPresetEnv',
// 'experimental.esmExternals', // 'experimental.esmExternals',
// 'experimental.externalDir',
// This is used to force swc-loader to run regardless of finding Babel. // This is used to force swc-loader to run regardless of finding Babel.
// 'experimental.forceSwcTransforms', // 'experimental.forceSwcTransforms',
// 'experimental.fullySpecified', // 'experimental.fullySpecified',
......
import { createNextDescribe } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
createNextDescribe( // Tests Babel, not needed for Turbopack
'with babel', ;(process.env.TURBOPACK ? describe.skip : describe)('with babel', () => {
{ createNextDescribe(
files: __dirname, 'with babel',
skipDeployment: true, {
}, files: __dirname,
({ next, isNextStart }) => { skipDeployment: true,
it('should support babel in app dir', async () => { },
const $ = await next.render$('/') ({ next, isNextStart }) => {
expect($('h1').text()).toBe('hello') it('should support babel in app dir', async () => {
}) const $ = await next.render$('/')
expect($('h1').text()).toBe('hello')
if (isNextStart) {
it('should contain og package files in middleware', async () => {
const middleware = await next.readFile('.next/server/middleware.js')
// @vercel/og default font should be bundled
expect(middleware).not.toContain('noto-sans-v27-latin-regular.ttf')
}) })
if (isNextStart) {
it('should contain og package files in middleware', async () => {
const middleware = await next.readFile('.next/server/middleware.js')
// @vercel/og default font should be bundled
expect(middleware).not.toContain('noto-sans-v27-latin-regular.ttf')
})
}
} }
} )
) })
...@@ -2,35 +2,39 @@ import { createNext } from 'e2e-utils' ...@@ -2,35 +2,39 @@ import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils' import { renderViaHTTP } from 'next-test-utils'
describe('swc warnings by default', () => { // Tests Babel, not needed for Turbopack
let next: NextInstance ;(process.env.TURBOPACK ? describe.skip : describe)(
'swc warnings by default',
() => {
let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
next = await createNext({ next = await createNext({
files: { files: {
'pages/index.js': ` 'pages/index.js': `
export default function Page() { export default function Page() {
return <p>hello world</p> return <p>hello world</p>
} }
`, `,
'.babelrc': ` '.babelrc': `
{ {
"presets": ["next/babel"] "presets": ["next/babel"]
} }
`, `,
}, },
dependencies: {}, dependencies: {},
})
}) })
}) afterAll(() => next.destroy())
afterAll(() => next.destroy())
it('should have warning', async () => { it('should have warning', async () => {
await renderViaHTTP(next.url, '/') await renderViaHTTP(next.url, '/')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'Disabled SWC as replacement for Babel because of custom Babel configuration' 'Disabled SWC as replacement for Babel because of custom Babel configuration'
) )
}) })
}) }
)
describe('can force swc', () => { describe('can force swc', () => {
let next: NextInstance let next: NextInstance
......
...@@ -3,14 +3,21 @@ ...@@ -3,14 +3,21 @@
import { join } from 'path' import { join } from 'path'
import { runNextCommand } from 'next-test-utils' import { runNextCommand } from 'next-test-utils'
describe('Invalid resolve alias', () => { // Skip in Turbopack as it does not support `config.resolve.alias` from webpack.
it('should show relevant error when webpack resolve alias is wrong', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)(
const { stderr } = await runNextCommand(['build', join(__dirname, '..')], { 'Invalid resolve alias',
stderr: true, () => {
}) it('should show relevant error when webpack resolve alias is wrong', async () => {
const { stderr } = await runNextCommand(
['build', join(__dirname, '..')],
{
stderr: true,
}
)
expect(stderr).toMatch( expect(stderr).toMatch(
'webpack config.resolve.alias was incorrectly overridden. https://' 'webpack config.resolve.alias was incorrectly overridden. https://'
) )
}) })
}) }
)
...@@ -7,29 +7,36 @@ const appDir = join(__dirname, '../') ...@@ -7,29 +7,36 @@ const appDir = join(__dirname, '../')
const expectedErr = const expectedErr =
/Webpack config is undefined. You may have forgot to return properly from within the "webpack" method of your next.config.js/ /Webpack config is undefined. You may have forgot to return properly from within the "webpack" method of your next.config.js/
describe('undefined webpack config error', () => { // Tests webpack, not needed for Turbopack
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => { ;(process.env.TURBOPACK ? describe.skip : describe)(
it.skip('should show in production mode', async () => { 'undefined webpack config error',
const result = await nextBuild(appDir, [], { () => {
stdout: true, ;(process.env.TURBOPACK ? describe.skip : describe)(
stderr: true, 'production mode',
}) () => {
expect(result.stderr || '' + result.stdout || '').toMatch(expectedErr) it.skip('should show in production mode', async () => {
}) const result = await nextBuild(appDir, [], {
}) stdout: true,
stderr: true,
})
expect(result.stderr || '' + result.stdout || '').toMatch(expectedErr)
})
}
)
it('should show in dev mode', async () => { it('should show in dev mode', async () => {
let output = '' let output = ''
await launchApp(appDir, await findPort(), { await launchApp(appDir, await findPort(), {
onStderr(msg) { onStderr(msg) {
output += msg || '' output += msg || ''
}, },
ontStdout(msg) { ontStdout(msg) {
output += msg || '' output += msg || ''
}, },
}) })
expect(output).toMatch(expectedErr) expect(output).toMatch(expectedErr)
}) })
}) }
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment