Unverified Commit 8482890a authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

test: make app-document-import-order more robust (#97682)

- The `brower.eval(callback)` version was a bit weird, use
beforePageLoad as we do everywhere else
- Properly parse the URL and match against the pathname, to not break
with `?dpl`
parent ba9f073c
...@@ -16,32 +16,37 @@ describe('Root components import order', () => { ...@@ -16,32 +16,37 @@ describe('Root components import order', () => {
expect($(sideEffectCall).text()).toEqual(expectSideEffectsOrder[index]) expect($(sideEffectCall).text()).toEqual(expectSideEffectsOrder[index])
}) })
}) })
// Only asserted for production builds: in development each entry is chunked from its own // Only asserted for production builds: in development each entry is chunked from its own
// per-page module graph, which can still merge a shared module into per-entry units. // per-page module graph, which can still merge a shared module into per-entry units.
;(isNextDev ? it.skip : it)( ;(isNextDev ? it.skip : it)(
'loads modules shared by _app and the page only once', 'loads modules shared by _app and the page only once',
async () => { async () => {
const browser = await next.browser('/', { waitHydration: false }) const requests: Set<string> = new Set()
const markerCount = await browser.eval(async () => { await next.browser('/', {
const chunkUrls = [ beforePageLoad(page) {
...new Set( page.on('request', (request) => {
performance const url = new URL(request.url(), next.url)
.getEntriesByType('resource') if (
.map((entry) => entry.name) url.pathname.startsWith('/_next/static/') &&
.filter( url.pathname.endsWith('.js')
(url) => url.includes('/_next/static/') && url.endsWith('.js') ) {
) requests.add(url.href)
), }
] })
const chunks = await Promise.all( },
chunkUrls.map((url) => fetch(url).then((response) => response.text()))
)
return chunks.filter((chunk) =>
chunk.includes('APP_PAGE_SHARED_MODULE_MARKER')
).length
}) })
expect(markerCount).toBe(1) const chunks = await Promise.all(
[...requests].map((url) =>
fetch(url).then((response) => response.text())
)
)
const matchingChunks = chunks.filter((chunk) =>
chunk.includes('APP_PAGE_SHARED_MODULE_MARKER')
)
expect(matchingChunks.length).toBe(1)
} }
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment