Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
185 lines
6.0 KiB
TypeScript
185 lines
6.0 KiB
TypeScript
import * as path from 'path'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import { waitForNoRedbox, retry } from 'next-test-utils'
|
|
|
|
describe('async imports in cacheComponents', () => {
|
|
const { next, isNextStart, isNextDev } = nextTestSetup({
|
|
files: path.join(__dirname, 'bundled'),
|
|
})
|
|
|
|
if (isNextStart) {
|
|
it('does not cause any routes to become (partially) dynamic', async () => {
|
|
const prerenderManifest = JSON.parse(
|
|
await next.readFile('.next/prerender-manifest.json')
|
|
)
|
|
|
|
// For the purpose of this test we don't consider an incomplete shell.
|
|
const prerenderedRoutes = Object.keys(prerenderManifest.routes)
|
|
.sort()
|
|
.filter((route) => {
|
|
const filename = route.replace(/^\//, '').replace(/^$/, 'index')
|
|
try {
|
|
return next
|
|
.readFileSync(`.next/server/app/${filename}.html`)
|
|
.endsWith('</html>')
|
|
} catch (err) {
|
|
if ('code' in err && err.code === 'ENOENT') {
|
|
// the route was prerendered, but we didn't find a HTML file for it.
|
|
// this means it must be a GET route handler, not a page
|
|
return true
|
|
} else {
|
|
throw err
|
|
}
|
|
}
|
|
})
|
|
|
|
expect(prerenderedRoutes).toMatchInlineSnapshot(`
|
|
[
|
|
"/_global-error",
|
|
"/_not-found",
|
|
"/inside-render/client/async-module",
|
|
"/inside-render/client/sync-module",
|
|
"/inside-render/route-handler/async-module",
|
|
"/inside-render/route-handler/sync-module",
|
|
"/inside-render/server/async-module",
|
|
"/inside-render/server/from-node-modules/cjs/sync-module",
|
|
"/inside-render/server/from-node-modules/esm/async-module",
|
|
"/inside-render/server/from-node-modules/esm/sync-module",
|
|
"/inside-render/server/sync-module",
|
|
"/not-instrumented/middleware",
|
|
"/outside-of-render/client/async-module",
|
|
"/outside-of-render/client/sync-module",
|
|
"/outside-of-render/server/async-module",
|
|
"/outside-of-render/server/sync-module",
|
|
]
|
|
`)
|
|
})
|
|
}
|
|
|
|
const testPage = async (href: string) => {
|
|
const browser = await next.browser(href)
|
|
expect(await browser.elementByCss('body').text()).toBe('hello')
|
|
if (isNextDev) {
|
|
await retry(async () => {
|
|
// we shouldn't get any errors from `spawnDynamicValidationInDev`
|
|
await waitForNoRedbox(browser)
|
|
})
|
|
}
|
|
}
|
|
|
|
describe('inside a server component', () => {
|
|
it('import of a sync module', async () => {
|
|
await testPage('/inside-render/server/sync-module')
|
|
})
|
|
|
|
it('import of module with top-level-await', async () => {
|
|
await testPage('/inside-render/server/async-module')
|
|
})
|
|
|
|
describe('dynamic import in node_modules', () => {
|
|
describe('in an ESM package', () => {
|
|
it('import of a sync module', async () => {
|
|
await testPage(
|
|
'/inside-render/server/from-node-modules/esm/sync-module'
|
|
)
|
|
})
|
|
|
|
it('import of module with top-level-await', async () => {
|
|
await testPage(
|
|
'/inside-render/server/from-node-modules/esm/async-module'
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('in a CJS package', () => {
|
|
// CJS can't do top-level-await, so we're only testing sync modules
|
|
it('import of a sync module', async () => {
|
|
await testPage(
|
|
'/inside-render/server/from-node-modules/cjs/sync-module'
|
|
)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('inside a client component', () => {
|
|
it('import of a sync module', async () => {
|
|
await testPage('/inside-render/client/sync-module')
|
|
})
|
|
|
|
it('import of module with top-level-await', async () => {
|
|
await testPage('/inside-render/client/async-module')
|
|
})
|
|
})
|
|
|
|
describe('inside a GET route handler', () => {
|
|
it('import of a sync module', async () => {
|
|
const result = await next
|
|
.fetch('/inside-render/route-handler/sync-module')
|
|
.then((res) => res.text())
|
|
expect(result).toBe('hello')
|
|
})
|
|
|
|
it('import of module with top-level-await', async () => {
|
|
const result = await next
|
|
.fetch('/inside-render/route-handler/async-module')
|
|
.then((res) => res.text())
|
|
expect(result).toBe('hello')
|
|
})
|
|
})
|
|
|
|
describe('outside of render', () => {
|
|
describe('server', () => {
|
|
it('import of a sync module', async () => {
|
|
await testPage('/outside-of-render/server/sync-module')
|
|
})
|
|
|
|
it('import of module with top-level-await', async () => {
|
|
await testPage('/outside-of-render/server/async-module')
|
|
})
|
|
})
|
|
|
|
describe('client', () => {
|
|
it('import of a sync module', async () => {
|
|
await testPage('/outside-of-render/client/sync-module')
|
|
})
|
|
|
|
it('import of module with top-level-await', async () => {
|
|
await testPage('/outside-of-render/client/async-module')
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('are not instrumented in edge', () => {
|
|
it('middleware', async () => {
|
|
// indirectly tests the behavior of middleware by rendering a page which the middleware matches
|
|
await testPage('/not-instrumented/middleware')
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('async imports in cacheComponents - external packages', () => {
|
|
const { next, isNextStart, skipped } = nextTestSetup({
|
|
files: path.join(__dirname, 'external'),
|
|
skipDeployment: true,
|
|
skipStart: true,
|
|
})
|
|
if (skipped) return
|
|
|
|
// This is currently expected to fail because we can only track `import()` in bundled code,
|
|
// and packages marked as external aren't bundled.
|
|
it('does not instrument import() in external packages', async () => {
|
|
const expectedError = 'https://nextjs.org/docs/messages/blocking-route'
|
|
if (isNextStart) {
|
|
// in prod, we fail during the build
|
|
await expect(() => next.start()).rejects.toThrow()
|
|
expect(next.cliOutput).toContain(expectedError)
|
|
} else {
|
|
// in dev, we fail when visiting the page
|
|
await next.start()
|
|
await next.browser('/')
|
|
await retry(() => expect(next.cliOutput).toContain(expectedError))
|
|
}
|
|
})
|
|
})
|