From ce7c8b06b85910e891fba6ee4564ea736508f5fc Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 8 Sep 2024 14:45:41 +0200 Subject: [PATCH] Turbopack build: Fix middleware dead code elimination test (#69828) This test assumed a hardcoded file but with Turbopack it's a combination of multiple files. Changed it to use the manifest to look up the relevant files. --- .../edge-runtime-is-addressable/index.test.ts | 18 ++++++++++++------ test/turbopack-build-tests-manifest.json | 5 ++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/production/edge-runtime-is-addressable/index.test.ts b/test/production/edge-runtime-is-addressable/index.test.ts index 0a9e25bb8460a..b4bc924023cd2 100644 --- a/test/production/edge-runtime-is-addressable/index.test.ts +++ b/test/production/edge-runtime-is-addressable/index.test.ts @@ -1,7 +1,6 @@ import { createNext } from 'e2e-utils' import { NextInstance } from 'e2e-utils' import { fetchViaHTTP } from 'next-test-utils' -import fs from 'fs-extra' import path from 'path' const files = { @@ -55,13 +54,20 @@ describe('Edge Runtime is addressable', () => { }) test('removes the undefined branch with dead code elimination', async () => { - const compiledMiddlewareFile = await fs.readFile( - path.join(next.testDir, '.next/server/middleware.js'), - 'utf8' + const middlewareManifest = await next.readJSON( + '.next/server/middleware-manifest.json' ) - expect(compiledMiddlewareFile).toContain('EdgeRuntime is defined') - expect(compiledMiddlewareFile).not.toContain('EdgeRuntime is undefined') + const files = middlewareManifest.middleware['/'].files + + let allContentCombined = '' + for (const file of files) { + const content = await next.readFile(path.join('.next', file)) + allContentCombined += content + } + + expect(allContentCombined).toContain('EdgeRuntime is defined') + expect(allContentCombined).not.toContain('EdgeRuntime is undefined') }) }) diff --git a/test/turbopack-build-tests-manifest.json b/test/turbopack-build-tests-manifest.json index 1029bce22ce69..9c4f581224093 100644 --- a/test/turbopack-build-tests-manifest.json +++ b/test/turbopack-build-tests-manifest.json @@ -16044,11 +16044,10 @@ "test/production/edge-runtime-is-addressable/index.test.ts": { "passed": [ "Edge Runtime can be set to the production provider EdgeRuntime evaluates to a string", - "Edge Runtime is addressable EdgeRuntime evaluates to a string" - ], - "failed": [ + "Edge Runtime is addressable EdgeRuntime evaluates to a string", "Edge Runtime is addressable removes the undefined branch with dead code elimination" ], + "failed": [], "pending": [], "flakey": [], "runtimeError": false