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