Unverified Commit 5f7faac1 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

More Turbopack test fixes (#56248)

Skips additional production tests.

Follow-up to #56089

<!-- 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 #

-->
parent cb8b3a21
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils' import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
import { outdent } from 'outdent' import { outdent } from 'outdent'
...@@ -21,10 +21,7 @@ describe.each([[''], ['/docs']])( ...@@ -21,10 +21,7 @@ describe.each([[''], ['/docs']])(
beforeAll(async () => { beforeAll(async () => {
next = await createNext({ next = await createNext({
files: { files: join(__dirname, 'hmr'),
pages: new FileRef(join(__dirname, 'hmr/pages')),
components: new FileRef(join(__dirname, 'hmr/components')),
},
nextConfig: { nextConfig: {
basePath, basePath,
}, },
......
...@@ -57,7 +57,7 @@ const runTests = () => { ...@@ -57,7 +57,7 @@ const runTests = () => {
} }
describe('Auto Export', () => { describe('Auto Export', () => {
describe('production', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => { beforeAll(async () => {
await nextBuild(appDir) await nextBuild(appDir)
appPort = await findPort() appPort = await findPort()
......
...@@ -150,7 +150,7 @@ function runTests(dev) { ...@@ -150,7 +150,7 @@ function runTests(dev) {
} }
describe('CSS Module client-side navigation', () => { describe('CSS Module client-side navigation', () => {
describe('production', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
await nextBuild(appDir) await nextBuild(appDir)
......
...@@ -2817,57 +2817,62 @@ describe('Custom routes', () => { ...@@ -2817,57 +2817,62 @@ describe('Custom routes', () => {
}) })
describe('export', () => { describe('export', () => {
let exportStderr = '' ;(process.env.TURBOPACK ? describe.skip : describe)(
let exportVercelStderr = '' 'production mode',
() => {
let exportStderr = ''
let exportVercelStderr = ''
beforeAll(async () => { beforeAll(async () => {
const { stdout: buildStdout, stderr: buildStderr } = await nextBuild( const { stdout: buildStdout, stderr: buildStderr } = await nextBuild(
appDir, appDir,
['-d'], ['-d'],
{ {
stdout: true, stdout: true,
stderr: true, stderr: true,
} }
) )
const exportResult = await nextExport( const exportResult = await nextExport(
appDir, appDir,
{ outdir: join(appDir, 'out') }, { outdir: join(appDir, 'out') },
{ stderr: true } { stderr: true }
) )
const exportVercelResult = await nextExport( const exportVercelResult = await nextExport(
appDir, appDir,
{ outdir: join(appDir, 'out') }, { outdir: join(appDir, 'out') },
{ {
stderr: true, stderr: true,
env: { env: {
NOW_BUILDER: '1', NOW_BUILDER: '1',
}, },
} }
) )
stdout = buildStdout stdout = buildStdout
stderr = buildStderr stderr = buildStderr
exportStderr = exportResult.stderr exportStderr = exportResult.stderr
exportVercelStderr = exportVercelResult.stderr exportVercelStderr = exportVercelResult.stderr
}) })
it('should not show warning for custom routes when not next export', async () => { it('should not show warning for custom routes when not next export', async () => {
expect(stderr).not.toContain( expect(stderr).not.toContain(
`rewrites, redirects, and headers are not applied when exporting your application detected` `rewrites, redirects, and headers are not applied when exporting your application detected`
) )
}) })
it('should not show warning for custom routes when next export on Vercel', async () => { it('should not show warning for custom routes when next export on Vercel', async () => {
expect(exportVercelStderr).not.toContain( expect(exportVercelStderr).not.toContain(
`rewrites, redirects, and headers are not applied when exporting your application detected` `rewrites, redirects, and headers are not applied when exporting your application detected`
) )
}) })
it('should show warning for custom routes with next export', async () => { it('should show warning for custom routes with next export', async () => {
expect(exportStderr).toContain( expect(exportStderr).toContain(
`rewrites, redirects, and headers are not applied when exporting your application, detected (rewrites, redirects, headers)` `rewrites, redirects, and headers are not applied when exporting your application, detected (rewrites, redirects, headers)`
) )
}) })
}
)
}) })
describe('should load custom routes when only one type is used', () => { describe('should load custom routes when only one type is used', () => {
......
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
const appDir = path.join(__dirname, '..') const appDir = path.join(__dirname, '..')
describe('Handles Duplicate Pages', () => { describe('Handles Duplicate Pages', () => {
describe('production', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
it('Throws an error during build', async () => { it('Throws an error during build', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true }) const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toContain('Duplicate page detected') expect(stderr).toContain('Duplicate page detected')
......
...@@ -97,21 +97,25 @@ describe('Edge runtime configurable guards', () => { ...@@ -97,21 +97,25 @@ describe('Edge runtime configurable guards', () => {
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime` `Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
) )
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
it('fails to build because of unallowed code', async () => { 'production mode',
const output = await nextBuild(context.appDir, undefined, { () => {
stdout: true, it('fails to build because of unallowed code', async () => {
stderr: true, const output = await nextBuild(context.appDir, undefined, {
env: { NEXT_TELEMETRY_DEBUG: 1 }, stdout: true,
}) stderr: true,
expect(output.stderr).toContain(`Build failed`) env: { NEXT_TELEMETRY_DEBUG: 1 },
expect(output.stderr).toContain(`./pages/api/route.js`) })
expect(output.stderr).toContain( expect(output.stderr).toContain(`Build failed`)
`Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime` expect(output.stderr).toContain(`./pages/api/route.js`)
) expect(output.stderr).toContain(
expect(output.stderr).toContain(`Used by default`) `Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime`
expect(output.stderr).toContain(TELEMETRY_EVENT_NAME) )
}) expect(output.stderr).toContain(`Used by default`)
expect(output.stderr).toContain(TELEMETRY_EVENT_NAME)
})
}
)
}) })
describe.each([ describe.each([
...@@ -297,23 +301,31 @@ describe('Edge runtime configurable guards', () => { ...@@ -297,23 +301,31 @@ describe('Edge runtime configurable guards', () => {
}, },
])('$title with allowed, unused dynamic code', ({ init, url }) => { ])('$title with allowed, unused dynamic code', ({ init, url }) => {
beforeEach(() => init()) beforeEach(() => init())
;(process.env.TURBOPACK ? describe.skip : describe)(
it('build and does not warn at runtime', async () => { 'production mode',
const output = await nextBuild(context.appDir, undefined, { () => {
stdout: true, it('build and does not warn at runtime', async () => {
stderr: true, const output = await nextBuild(context.appDir, undefined, {
env: { NEXT_TELEMETRY_DEBUG: 1 }, stdout: true,
}) stderr: true,
expect(output.stderr).not.toContain(`Build failed`) env: { NEXT_TELEMETRY_DEBUG: 1 },
expect(output.stderr).toContain(TELEMETRY_EVENT_NAME) })
context.app = await nextStart(context.appDir, context.appPort, appOption) expect(output.stderr).not.toContain(`Build failed`)
const res = await fetchViaHTTP(context.appPort, url) expect(output.stderr).toContain(TELEMETRY_EVENT_NAME)
expect(res.status).toBe(200) context.app = await nextStart(
expect(context.logs.output).not.toContain(`warn`) context.appDir,
expect(context.logs.output).not.toContain( context.appPort,
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime` appOption
) )
}) const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(200)
expect(context.logs.output).not.toContain(`warn`)
expect(context.logs.output).not.toContain(
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
)
})
}
)
}) })
describe.each([ describe.each([
...@@ -373,19 +385,23 @@ describe('Edge runtime configurable guards', () => { ...@@ -373,19 +385,23 @@ describe('Edge runtime configurable guards', () => {
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime` `Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
) )
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
it('fails to build because of dynamic code evaluation', async () => { 'production mode',
const output = await nextBuild(context.appDir, undefined, { () => {
stdout: true, it('fails to build because of dynamic code evaluation', async () => {
stderr: true, const output = await nextBuild(context.appDir, undefined, {
env: { NEXT_TELEMETRY_DEBUG: 1 }, stdout: true,
}) stderr: true,
expect(output.stderr).toContain(`Build failed`) env: { NEXT_TELEMETRY_DEBUG: 1 },
expect(output.stderr).toContain( })
`Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime` expect(output.stderr).toContain(`Build failed`)
) expect(output.stderr).toContain(
expect(output.stderr).toContain(TELEMETRY_EVENT_NAME) `Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime`
}) )
expect(output.stderr).toContain(TELEMETRY_EVENT_NAME)
})
}
)
}) })
describe.each([ describe.each([
...@@ -427,21 +443,29 @@ describe('Edge runtime configurable guards', () => { ...@@ -427,21 +443,29 @@ describe('Edge runtime configurable guards', () => {
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime` `Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
) )
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
// eslint-disable-next-line jest/no-identical-title 'production mode',
it('build and does not warn at runtime', async () => { () => {
const output = await nextBuild(context.appDir, undefined, { // eslint-disable-next-line jest/no-identical-title
stdout: true, it('build and does not warn at runtime', async () => {
stderr: true, const output = await nextBuild(context.appDir, undefined, {
}) stdout: true,
expect(output.stderr).not.toContain(`Build failed`) stderr: true,
context.app = await nextStart(context.appDir, context.appPort, appOption) })
const res = await fetchViaHTTP(context.appPort, url) expect(output.stderr).not.toContain(`Build failed`)
expect(res.status).toBe(200) context.app = await nextStart(
expect(context.logs.output).not.toContain(`warn`) context.appDir,
expect(context.logs.output).not.toContain( context.appPort,
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime` appOption
) )
}) const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(200)
expect(context.logs.output).not.toContain(`warn`)
expect(context.logs.output).not.toContain(
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
)
})
}
)
}) })
}) })
...@@ -11,7 +11,7 @@ import { join } from 'path' ...@@ -11,7 +11,7 @@ import { join } from 'path'
const appDir = join(__dirname, '../app') const appDir = join(__dirname, '../app')
describe('Image Generation', () => { describe('Image Generation', () => {
describe('Prod', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
let app let app
let appPort let appPort
......
...@@ -10,53 +10,54 @@ const indexPage = join(appDir, 'pages/index.js') ...@@ -10,53 +10,54 @@ const indexPage = join(appDir, 'pages/index.js')
const indexPageBak = `${indexPage}.bak` const indexPageBak = `${indexPage}.bak`
describe('Mixed getStaticProps and getServerSideProps error', () => { describe('Mixed getStaticProps and getServerSideProps error', () => {
it('should error with getStaticProps but no default export', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
// TODO: remove after investigating why dev swc build fails here it('should error with getStaticProps but no default export', async () => {
await fs.writeFile( // TODO: remove after investigating why dev swc build fails here
join(appDir, '.babelrc'), await fs.writeFile(
'{ "presets": ["next/babel"] }' join(appDir, '.babelrc'),
) '{ "presets": ["next/babel"] }'
await fs.move(indexPage, indexPageBak) )
await fs.writeFile( await fs.move(indexPage, indexPageBak)
indexPage, await fs.writeFile(
` indexPage,
`
export function getStaticProps() { export function getStaticProps() {
return { return {
props: {} props: {}
} }
} }
` `
) )
const { stderr } = await nextBuild(appDir, [], { stderr: true }) const { stderr } = await nextBuild(appDir, [], { stderr: true })
await fs.remove(join(appDir, '.babelrc')) await fs.remove(join(appDir, '.babelrc'))
await fs.remove(indexPage) await fs.remove(indexPage)
await fs.move(indexPageBak, indexPage) await fs.move(indexPageBak, indexPage)
expect(stderr).toContain( expect(stderr).toContain(
'found page without a React Component as default export in' 'found page without a React Component as default export in'
) )
}) })
it('should error when exporting both getStaticProps and getServerSideProps', async () => { it('should error when exporting both getStaticProps and getServerSideProps', async () => {
// TODO: remove after investigating why dev swc build fails here // TODO: remove after investigating why dev swc build fails here
await fs.writeFile( await fs.writeFile(
join(appDir, '.babelrc'), join(appDir, '.babelrc'),
'{ "presets": ["next/babel"] }' '{ "presets": ["next/babel"] }'
) )
const { stderr } = await nextBuild(appDir, [], { stderr: true }) const { stderr } = await nextBuild(appDir, [], { stderr: true })
await fs.remove(join(appDir, '.babelrc')) await fs.remove(join(appDir, '.babelrc'))
expect(stderr).toContain(SERVER_PROPS_SSG_CONFLICT) expect(stderr).toContain(SERVER_PROPS_SSG_CONFLICT)
}) })
it('should error when exporting both getStaticPaths and getServerSideProps', async () => { it('should error when exporting both getStaticPaths and getServerSideProps', async () => {
// TODO: remove after investigating why dev swc build fails here // TODO: remove after investigating why dev swc build fails here
await fs.writeFile( await fs.writeFile(
join(appDir, '.babelrc'), join(appDir, '.babelrc'),
'{ "presets": ["next/babel"] }' '{ "presets": ["next/babel"] }'
) )
await fs.move(indexPage, indexPageBak) await fs.move(indexPage, indexPageBak)
await fs.writeFile( await fs.writeFile(
indexPage, indexPage,
` `
export const getStaticPaths = async () => { export const getStaticPaths = async () => {
return { return {
props: { world: 'world' }, fallback: true props: { world: 'world' }, fallback: true
...@@ -71,20 +72,20 @@ describe('Mixed getStaticProps and getServerSideProps error', () => { ...@@ -71,20 +72,20 @@ describe('Mixed getStaticProps and getServerSideProps error', () => {
export default ({ world }) => <p>Hello {world}</p> export default ({ world }) => <p>Hello {world}</p>
` `
) )
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
await fs.remove(join(appDir, '.babelrc')) await fs.remove(join(appDir, '.babelrc'))
await fs.remove(indexPage) await fs.remove(indexPage)
await fs.move(indexPageBak, indexPage) await fs.move(indexPageBak, indexPage)
expect(code).toBe(1) expect(code).toBe(1)
expect(stderr).toContain(SERVER_PROPS_SSG_CONFLICT) expect(stderr).toContain(SERVER_PROPS_SSG_CONFLICT)
}) })
it('should error when exporting getStaticPaths on a non-dynamic page', async () => { it('should error when exporting getStaticPaths on a non-dynamic page', async () => {
await fs.move(indexPage, indexPageBak) await fs.move(indexPage, indexPageBak)
await fs.writeFile( await fs.writeFile(
indexPage, indexPage,
` `
export const getStaticPaths = async () => { export const getStaticPaths = async () => {
return { return {
props: { world: 'world' }, fallback: true props: { world: 'world' }, fallback: true
...@@ -93,14 +94,15 @@ describe('Mixed getStaticProps and getServerSideProps error', () => { ...@@ -93,14 +94,15 @@ describe('Mixed getStaticProps and getServerSideProps error', () => {
export default ({ world }) => <p>Hello {world}</p> export default ({ world }) => <p>Hello {world}</p>
` `
) )
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
await fs.remove(indexPage) await fs.remove(indexPage)
await fs.move(indexPageBak, indexPage) await fs.move(indexPageBak, indexPage)
expect(code).toBe(1) expect(code).toBe(1)
expect(stderr).toContain( expect(stderr).toContain(
"getStaticPaths is only allowed for dynamic SSG pages and was found on '/'." "getStaticPaths is only allowed for dynamic SSG pages and was found on '/'."
) )
})
}) })
}) })
...@@ -19,7 +19,7 @@ let app ...@@ -19,7 +19,7 @@ let app
let proxyServer: http.Server let proxyServer: http.Server
let cancelCount = 0 let cancelCount = 0
describe('react-virtualized wrapping next/legacy/image', () => { describe('react-virtualized wrapping next/legacy/image', () => {
describe('production', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
await nextBuild(appDir) await nextBuild(appDir)
......
...@@ -19,7 +19,7 @@ let app ...@@ -19,7 +19,7 @@ let app
let proxyServer: http.Server let proxyServer: http.Server
let cancelCount = 0 let cancelCount = 0
describe('react-virtualized wrapping next/image', () => { describe('react-virtualized wrapping next/image', () => {
describe('production', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
await nextBuild(appDir) await nextBuild(appDir)
......
...@@ -38,8 +38,7 @@ describe('node-fetch-keep-alive', () => { ...@@ -38,8 +38,7 @@ describe('node-fetch-keep-alive', () => {
runTests() runTests()
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('production', () => {
beforeAll(async () => { beforeAll(async () => {
mockServer = createServer((req, res) => { mockServer = createServer((req, res) => {
// we can test request headers by sending them // we can test request headers by sending them
......
...@@ -38,11 +38,13 @@ function runTests() { ...@@ -38,11 +38,13 @@ function runTests() {
} }
describe('Production browser sourcemaps', () => { describe('Production browser sourcemaps', () => {
describe('Server support', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => { describe('Server support', () => {
await nextBuild(appDir, [], {}) beforeAll(async () => {
}) await nextBuild(appDir, [], {})
})
runTests() runTests()
})
}) })
}) })
...@@ -10,22 +10,24 @@ import { ...@@ -10,22 +10,24 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
describe('Production Custom Build Directory', () => { describe('Production Custom Build Directory', () => {
describe('With basic usage', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
it('should render the page', async () => { describe('With basic usage', () => {
const result = await runNextCommand(['build', 'build'], { it('should render the page', async () => {
cwd: join(__dirname, '..'), const result = await runNextCommand(['build', 'build'], {
stdout: true, cwd: join(__dirname, '..'),
stderr: true, stdout: true,
}) stderr: true,
expect(result.stderr).toBe('') })
expect(result.stderr).toBe('')
const appPort = await findPort() const appPort = await findPort()
const app = await nextStart(join(__dirname, '../build'), appPort) const app = await nextStart(join(__dirname, '../build'), appPort)
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/) expect(html).toMatch(/Hello World/)
await killApp(app) await killApp(app)
})
}) })
}) })
}) })
...@@ -16,64 +16,66 @@ let app ...@@ -16,64 +16,66 @@ let app
let appPort let appPort
describe('Production Config Usage', () => { describe('Production Config Usage', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir) beforeAll(async () => {
appPort = await findPort() await nextBuild(appDir)
app = await nextStart(appDir, appPort) appPort = await findPort()
}) app = await nextStart(appDir, appPort)
afterAll(() => killApp(app)) })
afterAll(() => killApp(app))
describe('with generateBuildId', () => { describe('with generateBuildId', () => {
it('should add the custom buildid', async () => { it('should add the custom buildid', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
const text = await browser.elementByCss('#mounted').text() const text = await browser.elementByCss('#mounted').text()
expect(text).toMatch(/ComponentDidMount executed on client\./) expect(text).toMatch(/ComponentDidMount executed on client\./)
const html = await browser.eval('document.documentElement.innerHTML') const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toMatch('custom-buildid') expect(html).toMatch('custom-buildid')
await browser.close() await browser.close()
})
}) })
})
describe('env', () => { describe('env', () => {
it('should fail with leading __ in env key', async () => { it('should fail with leading __ in env key', async () => {
const result = await runNextCommand(['build', appDir], { const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_FAIL_UNDERSCORE: true }, env: { ENABLE_ENV_FAIL_UNDERSCORE: true },
stdout: true, stdout: true,
stderr: true, stderr: true,
})
expect(result.stderr).toMatch(/The key "__NEXT_MY_VAR" under/)
}) })
expect(result.stderr).toMatch(/The key "__NEXT_MY_VAR" under/) it('should fail with NODE_ in env key', async () => {
}) const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_FAIL_NODE: true },
stdout: true,
stderr: true,
})
it('should fail with NODE_ in env key', async () => { expect(result.stderr).toMatch(/The key "NODE_ENV" under/)
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_FAIL_NODE: true },
stdout: true,
stderr: true,
}) })
expect(result.stderr).toMatch(/The key "NODE_ENV" under/) it('should fail with NEXT_RUNTIME in env key', async () => {
}) const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_NEXT_PRESERVED: true },
stdout: true,
stderr: true,
})
it('should fail with NEXT_RUNTIME in env key', async () => { expect(result.stderr).toMatch(/The key "NEXT_RUNTIME" under/)
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_NEXT_PRESERVED: true },
stdout: true,
stderr: true,
}) })
expect(result.stderr).toMatch(/The key "NEXT_RUNTIME" under/) it('should allow __ within env key', async () => {
}) const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_WITH_UNDERSCORES: true },
stdout: true,
stderr: true,
})
it('should allow __ within env key', async () => { expect(result.stderr).not.toMatch(/The key "SOME__ENV__VAR" under/)
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_WITH_UNDERSCORES: true },
stdout: true,
stderr: true,
}) })
expect(result.stderr).not.toMatch(/The key "SOME__ENV__VAR" under/)
}) })
}) })
}) })
...@@ -10,25 +10,27 @@ let appPort ...@@ -10,25 +10,27 @@ let appPort
let app let app
describe('Production Usage', () => { describe('Production Usage', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir) beforeAll(async () => {
// use compatible port: https://www.browserstack.com/question/664 await nextBuild(appDir)
appPort = await getPort({ // use compatible port: https://www.browserstack.com/question/664
port: [8080, 8081, 8888, 8899], appPort = await getPort({
port: [8080, 8081, 8888, 8899],
})
app = await nextStart(appDir, appPort)
}) })
app = await nextStart(appDir, appPort) afterAll(() => killApp(app))
})
afterAll(() => killApp(app))
it('should navigate forward and back correctly', async () => { it('should navigate forward and back correctly', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
await browser.eval('window.beforeNav = true') await browser.eval('window.beforeNav = true')
await browser.elementByCss('#to-another').click() await browser.elementByCss('#to-another').click()
// waitForElement doesn't seem to work properly in safari 10 // waitForElement doesn't seem to work properly in safari 10
await waitFor(2000) await waitFor(2000)
expect(await browser.eval('window.beforeNav')).toBe(true) expect(await browser.eval('window.beforeNav')).toBe(true)
await browser.elementByCss('#to-index').click() await browser.elementByCss('#to-index').click()
await waitFor(2000) await waitFor(2000)
expect(await browser.eval('window.beforeNav')).toBe(true) expect(await browser.eval('window.beforeNav')).toBe(true)
})
}) })
}) })
...@@ -439,39 +439,41 @@ describe('404 handling', () => { ...@@ -439,39 +439,41 @@ describe('404 handling', () => {
isDev: true, isDev: true,
}) })
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
describe('production', () => { 'production mode',
beforeAll(async () => { () => {
await nextBuild(appDir, [], nextOpts)
})
describe('next start', () => {
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() await nextBuild(appDir, [], nextOpts)
app = await nextStart(appDir, appPort, nextOpts)
}) })
afterAll(() => killApp(app)) describe('next start', () => {
beforeAll(async () => {
runTests({ appPort = await findPort()
isPages404, app = await nextStart(appDir, appPort, nextOpts)
})
afterAll(() => killApp(app))
runTests({
isPages404,
})
}) })
})
describe('next export', () => { describe('next export', () => {
beforeAll(async () => { beforeAll(async () => {
await nextExport(appDir, { outdir }, nextOpts) await nextExport(appDir, { outdir }, nextOpts)
app = await startStaticServer(outdir, join(outdir, '404.html')) app = await startStaticServer(outdir, join(outdir, '404.html'))
appPort = app.address().port appPort = app.address().port
})
afterAll(() => {
stopApp(app)
})
runTests({
isPages404,
isExport: true,
})
}) })
afterAll(() => { }
stopApp(app) )
})
runTests({
isPages404,
isExport: true,
})
})
})
} }
describe('custom _error', () => { describe('custom _error', () => {
...@@ -479,14 +481,17 @@ describe('404 handling', () => { ...@@ -479,14 +481,17 @@ describe('404 handling', () => {
}) })
describe('pages/404', () => { describe('pages/404', () => {
const pagesErr = join(appDir, 'pages/_error.js') ;(process.env.TURBOPACK ? describe.skip : describe)(
const pages404 = join(appDir, 'pages/404.js') 'production mode',
() => {
const pagesErr = join(appDir, 'pages/_error.js')
const pages404 = join(appDir, 'pages/404.js')
beforeAll(async () => { beforeAll(async () => {
await fs.move(pagesErr, pagesErr + '.bak') await fs.move(pagesErr, pagesErr + '.bak')
await fs.writeFile( await fs.writeFile(
pages404, pages404,
` `
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
window.errorLoad = true window.errorLoad = true
} }
...@@ -494,14 +499,16 @@ describe('404 handling', () => { ...@@ -494,14 +499,16 @@ describe('404 handling', () => {
return <p id='error'>custom 404</p> return <p id='error'>custom 404</p>
} }
` `
) )
await nextBuild(appDir, [], nextOpts) await nextBuild(appDir, [], nextOpts)
}) })
afterAll(async () => { afterAll(async () => {
await fs.move(pagesErr + '.bak', pagesErr) await fs.move(pagesErr + '.bak', pagesErr)
await fs.remove(pages404) await fs.remove(pages404)
}) })
devStartAndExport(true) devStartAndExport(true)
}
)
}) })
}) })
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