Skip to content

Commit 74e1996

Browse files
committed
test
1 parent 244f047 commit 74e1996

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

.github/workflows/build_and_test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,12 @@ jobs:
910910
export IS_WEBPACK_TEST=1
911911
912912
BROWSER_NAME=firefox node run-tests.js \
913-
test/production/pages-dir/production/test/index.test.ts
913+
test/production/pages-dir/production/test/index.test.ts \
914+
test/production/chunk-load-failure/chunk-load-failure.test.ts
914915
915916
NEXT_TEST_MODE=start BROWSER_NAME=safari node run-tests.js \
916917
test/production/pages-dir/production/test/index.test.ts \
918+
test/production/chunk-load-failure/chunk-load-failure.test.ts \
917919
test/e2e/basepath/basepath.test.ts \
918920
test/e2e/basepath/error-pages.test.ts
919921

test/production/chunk-load-failure/chunk-load-failure.test.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,50 +58,49 @@ describe('chunk-load-failure', () => {
5858
}
5959
})
6060

61-
it.each(['chrome', 'firefox'])(
62-
'should report aborted chunks when navigating away with %s',
63-
async (browserName) => {
64-
let nextDynamicChunk = await getNextDynamicChunk()
61+
it('should report aborted chunks when navigating away', async () => {
62+
let nextDynamicChunk = await getNextDynamicChunk()
6563

66-
let resolve
67-
let oldBrowserName = process.env.BROWSER_NAME
68-
process.env.BROWSER_NAME = browserName
69-
try {
70-
const browser = await next.browser('/dynamic', {
71-
beforePageLoad(page) {
72-
page.route('**/' + nextDynamicChunk, async (route) => {
73-
await new Promise((r) => {
74-
resolve = r
75-
})
64+
let resolve
65+
try {
66+
const browser = await next.browser('/dynamic', {
67+
beforePageLoad(page) {
68+
page.route('**/' + nextDynamicChunk, async (route) => {
69+
// deterministically ensure that the async chunk is still loading during the navigation
70+
await new Promise((r) => {
71+
resolve = r
7672
})
77-
},
78-
})
73+
})
74+
page.on('pageerror', (error: Error) => {
75+
console.log('pageerror', error)
76+
})
77+
},
78+
})
79+
80+
await browser.get(next.url + '/other')
7981

80-
await browser.get(next.url + '/other')
82+
let body = await browser.elementByCss('body')
83+
expect(await body.text()).toMatch('this is other')
8184

82-
let body = await browser.elementByCss('body')
83-
expect(await body.text()).toMatch('this is other')
85+
const browserLogs = (await browser.log()).filter(
86+
(m) => m.source === 'warning' || m.source === 'error'
87+
)
8488

85-
const browserLogs = (await browser.log()).filter(
86-
(m) => m.source === 'warning' || m.source === 'error'
89+
if (process.env.BROWSER_NAME === 'firefox') {
90+
expect(browserLogs).toContainEqual(
91+
expect.objectContaining({
92+
message: expect.stringContaining(
93+
'Loading failed for the <script> with source'
94+
),
95+
})
8796
)
88-
if (browserName === 'firefox') {
89-
expect(browserLogs).toContainEqual(
90-
expect.objectContaining({
91-
message: expect.stringContaining(
92-
'Loading failed for the <script> with source'
93-
),
94-
})
95-
)
96-
} else {
97-
// Chrome doesn't show any errors or warnings here
98-
expect(browserLogs).toBeEmpty()
99-
}
100-
} finally {
101-
process.env.BROWSER_NAME = oldBrowserName
102-
// prevent hanging
103-
resolve?.()
97+
} else {
98+
// Chrome and Safari doesn't show any errors or warnings here
99+
expect(browserLogs).toBeEmpty()
104100
}
101+
} finally {
102+
// prevent hanging
103+
resolve?.()
105104
}
106-
)
105+
})
107106
})

0 commit comments

Comments
 (0)