From 35260bf676a7ea80cd0f75c400f8482e4bbba961 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Mon, 22 Jul 2024 22:46:20 +0200 Subject: [PATCH] Adjust assertions testing React implementation details --- test/e2e/app-dir/app-css/index.test.ts | 46 +++++++++++++++++++++----- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/test/e2e/app-dir/app-css/index.test.ts b/test/e2e/app-dir/app-css/index.test.ts index 74b9005dbe4e2..8ea56a4210b39 100644 --- a/test/e2e/app-dir/app-css/index.test.ts +++ b/test/e2e/app-dir/app-css/index.test.ts @@ -1,6 +1,8 @@ import { nextTestSetup } from 'e2e-utils' import { check } from 'next-test-utils' +const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true' + describe('app dir - css', () => { const { next, isNextDev, skipped } = nextTestSetup({ files: __dirname, @@ -476,15 +478,41 @@ describe('app dir - css', () => { } else { // Even if it's deduped by Float, it should still only be included once in the payload. - const matches = initialHtml.match(/\/_next\/static\/css\/.+?\.css/g) - const counts = new Map() - for (const match of matches) { - counts.set(match, (counts.get(match) || 0) + 1) - } - for (const count of counts.values()) { - // There are 3 matches, one for the rendered , one for float preload and one for the inside flight payload. - // And there is one match for the not found style - expect([1, 3]).toContain(count) + const matches = initialHtml + .match(/\/_next\/static\/css\/.+?\.css/g) + .sort() + + // Heavy on testing React implementation details. + // Assertions may change often but what needs to be checked on change is if styles are needlessly duplicated in Flight data + // There are 3 matches, one for the rendered (HTML), one for Float preload (Flight) and one for the inside Flight payload. + // And there is one match for the not found style + if (isPPREnabledByDefault) { + expect(matches).toEqual([ + // string split across chunks. + '/_next/static/css/app/css/css-dupl"])