Repository: vercel/next.js
Pull request: Turbopack: check css requests in test

<!-- 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 PACK-4318

Changed files:
filename: test/e2e/app-dir/css-order/app/nav.tsx
patch: @@ -159,6 +159,7 @@ export default function Nav() {
           <Link
             href={'/pages/partial-reversed/a'}
             id="pages-partial-reversed-a"
+            prefetch={false}
           >
             Partial Reversed A
           </Link>
@@ -167,6 +168,7 @@ export default function Nav() {
           <Link
             href={'/pages/partial-reversed/b'}
             id="pages-partial-reversed-b"
+            prefetch={false}
           >
             Partial Reversed B
           </Link>

filename: test/e2e/app-dir/css-order/css-order.test.ts
patch: @@ -28,49 +28,58 @@ const PAGES: Record<
     conflictTurbo?: boolean
     brokenLoading?: boolean
     brokenLoadingDev?: boolean
+    requests?: number
+    requestsLoose?: number
   }
 > = {
   first: {
     group: 'basic',
     url: '/first',
     selector: '#hello1',
     color: 'rgb(0, 0, 255)',
+    requests: 1,
   },
   second: {
     group: 'basic',
     url: '/second',
     selector: '#hello2',
     color: 'rgb(0, 128, 0)',
+    requests: 1,
   },
   third: {
     group: 'basic',
     url: '/third',
     selector: '#hello3',
     color: 'rgb(0, 128, 128)',
+    requests: 1,
   },
   'first-client': {
     group: 'basic',
     url: '/first-client',
     selector: '#hello1c',
     color: 'rgb(255, 0, 255)',
+    requests: 1,
   },
   'second-client': {
     group: 'basic',
     url: '/second-client',
     selector: '#hello2c',
     color: 'rgb(255, 128, 0)',
+    requests: 1,
   },
   'interleaved-a': {
     group: 'interleaved',
     url: '/interleaved/a',
     selector: '#helloia',
     color: 'rgb(0, 255, 0)',
+    requests: 1,
   },
   'interleaved-b': {
     group: 'interleaved',
     url: '/interleaved/b',
     selector: '#helloib',
     color: 'rgb(255, 0, 255)',
+    requests: 1,
   },
   'big-interleaved-a': {
     group: 'big-interleaved',
@@ -79,6 +88,7 @@ const PAGES: Record<
     url: '/big-interleaved/a',
     selector: '#hellobia',
     color: 'rgb(166, 255, 0)',
+    requests: 4,
   },
   'big-interleaved-b': {
     group: 'big-interleaved',
@@ -87,20 +97,23 @@ const PAGES: Record<
     url: '/big-interleaved/b',
     selector: '#hellobib',
     color: 'rgb(166, 0, 255)',
+    requests: 4,
   },
   'reversed-a': {
     group: 'reversed',
     conflict: true,
     url: '/reversed/a',
     selector: '#hellora',
     color: 'rgb(0, 166, 255)',
+    requests: 3,
   },
   'reversed-b': {
     group: 'reversed',
     conflict: true,
     url: '/reversed/b',
     selector: '#hellorb',
     color: 'rgb(0, 89, 255)',
+    requests: 3,
   },
   'partial-reversed-a': {
     group: 'partial-reversed',
@@ -109,6 +122,7 @@ const PAGES: Record<
     selector: '#hellopra',
     color: 'rgb(255, 166, 255)',
     background: 'rgba(0, 0, 0, 0)',
+    requests: 4,
   },
   'partial-reversed-b': {
     group: 'partial-reversed',
@@ -117,24 +131,28 @@ const PAGES: Record<
     selector: '#helloprb',
     color: 'rgb(255, 55, 255)',
     background: 'rgba(0, 0, 0, 0)',
+    requests: 4,
   },
   'pages-first': {
     group: 'pages-basic',
     url: '/pages/first',
     selector: '#hello1',
     color: 'rgb(0, 0, 255)',
+    requests: 1,
   },
   'pages-second': {
     group: 'pages-basic',
     url: '/pages/second',
     selector: '#hello2',
     color: 'rgb(0, 128, 0)',
+    requests: 1,
   },
   'pages-third': {
     group: 'pages-basic',
     url: '/pages/third',
     selector: '#hello3',
     color: 'rgb(0, 128, 128)',
+    requests: 1,
   },
 
   'pages-interleaved-a': {
@@ -143,13 +161,15 @@ const PAGES: Record<
     url: '/pages/interleaved/a',
     selector: '#helloia',
     color: 'rgb(0, 255, 0)',
+    requests: 1,
   },
   'pages-interleaved-b': {
     group: 'pages-interleaved',
     brokenLoadingDev: true,
     url: '/pages/interleaved/b',
     selector: '#helloib',
     color: 'rgb(255, 0, 255)',
+    requests: 1,
   },
   'pages-reversed-a': {
     group: 'pages-reversed',
@@ -159,6 +179,7 @@ const PAGES: Record<
     url: '/pages/reversed/a',
     selector: '#hellora',
     color: 'rgb(0, 166, 255)',
+    requests: 1,
   },
   'pages-reversed-b': {
     group: 'pages-reversed',
@@ -168,6 +189,7 @@ const PAGES: Record<
     url: '/pages/reversed/b',
     selector: '#hellorb',
     color: 'rgb(0, 89, 255)',
+    requests: 1,
   },
   'pages-partial-reversed-a': {
     group: 'pages-partial-reversed',
@@ -178,6 +200,7 @@ const PAGES: Record<
     selector: '#hellopra',
     color: 'rgb(255, 166, 255)',
     background: 'rgba(0, 0, 0, 0)',
+    requests: 1,
   },
   'pages-partial-reversed-b': {
     group: 'pages-partial-reversed',
@@ -188,26 +211,30 @@ const PAGES: Record<
     selector: '#helloprb',
     color: 'rgb(255, 55, 255)',
     background: 'rgba(0, 0, 0, 0)',
+    requests: 1,
   },
   'global-first': {
     group: 'global',
     conflict: true,
     url: '/global-first',
     selector: '#hello1',
     color: 'rgb(0, 255, 0)',
+    requests: 2,
   },
   'global-second': {
     group: 'global',
     conflict: true,
     url: '/global-second',
     selector: '#hello2',
     color: 'rgb(0, 0, 255)',
+    requests: 2,
   },
   vendor: {
     group: 'vendor',
     url: '/vendor',
     selector: '#vendor1',
     color: 'rgb(0, 255, 0)',
+    requests: 1,
   },
 }
 
@@ -350,7 +377,7 @@ describe.each(process.env.IS_TURBOPACK_TEST ? ['turbo'] : ['strict', 'loose'])(
 describe.each(process.env.IS_TURBOPACK_TEST ? ['turbo'] : ['strict', 'loose'])(
   'css-order %s',
   (mode: string) => {
-    const { next } = nextTestSetup(options(mode))
+    const { next, isNextDev } = nextTestSetup(options(mode))
     for (const [page, pageInfo] of Object.entries(PAGES)) {
       const name = `should load correct styles on ${page}`
       if (
@@ -367,6 +394,19 @@ describe.each(process.env.IS_TURBOPACK_TEST ? ['turbo'] : ['strict', 'loose'])(
             .waitForElementByCss(pageInfo.selector)
             .getComputedCss('color')
         ).toBe(pageInfo.color)
+        if (!isNextDev) {
+          const stylesheets = await browser.elementsByCss(
+            "link[rel='stylesheet']"
+          )
+          const files = await Promise.all(
+            Array.from(stylesheets).map((e) => e.getAttribute('href'))
+          )
+          expect(files).toHaveLength(
+            mode === 'turbo' || mode === 'loose'
+              ? pageInfo.requestsLoose || pageInfo.requests
+              : pageInfo.requests
+          )
+        }
         await browser.close()
       })
     }