Repository: vercel/next.js
Pull request: Turbopack Build: Fix next/font test

## What?

Fixes the test which assumed specific hashes.

While digging into this with @sokra and @mischnic we found that the reason it currently preloads 4 instead of 2 files is because of source based side-effects detection that Turbopack  does not have yet. We've created an issue to track that so that this PR can land.

Closes PACK-4658

Changed files:
filename: test/e2e/next-font/with-font-declarations-file.test.ts
patch: @@ -1,5 +1,5 @@
 import cheerio from 'cheerio'
-import { createNext, FileRef } from 'e2e-utils'
+import { createNext } from 'e2e-utils'
 import { NextInstance } from 'e2e-utils'
 import { renderViaHTTP } from 'next-test-utils'
 import { join } from 'path'
@@ -20,20 +20,7 @@ describe('next/font/google with-font-declarations-file', () => {
 
   beforeAll(async () => {
     next = await createNext({
-      files: {
-        pages: new FileRef(
-          join(__dirname, 'with-font-declarations-file/pages')
-        ),
-        components: new FileRef(
-          join(__dirname, 'with-font-declarations-file/components')
-        ),
-        'fonts.js': new FileRef(
-          join(__dirname, 'with-font-declarations-file/fonts.js')
-        ),
-        'my-font-roboto.woff2': new FileRef(
-          join(__dirname, 'with-font-declarations-file/my-font-roboto.woff2')
-        ),
-      },
+      files: join(__dirname, 'with-font-declarations-file'),
       env: {
         NEXT_FONT_GOOGLE_MOCKED_RESPONSES: mockedGoogleFontResponses,
       },
@@ -53,12 +40,17 @@ describe('next/font/google with-font-declarations-file', () => {
       expect($('link[as="font"]').length).toBe(4)
     } else {
       // Preload
-      expect($('link[as="font"]').length).toBe(2)
+      expect($('link[as="font"]').length).toBe(
+        // TODO: Remove this once tree shaking PACK-4656
+        process.env.IS_TURBOPACK_TEST ? 4 : 2
+      )
       // From /_app
       expect($('link[as="font"]').get(0).attribs).toEqual({
         as: 'font',
         crossorigin: 'anonymous',
-        href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
+        href: expect.stringMatching(
+          /\/_next\/static\/media\/.*-s\.p(\..*)?\.woff2/
+        ),
         rel: 'preload',
         type: 'font/woff2',
         'data-next-font': 'size-adjust',
@@ -67,7 +59,9 @@ describe('next/font/google with-font-declarations-file', () => {
       expect($('link[as="font"]').get(1).attribs).toEqual({
         as: 'font',
         crossorigin: 'anonymous',
-        href: '/_next/static/media/4a7f86e553ee7e51-s.p.woff2',
+        href: expect.stringMatching(
+          /\/_next\/static\/media\/.*-s\.p(\..*)?\.woff2/
+        ),
         rel: 'preload',
         type: 'font/woff2',
         'data-next-font': 'size-adjust',
@@ -87,12 +81,17 @@ describe('next/font/google with-font-declarations-file', () => {
       expect($('link[as="font"]').length).toBe(4)
     } else {
       // Preload
-      expect($('link[as="font"]').length).toBe(2)
+      expect($('link[as="font"]').length).toBe(
+        // TODO: Remove this once tree shaking PACK-4656
+        process.env.IS_TURBOPACK_TEST ? 4 : 2
+      )
       // From /_app
       expect($('link[as="font"]').get(0).attribs).toEqual({
         as: 'font',
         crossorigin: 'anonymous',
-        href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
+        href: expect.stringMatching(
+          /\/_next\/static\/media\/.*-s\.p(\..*)?\.woff2/
+        ),
         rel: 'preload',
         type: 'font/woff2',
         'data-next-font': 'size-adjust',
@@ -101,7 +100,9 @@ describe('next/font/google with-font-declarations-file', () => {
       expect($('link[as="font"]').get(1).attribs).toEqual({
         as: 'font',
         crossorigin: 'anonymous',
-        href: '/_next/static/media/9a7e84b4dd095b33-s.p.woff2',
+        href: expect.stringMatching(
+          /\/_next\/static\/media\/.*-s\.p(\..*)?\.woff2/
+        ),
         rel: 'preload',
         type: 'font/woff2',
         'data-next-font': 'size-adjust',
@@ -121,12 +122,17 @@ describe('next/font/google with-font-declarations-file', () => {
       expect($('link[as="font"]').length).toBe(4)
     } else {
       // Preload
-      expect($('link[as="font"]').length).toBe(2)
+      expect($('link[as="font"]').length).toBe(
+        // TODO: Remove this once tree shaking PACK-4656
+        process.env.IS_TURBOPACK_TEST ? 4 : 2
+      )
       // From /_app
       expect($('link[as="font"]').get(0).attribs).toEqual({
         as: 'font',
         crossorigin: 'anonymous',
-        href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
+        href: expect.stringMatching(
+          /\/_next\/static\/media\/.*-s\.p(\..*)?\.woff2/
+        ),
         rel: 'preload',
         type: 'font/woff2',
         'data-next-font': 'size-adjust',
@@ -135,7 +141,9 @@ describe('next/font/google with-font-declarations-file', () => {
       expect($('link[as="font"]').get(1).attribs).toEqual({
         as: 'font',
         crossorigin: 'anonymous',
-        href: '/_next/static/media/934c4b7cb736f2a3-s.p.woff2',
+        href: expect.stringMatching(
+          /\/_next\/static\/media\/.*-s\.p(\..*)?\.woff2/
+        ),
         rel: 'preload',
         type: 'font/woff2',
         'data-next-font': 'size-adjust',

filename: test/turbopack-build-tests-manifest.json
patch: @@ -7773,12 +7773,12 @@
     "runtimeError": false
   },
   "test/e2e/next-font/with-font-declarations-file.test.ts": {
-    "passed": [],
-    "failed": [
+    "passed": [
       "next/font/google with-font-declarations-file preload correct files at /inter",
       "next/font/google with-font-declarations-file preload correct files at /local-font",
       "next/font/google with-font-declarations-file preload correct files at /roboto"
     ],
+    "failed": [],
     "pending": [],
     "flakey": [],
     "runtimeError": false