Skip to content

Commit affafa3

Browse files
authored
Turbopack build: Fix preload-viewport tests (vercel#67589)
- Skip a test that only applies to webpack as it relies on the chunk loading - Updated a test to look for the scheme that works in both Turbopack and Webpack <!-- 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 # -->
1 parent 90fa258 commit affafa3

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

test/integration/preload-viewport/test/index.test.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,33 +410,38 @@ describe('Prefetching Links in viewport', () => {
410410
expect(found).toBe(false)
411411
})
412412

413-
it('should not prefetch already loaded scripts', async () => {
414-
const browser = await webdriver(appPort, '/')
413+
// Turbopack handling of chunks is different, by default it does not include a script tag for the page itself.
414+
;(process.env.TURBOPACK ? it.skip : it)(
415+
'should not prefetch already loaded scripts',
416+
async () => {
417+
const browser = await webdriver(appPort, '/')
415418

416-
const scriptSrcs = await browser.eval(`(function() {
419+
const scriptSrcs = await browser.eval(`(function() {
417420
return Array.from(document.querySelectorAll('script'))
418421
.map(function(el) {
419422
return el.src && new URL(el.src).pathname
420423
}).filter(Boolean)
421424
})()`)
422425

423-
await browser.eval('next.router.prefetch("/")')
426+
await browser.eval('next.router.prefetch("/")')
424427

425-
const linkHrefs = await browser.eval(`(function() {
428+
const linkHrefs = await browser.eval(`(function() {
426429
return Array.from(document.querySelectorAll('link'))
427430
.map(function(el) {
428431
return el.href && new URL(el.href).pathname
429432
}).filter(Boolean)
430433
})()`)
431434

432-
console.log({ linkHrefs, scriptSrcs })
433-
expect(scriptSrcs.some((src) => src.includes('pages/index-'))).toBe(
434-
true
435-
)
436-
expect(linkHrefs.some((href) => href.includes('pages/index-'))).toBe(
437-
false
438-
)
439-
})
435+
// eslint-disable-next-line jest/no-standalone-expect
436+
expect(scriptSrcs.some((src) => src.includes('pages/index-'))).toBe(
437+
true
438+
)
439+
// eslint-disable-next-line jest/no-standalone-expect
440+
expect(linkHrefs.some((href) => href.includes('pages/index-'))).toBe(
441+
false
442+
)
443+
}
444+
)
440445

441446
it('should not duplicate prefetches', async () => {
442447
const browser = await webdriver(appPort, '/multi-prefetch')
@@ -454,7 +459,7 @@ describe('Prefetching Links in viewport', () => {
454459
expect(hrefs).toEqual([...new Set(hrefs)])
455460

456461
// Verify encoding
457-
expect(hrefs.some((e) => e.includes(`%5Bhello%5D-`))).toBe(true)
462+
expect(hrefs.some((e) => e.includes(`%5Bhello%5D`))).toBe(true)
458463
})
459464

460465
it('should not re-prefetch for an already prefetched page', async () => {

test/turbopack-build-tests-manifest.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13662,13 +13662,13 @@
1366213662
"Prefetching Links in viewport production mode should prefetch with link in viewport on scroll",
1366313663
"Prefetching Links in viewport production mode should prefetch with link in viewport onload",
1366413664
"Prefetching Links in viewport production mode should prefetch with link in viewport when href changes",
13665-
"Prefetching Links in viewport production mode should prefetch with non-bot UA"
13666-
],
13667-
"failed": [
13668-
"Prefetching Links in viewport production mode should not prefetch already loaded scripts",
13665+
"Prefetching Links in viewport production mode should prefetch with non-bot UA",
1366913666
"Prefetching Links in viewport production mode should not duplicate prefetches"
1367013667
],
13671-
"pending": [],
13668+
"failed": [],
13669+
"pending": [
13670+
"Prefetching Links in viewport production mode should not prefetch already loaded scripts"
13671+
],
1367213672
"flakey": [],
1367313673
"runtimeError": false
1367413674
},

0 commit comments

Comments
 (0)