From 11a3a21bee5d4b58b254e60f4c080ee7349f40be Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 18 Feb 2025 10:09:53 +0100 Subject: [PATCH] Improve server actions sourcemap test (#76129) ## What? Improves the check for browser sourcemaps by reading all sourcemap files from the `.next/static` folder instead of trying to locate a specific value. The sensitive value that is being checked should not exist in any of the sourcemap files so it's safer to check them all. This also ensures that if for example the underlying bundling heuristics change the check will still fail. In this case it was failing on the path with Turbopack, instead of on the value. This ensures it checks the value. --------- Co-authored-by: Sebastian "Sebbie" Silbermann --- test/e2e/app-dir/actions/app-action.test.ts | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/test/e2e/app-dir/actions/app-action.test.ts b/test/e2e/app-dir/actions/app-action.test.ts index 4577286c917a7..9055cefa959e7 100644 --- a/test/e2e/app-dir/actions/app-action.test.ts +++ b/test/e2e/app-dir/actions/app-action.test.ts @@ -9,6 +9,7 @@ import { } from 'next-test-utils' import type { Page, Request, Response, Route } from 'playwright' import fs from 'fs-extra' +import nodeFs from 'fs' import { join } from 'path' const GENERIC_RSC_ERROR = @@ -919,19 +920,24 @@ describe('app-dir action handling', () => { if (isNextStart) { it('should not expose action content in sourcemaps', async () => { - const sourcemap = ( - await fs.readdir( - join(next.testDir, '.next', 'static', 'chunks', 'app', 'client') + // We check all sourcemaps in the `static` folder for sensitive information given that chunking + const sourcemaps = nodeFs + .readdirSync(join(next.testDir, '.next', 'static'), { + recursive: true, + encoding: 'utf8', + }) + .filter((f) => f.endsWith('.js.map')) + .map((f) => + nodeFs.readFileSync(join(next.testDir, '.next', 'static', f), { + encoding: 'utf8', + }) ) - ).find((f) => f.endsWith('.js.map')) - expect(sourcemap).toBeDefined() + expect(sourcemaps).not.toBeEmpty() - expect( - await next.readFile( - join('.next', 'static', 'chunks', 'app', 'client', sourcemap) - ) - ).not.toContain('this_is_sensitive_info') + for (const sourcemap of sourcemaps) { + expect(sourcemap).not.toContain('this_is_sensitive_info') + } }) }