Skip to content

Commit

Permalink
Turbopack: Improve edge tests (#76607)
Browse files Browse the repository at this point in the history
## What?

Improves the test to check not just the one output file but all files
related to the route. This makes it clearer why Turbopack fails instead
of failing on the file not existing. It does not attempt to fix the
test, only makes it easier to fix it later.

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

-->
  • Loading branch information
timneutkens authored Feb 28, 2025
1 parent fceb1d1 commit e3878ca
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
20 changes: 16 additions & 4 deletions test/e2e/app-dir/dynamic/dynamic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import path from 'path'

describe('app dir - next/dynamic', () => {
const { next, isNextStart, isNextDev, skipped } = nextTestSetup({
Expand Down Expand Up @@ -93,11 +94,22 @@ describe('app dir - next/dynamic', () => {

// in the server bundle should not contain client component imported through ssr: false
if (isNextStart) {
const chunkPath =
'.next/server/app/dynamic-mixed-ssr-false/client-edge/page.js'
const edgeServerChunk = await next.readFile(chunkPath)
const middlewareManifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json')
)

expect(edgeServerChunk).not.toContain('ssr-false-client-module-text')
const uniquePageFiles = [
...new Set<string>(
middlewareManifest.functions[
'/dynamic-mixed-ssr-false/client-edge/page'
].files
),
]

for (const file of uniquePageFiles) {
const contents = await next.readFile(path.join('.next', file))
expect(contents).not.toContain('ssr-false-client-module-text')
}
}
})

Expand Down
39 changes: 34 additions & 5 deletions test/e2e/app-dir/metadata-edge/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nextTestSetup } from 'e2e-utils'
import imageSize from 'image-size'
import path from 'path'

describe('app dir - Metadata API on the Edge runtime', () => {
const { next, isNextStart } = nextTestSetup({
Expand All @@ -9,13 +10,41 @@ describe('app dir - Metadata API on the Edge runtime', () => {
describe('OG image route', () => {
if (isNextStart) {
it('should not bundle `ImageResponse` into the page worker', async () => {
const pageBundle = await next.readFile('.next/server/app/page.js')
expect(pageBundle).not.toContain('ImageResponse')
const middlewareManifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json')
)

const uniquePageFiles = [
...new Set<string>(middlewareManifest.functions['/page'].files),
]

const pageFilesThatHaveImageResponse = uniquePageFiles.filter(
(file) => {
return next
.readFileSync(path.join('.next', file))
.includes('ImageResponse')
}
)

const uniqueAnotherFiles = [
...new Set<string>(
middlewareManifest.functions['/another/page'].files
),
]

const anotherFilesThatHaveImageResponse = uniqueAnotherFiles.filter(
(file) => {
return next
.readFileSync(path.join('.next', file))
.includes('ImageResponse')
}
)

const sharedPageBundle = await next.readFile(
'.next/server/app/another/page.js'
// Grab the list of files that hold `ImageResponse`. Given the chunking should create the same file for both routes it should end up being the same object.
// This test was added to ensure that we don't include `ImageResponse` in the individual page bundles: https://github.com/vercel/next.js/pull/51950.
expect(pageFilesThatHaveImageResponse).toMatchObject(
anotherFilesThatHaveImageResponse
)
expect(sharedPageBundle).not.toContain('ImageResponse')
})
}
})
Expand Down

0 comments on commit e3878ca

Please sign in to comment.