Unverified Commit 69f5fb26 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Skip test/integration development tests during Turbopack build test run (#63671)

## What?

Follow-up to #63665.

Ensures development tests are skipped during the production build run
for Turbopack (i.e. used to create the turbopack-build-tests-manifest).

Adds `pnpm test-dev-turbo` and `pnpm test-start-turbo` (and their
`testonly` equivalent) for running tests.

<!-- 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-2915
parent 9677c87e
......@@ -15,10 +15,14 @@
"test-types": "tsc",
"test-unit": "jest test/unit/ packages/next/ packages/font",
"test-dev": "cross-env NEXT_TEST_MODE=dev pnpm testheadless",
"test-dev-turbo": "cross-env NEXT_TEST_MODE=dev TURBOPACK=1 TURBOPACK_DEV=1 pnpm testheadless",
"test-start": "cross-env NEXT_TEST_MODE=start pnpm testheadless",
"test-start-turbo": "cross-env NEXT_TEST_MODE=start TURBOPACK=1 TURBOPACK_BUILD=1 pnpm testheadless",
"test-deploy": "cross-env NEXT_TEST_MODE=deploy pnpm testheadless",
"testonly-dev": "cross-env NEXT_TEST_MODE=dev pnpm testonly",
"testonly-dev-turbo": "cross-env NEXT_TEST_MODE=dev TURBOPACK=1 TURBOPACK_DEV=1 pnpm testonly",
"testonly-start": "cross-env NEXT_TEST_MODE=start pnpm testonly",
"testonly-start-turbo": "cross-env NEXT_TEST_MODE=start TURBOPACK=1 TURBOPACK_BUILD=1 pnpm testonly",
"testonly-deploy": "cross-env NEXT_TEST_MODE=deploy pnpm testonly",
"test": "pnpm testheadless",
"testonly": "jest --runInBand",
......
......@@ -61,31 +61,33 @@ describe('404 Page Support with _app', () => {
})
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let stderr = ''
let stdout = ''
describe('development mode', () => {
let stderr = ''
let stdout = ''
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg
},
onStdout(msg) {
stdout += msg
},
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg
},
onStdout(msg) {
stdout += msg
},
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should not show pages/404 GIP error if _app has GIP', async () => {
const res = await fetchViaHTTP(appPort, '/abc')
expect(res.status).toBe(404)
const $ = cheerio.load(await res.text())
expect($('#404-title').text()).toBe('Hi There')
expect(stderr).not.toMatch(gip404Err)
expect(stdout).not.toMatch(gip404Err)
})
})
it('should not show pages/404 GIP error if _app has GIP', async () => {
const res = await fetchViaHTTP(appPort, '/abc')
expect(res.status).toBe(404)
const $ = cheerio.load(await res.text())
expect($('#404-title').text()).toBe('Hi There')
expect(stderr).not.toMatch(gip404Err)
expect(stdout).not.toMatch(gip404Err)
})
}
)
})
......@@ -72,14 +72,16 @@ describe('Default 404 Page with custom _error', () => {
runTests('server')
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests('dev')
})
runTests('dev')
}
)
})
......@@ -113,23 +113,25 @@ describe('404 Page Support SSG', () => {
runTests()
}
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
stderr = ''
stdout = ''
app = await launchApp(appDir, appPort, {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
stderr = ''
stdout = ''
app = await launchApp(appDir, appPort, {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
})
......@@ -70,15 +70,18 @@ const runTests = (mode = 'server') => {
}
describe('404 Page Support', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests('dev')
})
runTests('dev')
}
)
describe('development mode 2', () => {
it('falls back to _error correctly without pages/404', async () => {
await fs.move(pages404, `${pages404}.bak`)
......
......@@ -183,64 +183,66 @@ describe('gsp-gssp', () => {
})
}
)
describe('development mode', () => {
it('does not show error with getStaticProps in pages/500 dev', async () => {
await fs.move(pages500, `${pages500}.bak`)
await fs.writeFile(
pages500,
`
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('does not show error with getStaticProps in pages/500 dev', async () => {
await fs.move(pages500, `${pages500}.bak`)
await fs.writeFile(
pages500,
`
const page = () => 'custom 500 page'
export const getStaticProps = () => ({ props: { a: 'b' } })
export default page
`
)
let stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
await renderViaHTTP(appPort, '/abc')
await waitFor(1000)
)
await killApp(app)
let stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
await renderViaHTTP(appPort, '/abc')
await waitFor(1000)
await fs.remove(pages500)
await fs.move(`${pages500}.bak`, pages500)
await killApp(app)
expect(stderr).not.toMatch(gip500Err)
})
await fs.remove(pages500)
await fs.move(`${pages500}.bak`, pages500)
it('shows error with getServerSideProps in pages/500 dev', async () => {
await fs.move(pages500, `${pages500}.bak`)
await fs.writeFile(
pages500,
`
expect(stderr).not.toMatch(gip500Err)
})
it('shows error with getServerSideProps in pages/500 dev', async () => {
await fs.move(pages500, `${pages500}.bak`)
await fs.writeFile(
pages500,
`
const page = () => 'custom 500 page'
export const getServerSideProps = () => ({ props: { a: 'b' } })
export default page
`
)
let stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
await renderViaHTTP(appPort, '/500')
await waitFor(1000)
)
let stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
await renderViaHTTP(appPort, '/500')
await waitFor(1000)
await killApp(app)
await killApp(app)
await fs.remove(pages500)
await fs.move(`${pages500}.bak`, pages500)
await fs.remove(pages500)
await fs.move(`${pages500}.bak`, pages500)
expect(stderr).toMatch(gip500Err)
})
})
expect(stderr).toMatch(gip500Err)
})
}
)
})
......@@ -60,16 +60,19 @@ const runTests = (mode = 'server') => {
}
describe('500 Page Support', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests('dev')
})
runTests('dev')
}
)
describe('development mode 2', () => {
it('shows error with getInitialProps in pages/500 dev', async () => {
await fs.move(pages500, `${pages500}.bak`)
......
......@@ -35,24 +35,26 @@ const appDir = join(__dirname, '../')
})
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('should run in development mode successfully', async () => {
let stderr = ''
describe('development mode', () => {
it('should run in development mode successfully', async () => {
let stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
const html = await renderViaHTTP(appPort, '/')
await killApp(app)
const html = await renderViaHTTP(appPort, '/')
await killApp(app)
expect(stderr).not.toContain('error')
expect(html).toContain('Hello from AMP')
})
})
expect(stderr).not.toContain('error')
expect(html).toContain('Hello from AMP')
})
}
)
}
)
......@@ -113,14 +113,17 @@ describe('AMP SSG Support', () => {
runTests()
}
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
describe('export mode', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
......
import { runTests } from './utils'
describe('app dir - with output export - dynamic missing gsp dev', () => {
describe('development mode', () => {
it('should error when dynamic route is missing generateStaticParams', async () => {
await runTests({
isDev: true,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set noop',
expectedErrMsg:
'Page "/another/[slug]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.',
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('should error when dynamic route is missing generateStaticParams', async () => {
await runTests({
isDev: true,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set noop',
expectedErrMsg:
'Page "/another/[slug]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.',
})
})
})
it('should error when client component has generateStaticParams', async () => {
await runTests({
isDev: true,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set client',
expectedErrMsg:
'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".',
it('should error when client component has generateStaticParams', async () => {
await runTests({
isDev: true,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set client',
expectedErrMsg:
'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".',
})
})
})
})
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic api route dev', () => {
describe('development mode', () => {
it.each([
{ dynamicApiRoute: 'undefined' },
{ dynamicApiRoute: "'error'" },
{ dynamicApiRoute: "'force-static'" },
{
dynamicApiRoute: "'force-dynamic'",
expectedErrMsg:
'export const dynamic = "force-dynamic" on page "/api/json" cannot be used with "output: export".',
},
])(
'should work in dev with dynamicApiRoute $dynamicApiRoute',
async ({ dynamicApiRoute, expectedErrMsg }) => {
await runTests({ isDev: true, dynamicApiRoute, expectedErrMsg })
}
)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it.each([
{ dynamicApiRoute: 'undefined' },
{ dynamicApiRoute: "'error'" },
{ dynamicApiRoute: "'force-static'" },
{
dynamicApiRoute: "'force-dynamic'",
expectedErrMsg:
'export const dynamic = "force-dynamic" on page "/api/json" cannot be used with "output: export".',
},
])(
'should work in dev with dynamicApiRoute $dynamicApiRoute',
async ({ dynamicApiRoute, expectedErrMsg }) => {
await runTests({ isDev: true, dynamicApiRoute, expectedErrMsg })
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic page dev', () => {
describe('development mode', () => {
it.each([
{ dynamicPage: 'undefined' },
{ dynamicPage: "'error'" },
{ dynamicPage: "'force-static'" },
{
dynamicPage: "'force-dynamic'",
expectedErrMsg:
'Page with `dynamic = "force-dynamic"` couldn\'t be exported. `output: "export"` requires all pages be renderable statically',
},
])(
'should work in dev with dynamicPage $dynamicPage',
async ({ dynamicPage, expectedErrMsg }) => {
await runTests({ isDev: true, dynamicPage, expectedErrMsg })
}
)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it.each([
{ dynamicPage: 'undefined' },
{ dynamicPage: "'error'" },
{ dynamicPage: "'force-static'" },
{
dynamicPage: "'force-dynamic'",
expectedErrMsg:
'Page with `dynamic = "force-dynamic"` couldn\'t be exported. `output: "export"` requires all pages be renderable statically',
},
])(
'should work in dev with dynamicPage $dynamicPage',
async ({ dynamicPage, expectedErrMsg }) => {
await runTests({ isDev: true, dynamicPage, expectedErrMsg })
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - trailing slash dev', () => {
describe('development mode', () => {
it.each([{ trailingSlash: false }, { trailingSlash: true }])(
"should work in dev with trailingSlash '$trailingSlash'",
async ({ trailingSlash }) => {
await runTests({ isDev: true, trailingSlash })
}
)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it.each([{ trailingSlash: false }, { trailingSlash: true }])(
"should work in dev with trailingSlash '$trailingSlash'",
async ({ trailingSlash }) => {
await runTests({ isDev: true, trailingSlash })
}
)
}
)
})
......@@ -72,28 +72,30 @@ describe('Root components import order', () => {
}
)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(join(__dirname, '../'), appPort)
})
afterAll(() => killApp(app))
it(
'root components should be imported in this order _document > _app > page in order to respect side effects',
respectsSideEffects
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(join(__dirname, '../'), appPort)
})
afterAll(() => killApp(app))
it(
'root components should be imported in this order _document > _app > page in order to respect side effects',
respectsSideEffects
)
// Test relies on webpack splitChunks overrides.
;(process.env.TURBOPACK ? describe.skip : describe)(
'Skipped in Turbopack',
() => {
it(
'_app chunks should be attached to de dom before page chunks',
respectsChunkAttachmentOrder
)
}
)
})
// Test relies on webpack splitChunks overrides.
;(process.env.TURBOPACK ? describe.skip : describe)(
'Skipped in Turbopack',
() => {
it(
'_app chunks should be attached to de dom before page chunks',
respectsChunkAttachmentOrder
)
}
)
}
)
......@@ -48,14 +48,17 @@ const runTests = () => {
}
describe('AppTree', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -104,17 +104,20 @@ function runTests(dev = false) {
}
describe('Async modules', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -33,15 +33,18 @@ const runTests = () => {
}
describe('bigint API route support', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -13,16 +13,19 @@ const appDir = join(__dirname, '../')
const errorRegex = /getStaticPaths was added without a getStaticProps in/
describe('Catches Missing getStaticProps', () => {
describe('development mode', () => {
it('should catch it in development mode', async () => {
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
const html = await renderViaHTTP(appPort, '/hello')
await killApp(app)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('should catch it in development mode', async () => {
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
const html = await renderViaHTTP(appPort, '/hello')
await killApp(app)
expect(html).toMatch(errorRegex)
})
})
expect(html).toMatch(errorRegex)
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -23,18 +23,21 @@ const runTests = (isProd = false) => {
}
describe('Client 404', () => {
describe('development mode', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort)
// pre-build page at the start
await renderViaHTTP(context.appPort, '/')
})
afterAll(() => killApp(context.server))
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort)
// pre-build page at the start
await renderViaHTTP(context.appPort, '/')
})
afterAll(() => killApp(context.server))
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -88,15 +88,18 @@ const runTests = () => {
}
describe('Client Shallow Routing', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -12,21 +12,24 @@ import {
const appDir = path.join(__dirname, '..')
describe('Errors on conflict between public file and page file', () => {
describe('development mode', () => {
it('Throws error during development', async () => {
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
const conflicts = ['/another/conflict', '/hello']
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('Throws error during development', async () => {
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
const conflicts = ['/another/conflict', '/hello']
for (const conflict of conflicts) {
const html = await renderViaHTTP(appPort, conflict)
expect(html).toMatch(
/A conflicting public file and page file was found for path/
)
}
await killApp(app)
})
})
for (const conflict of conflicts) {
const html = await renderViaHTTP(appPort, conflict)
expect(html).toMatch(
/A conflicting public file and page file was found for path/
)
}
await killApp(app)
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -509,20 +509,23 @@ module.exports = {
})
}
describe('Development Mode', () => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
tests(true)
})
tests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -27,14 +27,17 @@ const runTests = () => {
}
describe('Custom page extension', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -44,15 +44,18 @@ const runTests = () => {
}
describe('Custom routes', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -60,15 +60,17 @@ describe('Custom routes i18n with index redirect', () => {
afterAll(async () => {
server.close()
})
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -167,15 +167,17 @@ describe('Custom routes i18n', () => {
server.close()
nextConfig.restore()
})
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -2635,37 +2635,39 @@ describe('Custom routes', () => {
externalServer.close()
await fs.writeFile(nextConfigPath, nextConfigRestoreContent)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let nextConfigContent
describe('development mode', () => {
let nextConfigContent
beforeAll(async () => {
// ensure cache with rewrites disabled doesn't persist
// after enabling rewrites
await fs.remove(join(appDir, '.next'))
nextConfigContent = await fs.readFile(nextConfigPath, 'utf8')
await fs.writeFile(
nextConfigPath,
nextConfigContent.replace('// no-rewrites comment', 'return []')
)
beforeAll(async () => {
// ensure cache with rewrites disabled doesn't persist
// after enabling rewrites
await fs.remove(join(appDir, '.next'))
nextConfigContent = await fs.readFile(nextConfigPath, 'utf8')
await fs.writeFile(
nextConfigPath,
nextConfigContent.replace('// no-rewrites comment', 'return []')
)
const tempPort = await findPort()
const tempApp = await launchApp(appDir, tempPort)
await renderViaHTTP(tempPort, '/')
const tempPort = await findPort()
const tempApp = await launchApp(appDir, tempPort)
await renderViaHTTP(tempPort, '/')
await killApp(tempApp)
await fs.writeFile(nextConfigPath, nextConfigContent)
await killApp(tempApp)
await fs.writeFile(nextConfigPath, nextConfigContent)
appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(async () => {
await fs.writeFile(nextConfigPath, nextConfigContent)
await killApp(app)
})
runTests(true)
})
appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(async () => {
await fs.writeFile(nextConfigPath, nextConfigContent)
await killApp(app)
})
runTests(true)
}
)
describe('no-op rewrite', () => {
beforeAll(async () => {
......@@ -2810,9 +2812,12 @@ describe('Custom routes', () => {
})
}
describe('development mode', () => {
runSoloTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
runSoloTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -128,10 +128,12 @@ describe('GS(S)P Page Errors', () => {
origIndexPage = await fs.readFile(indexPage, 'utf8')
})
afterAll(() => fs.writeFile(indexPage, origIndexPage))
describe('development mode', () => {
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -56,38 +56,42 @@ describe('disabled runtime JS', () => {
})
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let appPort
let app
describe('development mode', () => {
let appPort
let app
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(join(__dirname, '../'), appPort)
})
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(join(__dirname, '../'), appPort)
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/)
})
// eslint-disable-next-line jest/no-identical-title
it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/)
})
it('should not have __NEXT_DATA__ script', async () => {
const html = await renderViaHTTP(appPort, '/')
// eslint-disable-next-line jest/no-identical-title
it('should not have __NEXT_DATA__ script', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect($('script#__NEXT_DATA__').length).toBe(1)
})
const $ = cheerio.load(html)
expect($('script#__NEXT_DATA__').length).toBe(1)
})
it('should have a script for each preload link', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
const preloadLinks = $('link[rel=preload]')
preloadLinks.each((idx, element) => {
const url = $(element).attr('href')
expect($(`script[src="${url}"]`).length).toBe(1)
it('should have a script for each preload link', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
const preloadLinks = $('link[rel=preload]')
preloadLinks.each((idx, element) => {
const url = $(element).attr('href')
expect($(`script[src="${url}"]`).length).toBe(1)
})
})
})
})
}
)
})
......@@ -47,30 +47,32 @@ describe('distDir', () => {
}
)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
await fs.remove(join(appDir, 'dist'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
await fs.remove(join(appDir, 'dist'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/)
})
it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/)
})
it('should build the app within the given `dist` directory', async () => {
expect(
await fs.exists(join(__dirname, `/../dist/${BUILD_MANIFEST}`))
).toBeTruthy()
})
it('should not build the app within the default `.next` directory', async () => {
expect(await fs.exists(join(__dirname, '/../.next'))).toBeFalsy()
})
})
it('should build the app within the given `dist` directory', async () => {
expect(
await fs.exists(join(__dirname, `/../dist/${BUILD_MANIFEST}`))
).toBeTruthy()
})
it('should not build the app within the default `.next` directory', async () => {
expect(await fs.exists(join(__dirname, '/../.next'))).toBeFalsy()
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -19,24 +19,26 @@ describe('Custom Document Head Warnings', () => {
await renderViaHTTP(appPort, '/')
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('warns when using a <title> in document/head', () => {
expect(output).toMatch(
/.*Warning: <title> should not be used in _document.js's <Head>\..*/
)
})
describe('development mode', () => {
it('warns when using a <title> in document/head', () => {
expect(output).toMatch(
/.*Warning: <title> should not be used in _document.js's <Head>\..*/
)
})
it('warns when using viewport meta tags in document/head', () => {
expect(output).toMatch(
/.*Warning: viewport meta tags should not be used in _document.js's <Head>\..*/
)
})
it('warns when using viewport meta tags in document/head', () => {
expect(output).toMatch(
/.*Warning: viewport meta tags should not be used in _document.js's <Head>\..*/
)
})
it('warns when using a crossOrigin attribute on document/head', () => {
expect(output).toMatch(
/.*Warning: `Head` attribute `crossOrigin` is deprecated\..*/
)
})
})
it('warns when using a crossOrigin attribute on document/head', () => {
expect(output).toMatch(
/.*Warning: `Head` attribute `crossOrigin` is deprecated\..*/
)
})
}
)
})
......@@ -32,91 +32,94 @@ function getData(html: string) {
}
describe('Test Draft Mode', () => {
describe('Development Mode', () => {
let appPort, app, browser, cookieString
it('should start development application', async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
it('should enable draft mode', async () => {
const res = await fetchViaHTTP(appPort, '/api/enable')
expect(res.status).toBe(200)
const cookies = res.headers
.get('set-cookie')
.split(',')
.map((c) => cookie.parse(c))
expect(cookies[0]).toBeTruthy()
expect(cookies[0].__prerender_bypass).toBeTruthy()
cookieString = cookie.serialize(
'__prerender_bypass',
cookies[0].__prerender_bypass
)
})
it('should return cookies to be expired after dev server reboot', async () => {
await killApp(app)
appPort = await findPort()
app = await launchApp(appDir, appPort)
const res = await fetchViaHTTP(
appPort,
'/',
{},
{ headers: { Cookie: cookieString } }
)
expect(res.status).toBe(200)
const body = await res.text()
// "err":{"name":"TypeError","message":"Cannot read property 'previewModeId' of undefined"
expect(body).not.toContain('"err"')
expect(body).not.toContain('TypeError')
expect(body).not.toContain('previewModeId')
const cookies = res.headers
.get('set-cookie')
.replace(/(=(?!Lax)\w{3}),/g, '$1')
.split(',')
.map((c) => cookie.parse(c))
expect(cookies[0]).toBeTruthy()
})
it('should start the client-side browser', async () => {
browser = await webdriver(appPort, '/api/enable')
})
it('should fetch draft data on SSR', async () => {
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#draft')
expect(await browser.elementById('draft').text()).toBe('true')
})
it('should fetch draft data on CST', async () => {
await browser.get(`http://localhost:${appPort}/to-index`)
await browser.waitForElementByCss('#to-index')
await browser.eval('window.itdidnotrefresh = "yep"')
await browser.elementById('to-index').click()
await browser.waitForElementByCss('#draft')
expect(await browser.eval('window.itdidnotrefresh')).toBe('yep')
expect(await browser.elementById('draft').text()).toBe('true')
})
it('should disable draft mode', async () => {
await browser.get(`http://localhost:${appPort}/api/disable`)
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#draft')
expect(await browser.elementById('draft').text()).toBe('false')
})
afterAll(async () => {
await browser.close()
await killApp(app)
})
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let appPort, app, browser, cookieString
it('should start development application', async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
it('should enable draft mode', async () => {
const res = await fetchViaHTTP(appPort, '/api/enable')
expect(res.status).toBe(200)
const cookies = res.headers
.get('set-cookie')
.split(',')
.map((c) => cookie.parse(c))
expect(cookies[0]).toBeTruthy()
expect(cookies[0].__prerender_bypass).toBeTruthy()
cookieString = cookie.serialize(
'__prerender_bypass',
cookies[0].__prerender_bypass
)
})
it('should return cookies to be expired after dev server reboot', async () => {
await killApp(app)
appPort = await findPort()
app = await launchApp(appDir, appPort)
const res = await fetchViaHTTP(
appPort,
'/',
{},
{ headers: { Cookie: cookieString } }
)
expect(res.status).toBe(200)
const body = await res.text()
// "err":{"name":"TypeError","message":"Cannot read property 'previewModeId' of undefined"
expect(body).not.toContain('"err"')
expect(body).not.toContain('TypeError')
expect(body).not.toContain('previewModeId')
const cookies = res.headers
.get('set-cookie')
.replace(/(=(?!Lax)\w{3}),/g, '$1')
.split(',')
.map((c) => cookie.parse(c))
expect(cookies[0]).toBeTruthy()
})
it('should start the client-side browser', async () => {
browser = await webdriver(appPort, '/api/enable')
})
it('should fetch draft data on SSR', async () => {
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#draft')
expect(await browser.elementById('draft').text()).toBe('true')
})
it('should fetch draft data on CST', async () => {
await browser.get(`http://localhost:${appPort}/to-index`)
await browser.waitForElementByCss('#to-index')
await browser.eval('window.itdidnotrefresh = "yep"')
await browser.elementById('to-index').click()
await browser.waitForElementByCss('#draft')
expect(await browser.eval('window.itdidnotrefresh')).toBe('yep')
expect(await browser.elementById('draft').text()).toBe('true')
})
it('should disable draft mode', async () => {
await browser.get(`http://localhost:${appPort}/api/disable`)
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#draft')
expect(await browser.elementById('draft').text()).toBe('false')
})
afterAll(async () => {
await browser.close()
await killApp(app)
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......@@ -153,6 +156,7 @@ describe('Test Draft Mode', () => {
expect(rand).toBe(initialRand)
})
// eslint-disable-next-line jest/no-identical-title
it('should enable draft mode', async () => {
const res = await fetchViaHTTP(appPort, '/api/enable')
expect(res.status).toBe(200)
......
......@@ -51,17 +51,20 @@ function runTests() {
const nextConfig = join(appDir, 'next.config.js')
describe('Dynamic Optional Routing Root Fallback', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -39,15 +39,18 @@ function runTests() {
const nextConfig = join(appDir, 'next.config.js')
describe('Dynamic Optional Routing', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -237,24 +237,27 @@ function runInvalidPagesTests(buildFn) {
}
describe('Dynamic Optional Routing', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
runInvalidPagesTests(async (appDir) => {
stderr = ''
await launchApp(appDir, await findPort(), {
onStderr: (msg) => {
stderr += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
})
})
afterAll(() => killApp(app))
runTests()
runInvalidPagesTests(async (appDir) => {
stderr = ''
await launchApp(appDir, await findPort(), {
onStderr: (msg) => {
stderr += msg
},
})
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -1579,18 +1579,21 @@ describe('Dynamic Routing', () => {
afterAll(() => fs.remove(middlewarePath))
}
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(nextConfig)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(nextConfig)
appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(() => killApp(app))
appPort = await findPort()
app = await launchApp(appDir, appPort)
buildId = 'development'
})
afterAll(() => killApp(app))
runTests({ dev: true })
})
runTests({ dev: true })
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -74,90 +74,93 @@ describe.each([
])(
'$title usage of dynamic code evaluation',
({ extractValue, computeRoute }) => {
describe('development mode', () => {
let output = ''
beforeAll(async () => {
context.appPort = await findPort()
context.app = await launchApp(context.appDir, context.appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let output = ''
beforeAll(async () => {
context.appPort = await findPort()
context.app = await launchApp(context.appDir, context.appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
})
})
beforeEach(() => (output = ''))
afterAll(() => killApp(context.app))
it('shows a warning when running code with eval', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-eval')
)
expect(await extractValue(res)).toEqual(100)
await waitFor(500)
expect(output).toContain(EVAL_ERROR)
// TODO check why that has a backslash on windows
expect(output).toMatch(/lib[\\/]utils\.js/)
expect(output).toContain('usingEval')
expect(stripAnsi(output)).toContain("value: eval('100')")
})
it('does not show warning when no code uses eval', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('not-using-eval')
)
expect(await extractValue(res)).toEqual(100)
await waitFor(500)
expect(output).not.toContain('Dynamic Code Evaluation')
})
it('shows a warning when running WebAssembly.compile', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-webassembly-compile')
)
expect(await extractValue(res)).toEqual(81)
await waitFor(500)
expect(output).toContain(WASM_COMPILE_ERROR)
expect(output).toMatch(/lib[\\/]wasm\.js/)
expect(output).toContain('usingWebAssemblyCompile')
expect(stripAnsi(output)).toContain(
'await WebAssembly.compile(SQUARE_WASM_BUFFER)'
)
})
it('shows a warning when running WebAssembly.instantiate with a buffer parameter', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-webassembly-instantiate-with-buffer')
)
expect(await extractValue(res)).toEqual(81)
await waitFor(500)
expect(output).toContain(WASM_INSTANTIATE_ERROR)
expect(output).toMatch(/lib[\\/]wasm\.js/)
expect(output).toContain('usingWebAssemblyInstantiateWithBuffer')
expect(stripAnsi(output)).toContain(
'await WebAssembly.instantiate(SQUARE_WASM_BUFFER, {})'
)
})
it('does not show a warning when running WebAssembly.instantiate with a module parameter', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-webassembly-instantiate')
)
expect(await extractValue(res)).toEqual(81)
await waitFor(500)
expect(output).not.toContain(WASM_INSTANTIATE_ERROR)
expect(output).not.toContain('DynamicWasmCodeGenerationWarning')
})
})
beforeEach(() => (output = ''))
afterAll(() => killApp(context.app))
it('shows a warning when running code with eval', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-eval')
)
expect(await extractValue(res)).toEqual(100)
await waitFor(500)
expect(output).toContain(EVAL_ERROR)
// TODO check why that has a backslash on windows
expect(output).toMatch(/lib[\\/]utils\.js/)
expect(output).toContain('usingEval')
expect(stripAnsi(output)).toContain("value: eval('100')")
})
it('does not show warning when no code uses eval', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('not-using-eval')
)
expect(await extractValue(res)).toEqual(100)
await waitFor(500)
expect(output).not.toContain('Dynamic Code Evaluation')
})
it('shows a warning when running WebAssembly.compile', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-webassembly-compile')
)
expect(await extractValue(res)).toEqual(81)
await waitFor(500)
expect(output).toContain(WASM_COMPILE_ERROR)
expect(output).toMatch(/lib[\\/]wasm\.js/)
expect(output).toContain('usingWebAssemblyCompile')
expect(stripAnsi(output)).toContain(
'await WebAssembly.compile(SQUARE_WASM_BUFFER)'
)
})
it('shows a warning when running WebAssembly.instantiate with a buffer parameter', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-webassembly-instantiate-with-buffer')
)
expect(await extractValue(res)).toEqual(81)
await waitFor(500)
expect(output).toContain(WASM_INSTANTIATE_ERROR)
expect(output).toMatch(/lib[\\/]wasm\.js/)
expect(output).toContain('usingWebAssemblyInstantiateWithBuffer')
expect(stripAnsi(output)).toContain(
'await WebAssembly.instantiate(SQUARE_WASM_BUFFER, {})'
)
})
it('does not show a warning when running WebAssembly.instantiate with a module parameter', async () => {
const res = await fetchViaHTTP(
context.appPort,
computeRoute('using-webassembly-instantiate')
)
expect(await extractValue(res)).toEqual(81)
await waitFor(500)
expect(output).not.toContain(WASM_INSTANTIATE_ERROR)
expect(output).not.toContain('DynamicWasmCodeGenerationWarning')
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -82,25 +82,27 @@ describe('Edge runtime code with imports', () => {
const importStatement = `await import("${moduleName}")`
beforeEach(() => init(importStatement))
describe('development mode', () => {
it('throws unsupported module error in dev at runtime and highlights the faulty line', async () => {
context.app = await launchApp(
context.appDir,
context.appPort,
appOption
)
await retry(async () => {
const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(500)
expectUnsupportedModuleDevError(
moduleName,
importStatement,
await res.text()
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('throws unsupported module error in dev at runtime and highlights the faulty line', async () => {
context.app = await launchApp(
context.appDir,
context.appPort,
appOption
)
await retry(async () => {
const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(500)
expectUnsupportedModuleDevError(
moduleName,
importStatement,
await res.text()
)
})
})
})
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......@@ -167,26 +169,28 @@ describe('Edge runtime code with imports', () => {
}
`)
})
describe('development mode', () => {
it('throws unsupported module error in dev at runtime and highlights the faulty line', async () => {
context.app = await launchApp(
context.appDir,
context.appPort,
appOption
)
const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(500)
await check(async () => {
expectUnsupportedModuleDevError(
moduleName,
importStatement,
await res.text()
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('throws unsupported module error in dev at runtime and highlights the faulty line', async () => {
context.app = await launchApp(
context.appDir,
context.appPort,
appOption
)
return 'success'
}, 'success')
})
})
const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(500)
await check(async () => {
expectUnsupportedModuleDevError(
moduleName,
importStatement,
await res.text()
)
return 'success'
}, 'success')
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -50,21 +50,24 @@ function createContext() {
return ctx
}
describe('development mode', () => {
const context = createContext()
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const context = createContext()
beforeAll(async () => {
context.appPort = await findPort()
context.app = await launchApp(appDir, context.appPort, {
...context.handler,
env: { __NEXT_TEST_WITH_DEVTOOL: '1' },
beforeAll(async () => {
context.appPort = await findPort()
context.app = await launchApp(appDir, context.appPort, {
...context.handler,
env: { __NEXT_TEST_WITH_DEVTOOL: '1' },
})
})
})
afterAll(() => killApp(context.app))
afterAll(() => killApp(context.app))
it('logs the error correctly', test(context))
})
it('logs the error correctly', test(context))
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......@@ -82,6 +85,7 @@ describe('development mode', () => {
})
})
afterAll(() => killApp(context.app))
// eslint-disable-next-line jest/no-identical-title
it('logs the error correctly', test(context))
}
)
......@@ -60,56 +60,59 @@ describe.each([
])('$title using Node.js API', ({ computeRoute }) => {
const appDir = join(__dirname, '..')
describe('development mode', () => {
let output = ''
let appPort: number
let app = null
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let output = ''
let appPort: number
let app = null
beforeAll(async () => {
output = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: '1' },
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
beforeAll(async () => {
output = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: '1' },
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it.each(undefinedProperties.map((api) => ({ api })))(
'does not throw on using $api',
async ({ api }) => {
const res = await fetchViaHTTP(appPort, computeRoute(api))
expect(res.status).toBe(200)
await waitFor(500)
expect(output).not.toInclude(`A Node.js API is used (${api})`)
}
)
it.each(undefinedProperties.map((api) => ({ api })))(
'does not throw on using $api',
async ({ api }) => {
it.each([
...unsupportedFunctions.map((api) => ({
api,
errorHighlight: `${api}(`,
})),
...unsupportedClasses.map((api) => ({
api,
errorHighlight: `new ${api}(`,
})),
])(`throws error when using $api`, async ({ api, errorHighlight }) => {
const res = await fetchViaHTTP(appPort, computeRoute(api))
expect(res.status).toBe(200)
expect(res.status).toBe(500)
await waitFor(500)
expect(output).not.toInclude(`A Node.js API is used (${api})`)
}
)
it.each([
...unsupportedFunctions.map((api) => ({
api,
errorHighlight: `${api}(`,
})),
...unsupportedClasses.map((api) => ({
api,
errorHighlight: `new ${api}(`,
})),
])(`throws error when using $api`, async ({ api, errorHighlight }) => {
const res = await fetchViaHTTP(appPort, computeRoute(api))
expect(res.status).toBe(500)
await waitFor(500)
expect(output)
.toInclude(`A Node.js API is used (${api}) which is not supported in the Edge Runtime.
expect(output)
.toInclude(`A Node.js API is used (${api}) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime`)
expect(stripAnsi(output)).toInclude(errorHighlight)
})
})
expect(stripAnsi(output)).toInclude(errorHighlight)
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -107,16 +107,19 @@ const runTests = () => {
}
describe('fallback: false rewrite', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -40,16 +40,19 @@ const runTests = () => {
}
describe('Fallback Dynamic Route Params', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -51,23 +51,26 @@ function runTests() {
}
describe('Fetch polyfill with ky-universal', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
await startApiServer()
app = await launchApp(appDir, appPort, {
env: {
NEXT_PUBLIC_API_PORT: apiServerPort,
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
await startApiServer()
app = await launchApp(appDir, appPort, {
env: {
NEXT_PUBLIC_API_PORT: apiServerPort,
},
})
})
afterAll(async () => {
await killApp(app)
await killApp(apiServer)
})
})
afterAll(async () => {
await killApp(app)
await killApp(apiServer)
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -70,23 +70,26 @@ function runTests() {
}
describe('Fetch polyfill', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
await startApiServer()
app = await launchApp(appDir, appPort, {
env: {
NEXT_PUBLIC_API_PORT: apiServerPort,
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
await startApiServer()
app = await launchApp(appDir, appPort, {
env: {
NEXT_PUBLIC_API_PORT: apiServerPort,
},
})
})
afterAll(async () => {
await killApp(app)
await killApp(apiServer)
})
})
afterAll(async () => {
await killApp(app)
await killApp(apiServer)
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -4465,23 +4465,26 @@ const copyTestFileToDist = () =>
fs.copy(join(appDir, 'test-file.txt'), join(appDir, '.next', 'test-file.txt'))
describe('File Serving', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
// don't log stdout and stderr as we're going to generate
// a lot of output from resolve mismatches
stdout: false,
stderr: false,
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
// don't log stdout and stderr as we're going to generate
// a lot of output from resolve mismatches
stdout: false,
stderr: false,
})
await copyTestFileToDist()
})
afterAll(async () => {
await killApp(app)
})
await copyTestFileToDist()
})
afterAll(async () => {
await killApp(app)
})
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -40,15 +40,18 @@ const runTests = () => {
}
describe('getInitialProps', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -174,101 +174,115 @@ function runTests(startServer = nextStart) {
}
describe('ServerSide Props Preview Mode', () => {
describe('Development Mode', () => {
let appPort, app
it('should start development application', async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
let previewCookieString
it('should enable preview mode', async () => {
const res = await fetchViaHTTP(appPort, '/api/preview', { lets: 'goooo' })
expect(res.status).toBe(200)
const cookies = res.headers.get('set-cookie').split(',').map(cookie.parse)
expect(cookies.length).toBe(2)
previewCookieString =
cookie.serialize('__prerender_bypass', cookies[0].__prerender_bypass) +
'; ' +
cookie.serialize('__next_preview_data', cookies[1].__next_preview_data)
})
it('should return cookies to be expired after dev server reboot', async () => {
await killApp(app)
appPort = await findPort()
app = await launchApp(appDir, appPort)
const res = await fetchViaHTTP(
appPort,
'/',
{},
{ headers: { Cookie: previewCookieString } }
)
expect(res.status).toBe(200)
const body = await res.text()
// "err":{"name":"TypeError","message":"Cannot read property 'previewModeId' of undefined"
expect(body).not.toContain('"err"')
expect(body).not.toContain('TypeError')
expect(body).not.toContain('previewModeId')
const cookies = res.headers
.get('set-cookie')
.replace(/(=(?!Lax)\w{3}),/g, '$1')
.split(',')
.map(cookie.parse)
expect(cookies.length).toBe(2)
})
/** @type {import('next-webdriver').Chain} */
let browser
it('should start the client-side browser', async () => {
browser = await webdriver(
appPort,
'/api/preview?' + qs.stringify({ client: 'mode' })
)
})
it('should fetch preview data on SSR', async () => {
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#props-pre')
// expect(await browser.elementById('props-pre').text()).toBe('Has No Props')
// await new Promise(resolve => setTimeout(resolve, 2000))
expect(await browser.elementById('props-pre').text()).toBe(
'true and {"client":"mode"}'
)
})
it('should fetch preview data on CST', async () => {
await browser.get(`http://localhost:${appPort}/to-index`)
await browser.waitForElementByCss('#to-index')
await browser.eval('window.itdidnotrefresh = "hello"')
await browser.elementById('to-index').click()
await browser.waitForElementByCss('#props-pre')
expect(await browser.eval('window.itdidnotrefresh')).toBe('hello')
expect(await browser.elementById('props-pre').text()).toBe(
'true and {"client":"mode"}'
)
})
it('should fetch prerendered data', async () => {
await browser.get(`http://localhost:${appPort}/api/reset`)
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#props-pre')
expect(await browser.elementById('props-pre').text()).toBe(
'false and null'
)
})
afterAll(async () => {
await browser.close()
await killApp(app)
})
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let appPort, app
it('should start development application', async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
let previewCookieString
it('should enable preview mode', async () => {
const res = await fetchViaHTTP(appPort, '/api/preview', {
lets: 'goooo',
})
expect(res.status).toBe(200)
const cookies = res.headers
.get('set-cookie')
.split(',')
.map(cookie.parse)
expect(cookies.length).toBe(2)
previewCookieString =
cookie.serialize(
'__prerender_bypass',
cookies[0].__prerender_bypass
) +
'; ' +
cookie.serialize(
'__next_preview_data',
cookies[1].__next_preview_data
)
})
it('should return cookies to be expired after dev server reboot', async () => {
await killApp(app)
appPort = await findPort()
app = await launchApp(appDir, appPort)
const res = await fetchViaHTTP(
appPort,
'/',
{},
{ headers: { Cookie: previewCookieString } }
)
expect(res.status).toBe(200)
const body = await res.text()
// "err":{"name":"TypeError","message":"Cannot read property 'previewModeId' of undefined"
expect(body).not.toContain('"err"')
expect(body).not.toContain('TypeError')
expect(body).not.toContain('previewModeId')
const cookies = res.headers
.get('set-cookie')
.replace(/(=(?!Lax)\w{3}),/g, '$1')
.split(',')
.map(cookie.parse)
expect(cookies.length).toBe(2)
})
/** @type {import('next-webdriver').Chain} */
let browser
it('should start the client-side browser', async () => {
browser = await webdriver(
appPort,
'/api/preview?' + qs.stringify({ client: 'mode' })
)
})
it('should fetch preview data on SSR', async () => {
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#props-pre')
// expect(await browser.elementById('props-pre').text()).toBe('Has No Props')
// await new Promise(resolve => setTimeout(resolve, 2000))
expect(await browser.elementById('props-pre').text()).toBe(
'true and {"client":"mode"}'
)
})
it('should fetch preview data on CST', async () => {
await browser.get(`http://localhost:${appPort}/to-index`)
await browser.waitForElementByCss('#to-index')
await browser.eval('window.itdidnotrefresh = "hello"')
await browser.elementById('to-index').click()
await browser.waitForElementByCss('#props-pre')
expect(await browser.eval('window.itdidnotrefresh')).toBe('hello')
expect(await browser.elementById('props-pre').text()).toBe(
'true and {"client":"mode"}'
)
})
it('should fetch prerendered data', async () => {
await browser.get(`http://localhost:${appPort}/api/reset`)
await browser.get(`http://localhost:${appPort}/`)
await browser.waitForElementByCss('#props-pre')
expect(await browser.elementById('props-pre').text()).toBe(
'false and null'
)
})
afterAll(async () => {
await browser.close()
await killApp(app)
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -87,9 +87,12 @@ const runTests = (isDev) => {
}
describe('gip identifiers', () => {
describe('development mode', () => {
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -31,15 +31,18 @@ const runTests = () => {
}
describe('pageProps GSSP conflict', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -480,15 +480,18 @@ const runTests = (isDev) => {
}
describe('GS(S)P Redirect Support', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -505,15 +505,18 @@ const runTests = (isDev) => {
}
describe('GS(S)P Redirect Support', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -37,15 +37,18 @@ function runTests() {
const nextConfig = join(appDir, 'next.config.js')
describe('Hashbang', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -40,16 +40,19 @@ const runTests = () => {
}
describe('Hydration', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(path.join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(path.join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -40,25 +40,27 @@ describe('i18n Support basePath', () => {
})
)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
...ctx,
isDev: true,
}
beforeAll(async () => {
nextConfig.replace(/__EXTERNAL_PORT__/g, ctx.externalPort)
await fs.remove(join(appDir, '.next'))
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
})
afterAll(async () => {
nextConfig.restore()
await killApp(curCtx.app)
})
describe('development mode', () => {
const curCtx = {
...ctx,
isDev: true,
runTests(curCtx)
}
beforeAll(async () => {
nextConfig.replace(/__EXTERNAL_PORT__/g, ctx.externalPort)
await fs.remove(join(appDir, '.next'))
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
})
afterAll(async () => {
nextConfig.restore()
await killApp(curCtx.app)
})
runTests(curCtx)
})
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -221,16 +221,19 @@ function runTests(isDev) {
}
describe('i18n Support Root Catch-all', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -108,14 +108,17 @@ const runTests = () => {
}
describe('Custom routes i18n custom error', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -85,19 +85,22 @@ function runTests() {
}
describe('i18n Support', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -85,19 +85,22 @@ function runTests() {
}
describe('i18n Support', () => {
describe('development mode', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -76,14 +76,17 @@ const runTests = () => {
}
describe('Custom routes i18n support index rewrite', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -71,14 +71,17 @@ const runTests = () => {
}
describe('Hash changes i18n', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -38,26 +38,28 @@ describe('i18n Support', () => {
})
})
afterAll(() => ctx.externalApp.close())
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
...ctx,
isDev: true,
}
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
nextConfig.replace(/__EXTERNAL_PORT__/g, ctx.externalPort)
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
curCtx.buildId = 'development'
})
afterAll(async () => {
await killApp(curCtx.app)
nextConfig.restore()
})
describe('development mode', () => {
const curCtx = {
...ctx,
isDev: true,
runTests(curCtx)
}
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
nextConfig.replace(/__EXTERNAL_PORT__/g, ctx.externalPort)
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
curCtx.buildId = 'development'
})
afterAll(async () => {
await killApp(curCtx.app)
nextConfig.restore()
})
runTests(curCtx)
})
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......@@ -421,25 +423,28 @@ describe('i18n Support', () => {
})
}
describe('development mode', () => {
const curCtx = {
...ctx,
isDev: true,
}
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
nextConfig.replace('// trailingSlash', 'trailingSlash')
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
...ctx,
isDev: true,
}
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
nextConfig.replace('// trailingSlash', 'trailingSlash')
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
})
afterAll(async () => {
nextConfig.restore()
await killApp(curCtx.app)
})
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
})
afterAll(async () => {
nextConfig.restore()
await killApp(curCtx.app)
})
runSlashTests(curCtx)
})
runSlashTests(curCtx)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......@@ -488,25 +493,28 @@ describe('i18n Support', () => {
})
}
describe('development mode', () => {
const curCtx = {
...ctx,
isDev: true,
}
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
nextConfig.replace('// trailingSlash: true', 'trailingSlash: false')
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
...ctx,
isDev: true,
}
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
nextConfig.replace('// trailingSlash: true', 'trailingSlash: false')
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
})
afterAll(async () => {
nextConfig.restore()
await killApp(curCtx.app)
})
curCtx.appPort = await findPort()
curCtx.app = await launchApp(appDir, curCtx.appPort)
})
afterAll(async () => {
nextConfig.restore()
await killApp(curCtx.app)
})
runSlashTests(curCtx)
})
runSlashTests(curCtx)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -182,15 +182,18 @@ function runTests() {
const nextConfig = join(appDir, 'next.config.js')
describe('nested index.js', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -35,14 +35,16 @@ describe('Initial Refs', () => {
runTest()
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTest()
})
runTest()
}
)
})
......@@ -578,26 +578,28 @@ const runTests = () => {
describe('Errors on invalid custom routes', () => {
afterAll(() => fs.remove(nextConfigPath))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let stderr = ''
beforeAll(() => {
getStderr = async () => {
const port = await findPort()
await launchApp(appDir, port, {
onStderr: (msg) => {
stderr += msg
},
})
return stderr
}
})
afterEach(() => {
stderr = ''
})
describe('development mode', () => {
let stderr = ''
beforeAll(() => {
getStderr = async () => {
const port = await findPort()
await launchApp(appDir, port, {
onStderr: (msg) => {
stderr += msg
},
})
return stderr
}
})
afterEach(() => {
stderr = ''
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -147,53 +147,57 @@ describe('Invalid hrefs', () => {
})
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('does not show error when mailto: is used as href on Link', async () => {
await noError('/first')
})
it('does not show error when https://google.com is used as href on Link', async () => {
await noError('/second')
})
it('shows error when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/The provided `as` value \(\/blog\/post-1\) is incompatible with the `href` value \(\/\[post\]\)/,
true
)
})
it('shows error when internal href is used with external as', async () => {
await showsError(
'/invalid-relative',
/Invalid href: "\/second" and as: "mailto:hello@example\.com", received relative href and external as/,
true
)
})
it('does not throw error when dynamic route mismatch is used on Link and params are manually provided', async () => {
await noError('/dynamic-route-mismatch-manual', true)
})
it("doesn't fail on invalid url", async () => {
await noError('/third')
})
it('shows warning when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/Mismatching `as` and `href` failed to manually provide the params: post in the `href`'s `query`/,
true,
true
)
})
})
it('does not show error when mailto: is used as href on Link', async () => {
await noError('/first')
})
it('does not show error when https://google.com is used as href on Link', async () => {
await noError('/second')
})
// eslint-disable-next-line jest/no-identical-title
it('shows error when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/The provided `as` value \(\/blog\/post-1\) is incompatible with the `href` value \(\/\[post\]\)/,
true
)
})
it('shows error when internal href is used with external as', async () => {
await showsError(
'/invalid-relative',
/Invalid href: "\/second" and as: "mailto:hello@example\.com", received relative href and external as/,
true
)
})
it('does not throw error when dynamic route mismatch is used on Link and params are manually provided', async () => {
await noError('/dynamic-route-mismatch-manual', true)
})
// eslint-disable-next-line jest/no-identical-title
it("doesn't fail on invalid url", async () => {
await noError('/third')
})
it('shows warning when dynamic route mismatch is used on Link', async () => {
await showsError(
'/dynamic-route-mismatch',
/Mismatching `as` and `href` failed to manually provide the params: post in the `href`'s `query`/,
true,
true
)
})
}
)
})
......@@ -135,24 +135,26 @@ const runTests = () => {
describe('Errors on invalid custom middleware matchers', () => {
afterAll(() => fs.remove(middlewarePath))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(() => {
getStderr = async () => {
let stderr = ''
const port = await findPort()
await launchApp(appDir, port, {
onStderr(msg) {
stderr += msg
},
})
await fetchViaHTTP(port, '/').catch(() => {})
return stderr
}
})
describe('development mode', () => {
beforeAll(() => {
getStderr = async () => {
let stderr = ''
const port = await findPort()
await launchApp(appDir, port, {
onStderr(msg) {
stderr += msg
},
})
await fetchViaHTTP(port, '/').catch(() => {})
return stderr
}
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -28,18 +28,21 @@ const runTests = () => {
}
describe('Custom routes invalid multi-match', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr: (msg) => {
stderr += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr: (msg) => {
stderr += msg
},
})
})
})
afterAll(() => killApp(app))
runTests(true)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -58,31 +58,34 @@ function runCommonTests() {
}
describe('Invalid hrefs', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runCommonTests()
it('should not show error for function component with forwardRef', async () => {
await noError('/function')
})
it('should not show error for class component as child of next/link', async () => {
await noError('/class')
})
it('should handle child ref with React.createRef', async () => {
await noError('/child-ref')
})
it('should handle child ref that is a function', async () => {
await noError('/child-ref-func')
})
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runCommonTests()
it('should not show error for function component with forwardRef', async () => {
await noError('/function')
})
it('should not show error for class component as child of next/link', async () => {
await noError('/class')
})
it('should handle child ref with React.createRef', async () => {
await noError('/child-ref')
})
it('should handle child ref that is a function', async () => {
await noError('/child-ref-func')
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -21,25 +21,28 @@ describe('Link without a router', () => {
container.remove()
container = null
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('should not throw when rendered', () => {
jest.useFakeTimers()
describe('development mode', () => {
it('should not throw when rendered', () => {
jest.useFakeTimers()
act(() => {
render(<Hello />, container)
})
act(() => {
render(<Hello />, container)
})
act(() => {
jest.runAllTimers()
})
act(() => {
jest.runAllTimers()
expect(container.textContent).toBe('Click me')
})
expect(container.textContent).toBe('Click me')
})
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
// eslint-disable-next-line jest/no-identical-title
it('should not throw when rendered', () => {
jest.useFakeTimers()
......
......@@ -23,15 +23,18 @@ function runTest() {
})
}
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTest()
})
runTest()
}
)
// TODO enable that once turbopack supports middleware in development mode
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -14,32 +14,35 @@ const context = { appDir: join(__dirname, '../'), appPort: NaN, app: null }
jest.setTimeout(1000 * 60 * 2)
describe('Middleware overriding a Node.js API', () => {
describe('development mode', () => {
let output = ''
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let output = ''
beforeAll(async () => {
output = ''
context.appPort = await findPort()
context.app = await launchApp(context.appDir, context.appPort, {
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
beforeAll(async () => {
output = ''
context.appPort = await findPort()
context.app = await launchApp(context.appDir, context.appPort, {
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
})
})
afterAll(() => killApp(context.app))
afterAll(() => killApp(context.app))
it('does not show a warning and allows overriding', async () => {
const res = await fetchViaHTTP(context.appPort, '/')
await waitFor(500)
expect(res.status).toBe(200)
expect(output).toContain('fixed-value')
expect(output).not.toContain('TypeError')
expect(output).not.toContain('A Node.js API is used (process.env')
expect(output).not.toContain('A Node.js API is used (process.cwd')
})
})
it('does not show a warning and allows overriding', async () => {
const res = await fetchViaHTTP(context.appPort, '/')
await waitFor(500)
expect(res.status).toBe(200)
expect(output).toContain('fixed-value')
expect(output).not.toContain('TypeError')
expect(output).not.toContain('A Node.js API is used (process.env')
expect(output).not.toContain('A Node.js API is used (process.cwd')
})
}
)
})
......@@ -89,16 +89,18 @@ describe.each([
])('$title', ({ setup, teardown, runTest }) => {
beforeAll(() => setup())
afterAll(() => teardown())
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTest()
})
runTest()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -31,15 +31,18 @@ function runTests() {
}
describe('next/dynamic', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -50,15 +50,18 @@ function runTests() {
;(process.env.TURBOPACK ? describe.skip : describe)(
'next/dynamic lazy compilation',
() => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -43,15 +43,18 @@ function runTests() {
}
describe('next/dynamic', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -16,35 +16,38 @@ let appPort
let app
describe('Image Component assetPrefix Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include assetPrefix when placeholder=blur during next dev', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const bgImage = await browser.eval(
`document.getElementById('${id}').style['background-image']`
)
if (process.env.TURBOPACK) {
expect(bgImage).toContain('data:image/jpeg;')
} else {
expect(bgImage).toMatch(
/\/_next\/image\?url=https%3A%2F%2Fexample.com%2Fpre%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=8&q=70/
it('should include assetPrefix when placeholder=blur during next dev', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const bgImage = await browser.eval(
`document.getElementById('${id}').style['background-image']`
)
if (process.env.TURBOPACK) {
expect(bgImage).toContain('data:image/jpeg;')
} else {
expect(bgImage).toMatch(
/\/_next\/image\?url=https%3A%2F%2Fexample.com%2Fpre%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=8&q=70/
)
}
} finally {
if (browser) {
await browser.close()
}
}
} finally {
if (browser) {
await browser.close()
}
}
})
})
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -465,15 +465,18 @@ function runTests(mode) {
}
describe('Image Component basePath Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests('dev')
})
runTests('dev')
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -139,17 +139,19 @@ describe('Static Image Component Tests for basePath', () => {
runTests()
}
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/docs/static-img')
browser = await webdriver(appPort, '/docs/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/docs/static-img')
browser = await webdriver(appPort, '/docs/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
}
)
})
......@@ -1469,17 +1469,20 @@ function runTests(mode) {
}
describe('Image Component Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests('dev')
})
runTests('dev')
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -31,26 +31,28 @@ let devOutput
})
}
)
describe('development mode', () => {
beforeAll(async () => {
devOutput = { stdout: '', stderr: '' }
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (msg) => {
devOutput.stdout += msg
},
onStderr: (msg) => {
devOutput.stderr += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
devOutput = { stdout: '', stderr: '' }
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (msg) => {
devOutput.stdout += msg
},
onStderr: (msg) => {
devOutput.stderr += msg
},
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/', {})
expect(devOutput.stderr).toBeFalsy()
})
})
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/', {})
expect(devOutput.stderr).toBeFalsy()
})
}
)
}
)
......@@ -17,33 +17,36 @@ let appPort
let app
describe('Image Component Trailing Slash Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include trailing slash when trailingSlash is set on config file during next dev', async () => {
expect.assertions(1)
let browser
it('should include trailing slash when trailingSlash is set on config file during next dev', async () => {
expect.assertions(1)
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
}
}
}
})
})
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -55,34 +55,39 @@ describe('TypeScript Image Component', () => {
})
}
)
describe('development mode', () => {
beforeAll(async () => {
output = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: handleOutput,
onStderr: handleOutput,
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
output = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: handleOutput,
onStderr: handleOutput,
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should have image types when enabled', async () => {
const envTypes = await fs.readFile(join(appDir, 'next-env.d.ts'), 'utf8')
expect(envTypes).toContain('image-types/global')
})
it('should have image types when enabled', async () => {
const envTypes = await fs.readFile(
join(appDir, 'next-env.d.ts'),
'utf8'
)
expect(envTypes).toContain('image-types/global')
})
it('should render the valid Image usage and not print error', async () => {
const html = await renderViaHTTP(appPort, '/valid', {})
expect(html).toMatch(/This is valid usage of the Image component/)
expect(output).not.toMatch(/Error: Image/)
})
it('should render the valid Image usage and not print error', async () => {
const html = await renderViaHTTP(appPort, '/valid', {})
expect(html).toMatch(/This is valid usage of the Image component/)
expect(output).not.toMatch(/Error: Image/)
})
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/invalid', {})
expect(output).toMatch(/Error: Image/)
})
})
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/invalid', {})
expect(output).toMatch(/Error: Image/)
})
}
)
describe('development mode 2', () => {
it('should remove global image types when disabled (dev)', async () => {
......
......@@ -68,20 +68,23 @@ function runTests() {
}
describe('Image Component Unicode Image URL', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
browser = await webdriver(appPort, '/')
})
afterAll(() => {
killApp(app)
if (browser) {
browser.close()
}
})
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
browser = await webdriver(appPort, '/')
})
afterAll(() => {
killApp(app)
if (browser) {
browser.close()
}
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -98,17 +98,20 @@ function runTests() {
}
describe('Unoptimized Image Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -1515,17 +1515,20 @@ function runTests(mode) {
}
describe('Image Component Default Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests('dev')
})
runTests('dev')
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -263,18 +263,20 @@ describe('Static Image Component Tests', () => {
runTests(false)
}
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/static-img')
$ = cheerio.load(html)
browser = await webdriver(appPort, '/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/static-img')
$ = cheerio.load(html)
browser = await webdriver(appPort, '/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
}
)
})
......@@ -16,46 +16,49 @@ let appPort
let app
describe('Image Component assetPrefix Tests', () => {
describe('development mode', () => {
let stdout = ''
let stderr = ''
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
let stdout = ''
let stderr = ''
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should include assetPrefix when placeholder=blur during next dev', async () => {
const browser = await webdriver(appPort, '/')
const id = 'test1'
const bgImage = await browser.eval(
`document.getElementById('${id}').style['background-image']`
)
if (process.env.TURBOPACK) {
expect(bgImage).toContain('data:image/svg+xml;')
} else {
expect(bgImage).toMatch(
/\/_next\/image\?url=https%3A%2F%2Fexample\.vercel\.sh%2Fpre%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=8&q=70/
it('should include assetPrefix when placeholder=blur during next dev', async () => {
const browser = await webdriver(appPort, '/')
const id = 'test1'
const bgImage = await browser.eval(
`document.getElementById('${id}').style['background-image']`
)
}
})
if (process.env.TURBOPACK) {
expect(bgImage).toContain('data:image/svg+xml;')
} else {
expect(bgImage).toMatch(
/\/_next\/image\?url=https%3A%2F%2Fexample\.vercel\.sh%2Fpre%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=8&q=70/
)
}
})
it('should not log a deprecation warning about using `images.domains`', async () => {
await webdriver(appPort, '/')
const warningMessage =
'The "images.domains" configuration is deprecated. Please use "images.remotePatterns" configuration instead.'
it('should not log a deprecation warning about using `images.domains`', async () => {
await webdriver(appPort, '/')
const warningMessage =
'The "images.domains" configuration is deprecated. Please use "images.remotePatterns" configuration instead.'
expect(stderr).not.toContain(warningMessage)
expect(stdout).not.toContain(warningMessage)
})
})
expect(stderr).not.toContain(warningMessage)
expect(stdout).not.toContain(warningMessage)
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......@@ -84,6 +87,7 @@ describe('Image Component assetPrefix Tests', () => {
expect(bgImage).toMatch('data:image/jpeg;base64')
})
// eslint-disable-next-line jest/no-identical-title
it('should not log a deprecation warning about using `images.domains`', async () => {
await webdriver(appPort, '/')
const warningMessage =
......
......@@ -195,17 +195,20 @@ function runTests(mode) {
}
describe('Image Component basePath Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests('dev')
})
runTests('dev')
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -209,18 +209,20 @@ describe('Static Image Component Tests for basePath', () => {
runTests(false)
}
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/docs/static-img')
$ = cheerio.load(html)
browser = await webdriver(appPort, '/docs/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/docs/static-img')
$ = cheerio.load(html)
browser = await webdriver(appPort, '/docs/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
}
)
})
......@@ -42,15 +42,18 @@ const runTests = () => {
}
describe('Image Component basePath + trailingSlash Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -1523,17 +1523,20 @@ function runTests(mode) {
}
describe('Image Component Default Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests('dev')
})
runTests('dev')
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -275,18 +275,20 @@ describe('Static Image Component Tests', () => {
runTests(false)
}
)
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/static-img')
$ = cheerio.load(html)
browser = await webdriver(appPort, '/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
html = await renderViaHTTP(appPort, '/static-img')
$ = cheerio.load(html)
browser = await webdriver(appPort, '/static-img')
})
afterAll(() => {
killApp(app)
})
runTests(true)
}
)
})
......@@ -16,26 +16,29 @@ let app
let stderr = ''
describe('next/image with output export config', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
})
})
afterAll(async () => {
await killApp(app)
stderr = ''
})
it('should error', async () => {
const browser = await webdriver(appPort, '/')
const msg =
"Image Optimization using the default loader is not compatible with `{ output: 'export' }`."
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(msg)
expect(stderr).toContain(msg)
})
})
afterAll(async () => {
await killApp(app)
stderr = ''
})
it('should error', async () => {
const browser = await webdriver(appPort, '/')
const msg =
"Image Optimization using the default loader is not compatible with `{ output: 'export' }`."
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(msg)
expect(stderr).toContain(msg)
})
}
)
})
......@@ -49,24 +49,27 @@ function runTests({ isDev }) {
}
describe('Missing Import Image Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
})
afterAll(async () => {
if (app) {
await killApp(app)
}
})
})
afterAll(async () => {
if (app) {
await killApp(app)
}
})
runTests({ isDev: true })
})
runTests({ isDev: true })
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -43,20 +43,23 @@ function runTests() {
}
describe('Image Loader Config with Edge Runtime', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
browser = await webdriver(appPort, '/')
})
afterAll(() => {
killApp(app)
if (browser) {
browser.close()
}
})
runTests()
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
browser = await webdriver(appPort, '/')
})
afterAll(() => {
killApp(app)
if (browser) {
browser.close()
}
})
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -10,30 +10,35 @@ let app: Awaited<ReturnType<typeof launchApp>>
let output = ''
describe('Image with middleware in edge func', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (s) => {
output += s
},
onStderr: (s) => {
output += s
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (s) => {
output += s
},
onStderr: (s) => {
output += s
},
})
})
afterAll(async () => {
await killApp(app)
})
})
afterAll(async () => {
await killApp(app)
})
it('should not error', async () => {
/**
it('should not error', async () => {
/**
⚠️ ../../../../packages/next/dist/esm/client/image-component.js
Attempted import error: 'preload' is not exported from 'react-dom' (imported as 'preload').
*/
await webdriver(appPort, '/')
await check(() => output, /compiled \//i)
expect(output).not.toContain(`'preload' is not exported from 'react-dom'`)
})
})
await webdriver(appPort, '/')
await check(() => output, /compiled \//i)
expect(output).not.toContain(
`'preload' is not exported from 'react-dom'`
)
})
}
)
})
......@@ -31,29 +31,31 @@ let devOutput
})
}
)
describe('development mode', () => {
beforeAll(async () => {
devOutput = { stdout: '', stderr: '' }
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (msg) => {
devOutput.stdout += msg
},
onStderr: (msg) => {
devOutput.stderr += msg
},
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
devOutput = { stdout: '', stderr: '' }
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (msg) => {
devOutput.stdout += msg
},
onStderr: (msg) => {
devOutput.stderr += msg
},
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/', {})
const errors = devOutput.stderr
.split('\n')
.filter((line) => line && !line.trim().startsWith('⚠️'))
expect(errors).toEqual([])
})
})
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/', {})
const errors = devOutput.stderr
.split('\n')
.filter((line) => line && !line.trim().startsWith('⚠️'))
expect(errors).toEqual([])
})
}
)
}
)
......@@ -17,33 +17,36 @@ let appPort
let app
describe('Image Component Trailing Slash Tests', () => {
describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include trailing slash when trailingSlash is set on config file during next dev', async () => {
expect.assertions(1)
let browser
it('should include trailing slash when trailingSlash is set on config file during next dev', async () => {
expect.assertions(1)
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
}
}
}
})
})
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
......
......@@ -55,34 +55,39 @@ describe('TypeScript Image Component', () => {
})
}
)
describe('development mode', () => {
beforeAll(async () => {
output = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: handleOutput,
onStderr: handleOutput,
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
output = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: handleOutput,
onStderr: handleOutput,
})
})
})
afterAll(() => killApp(app))
afterAll(() => killApp(app))
it('should have image types when enabled', async () => {
const envTypes = await fs.readFile(join(appDir, 'next-env.d.ts'), 'utf8')
expect(envTypes).toContain('image-types/global')
})
it('should have image types when enabled', async () => {
const envTypes = await fs.readFile(
join(appDir, 'next-env.d.ts'),
'utf8'
)
expect(envTypes).toContain('image-types/global')
})
it('should render the valid Image usage and not print error', async () => {
const html = await renderViaHTTP(appPort, '/valid', {})
expect(html).toMatch(/This is valid usage of the Image component/)
expect(output).not.toMatch(/Error: Image/)
})
it('should render the valid Image usage and not print error', async () => {
const html = await renderViaHTTP(appPort, '/valid', {})
expect(html).toMatch(/This is valid usage of the Image component/)
expect(output).not.toMatch(/Error: Image/)
})
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/invalid', {})
expect(output).toMatch(/Error: Image/)
})
})
it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/invalid', {})
expect(output).toMatch(/Error: Image/)
})
}
)
it('should remove global image types when disabled (dev)', async () => {
const content = await fs.readFile(nextConfig, 'utf8')
......
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