Skip to content

Commit

Permalink
Adjust assertions testing React implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 22, 2024
1 parent e31b973 commit 35260bf
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions test/e2e/app-dir/app-css/index.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 <link>, one for float preload and one for the <link> 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 <link> (HTML), one for Float preload (Flight) and one for the <link> 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"])</script><script>self.__next_f.push([1,"icate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/not-found.css',
])
} else {
expect(matches).toEqual([
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/css-duplicate-2/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/css/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/layout.css',
'/_next/static/css/app/not-found.css',
])
}
}
})
Expand Down

0 comments on commit 35260bf

Please sign in to comment.