Skip to content

Commit 53e9983

Browse files
ijjkTimer
authored andcommitted
Add hydration callback for testing (vercel#10195)
* Add hydration callback for testing * Update size-limit test
1 parent fa65442 commit 53e9983

File tree

33 files changed

+217
-208
lines changed

33 files changed

+217
-208
lines changed

packages/next/client/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ class Container extends React.Component {
114114
}
115115
)
116116
}
117+
118+
if (process.env.__NEXT_TEST_MODE) {
119+
window.__NEXT_HYDRATED = true
120+
121+
if (window.__NEXT_HYDRATED_CB) {
122+
window.__NEXT_HYDRATED_CB()
123+
}
124+
}
117125
}
118126

119127
componentDidUpdate() {

test/integration/auto-export/test/index.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
findPort,
99
killApp,
1010
launchApp,
11-
waitFor,
1211
} from 'next-test-utils'
1312

1413
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
@@ -42,14 +41,12 @@ const runTests = () => {
4241

4342
it('should update asPath after mount', async () => {
4443
const browser = await webdriver(appPort, '/zeit/cmnt-2')
45-
await waitFor(500)
4644
const html = await browser.eval(`document.documentElement.innerHTML`)
4745
expect(html).toMatch(/\/zeit\/cmnt-2/)
4846
})
4947

5048
it('should not replace URL with page name while asPath is delayed', async () => {
5149
const browser = await webdriver(appPort, '/zeit/cmnt-1')
52-
await waitFor(500)
5350
const val = await browser.eval(`!!window.pathnames.find(function(p) {
5451
return p !== '/zeit/cmnt-1'
5552
})`)
@@ -84,7 +81,6 @@ describe('Auto Export', () => {
8481

8582
it('should not show hydration warning from mismatching asPath', async () => {
8683
const browser = await webdriver(appPort, '/zeit/cmnt-1')
87-
await waitFor(500)
8884

8985
const numCaught = await browser.eval(`window.caughtWarns.length`)
9086
expect(numCaught).toBe(0)

test/integration/chunking/test/index.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
import { join } from 'path'
44
import express from 'express'
55
import http from 'http'
6-
import {
7-
nextBuild,
8-
waitFor,
9-
nextServer,
10-
promiseCall,
11-
stopApp,
12-
} from 'next-test-utils'
6+
import { nextBuild, nextServer, promiseCall, stopApp } from 'next-test-utils'
137
import { readdir, readFile, unlink, access } from 'fs-extra'
148
import cheerio from 'cheerio'
159
import webdriver from 'next-webdriver'
@@ -134,7 +128,6 @@ describe('Chunking', () => {
134128

135129
it('should hydrate with granularChunks config', async () => {
136130
const browser = await webdriver(appPort, '/page2')
137-
await waitFor(1000)
138131
const text = await browser.elementByCss('#padded-str').text()
139132

140133
expect(text).toBe('__rad__')
@@ -144,7 +137,6 @@ describe('Chunking', () => {
144137

145138
it('should load chunks when navigating', async () => {
146139
const browser = await webdriver(appPort, '/page3')
147-
await waitFor(1000)
148140
const text = await browser
149141
.elementByCss('#page2-link')
150142
.click()

test/integration/config/test/client.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export default (context, render) => {
88
describe('Configuration', () => {
99
it('should have config available on the client', async () => {
1010
const browser = await webdriver(context.appPort, '/next-config')
11-
// Wait for client side to load
12-
await waitFor(10000)
1311

1412
const serverText = await browser.elementByCss('#server-only').text()
1513
const serverClientText = await browser

test/integration/conflicting-public-file-page/test/index.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
findPort,
88
killApp,
99
renderViaHTTP,
10-
waitFor,
1110
} from 'next-test-utils'
1211

1312
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
@@ -25,7 +24,6 @@ describe('Errors on conflict between public file and page file', () => {
2524
/A conflicting public file and page file was found for path/
2625
)
2726
}
28-
await waitFor(1000)
2927
await killApp(app)
3028
})
3129

test/integration/css-client-nav/test/index.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { remove } from 'fs-extra'
55
import {
66
nextBuild,
77
nextStart,
8-
waitFor,
98
findPort,
109
killApp,
1110
renderViaHTTP,
@@ -80,9 +79,6 @@ describe('CSS Module client-side navigation in Production', () => {
8079
let browser
8180
try {
8281
browser = await webdriver(appPort, '/blue')
83-
84-
await waitFor(2000) // Ensure hydration
85-
8682
await browser.eval(`window.__did_not_ssr = 'make sure this is set'`)
8783

8884
const redColor = await browser.eval(

test/integration/css-modules/test/index.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ xdescribe('Can hot reload CSS Module without losing state', () => {
178178
// FIXME: this is broken
179179
it('should update CSS color without remounting <input>', async () => {
180180
const browser = await webdriver(appPort, '/')
181-
await waitFor(2000) // ensure application hydrates
182181

183182
const desiredText = 'hello world'
184183
await browser.elementById('text-input').type(desiredText)

test/integration/css/test/index.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ describe('CSS Support', () => {
304304
let browser
305305
try {
306306
browser = await webdriver(appPort, '/page1')
307-
await waitFor(2000) // ensure application hydrates
308307

309308
const desiredText = 'hello world'
310309
await browser.elementById('text-input').type(desiredText)
@@ -703,7 +702,6 @@ describe('CSS Support', () => {
703702

704703
it('should have the correct color (css ordering)', async () => {
705704
const browser = await webdriver(appPort, '/')
706-
await waitFor(2000) // ensure application hydrates
707705

708706
const currentColor = await browser.eval(
709707
`window.getComputedStyle(document.querySelector('.my-text')).color`
@@ -729,7 +727,6 @@ describe('CSS Support', () => {
729727

730728
it('should have the correct color (css ordering)', async () => {
731729
const browser = await webdriver(appPort, '/')
732-
await waitFor(2000) // ensure application hydrates
733730

734731
const currentColor = await browser.eval(
735732
`window.getComputedStyle(document.querySelector('.my-text')).color`

test/integration/duplicate-pages/test/index.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
launchApp,
99
renderViaHTTP,
1010
killApp,
11-
waitFor,
1211
} from 'next-test-utils'
1312

1413
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
@@ -34,7 +33,6 @@ describe('Handles Duplicate Pages', () => {
3433
onStderr: handleOutput,
3534
})
3635
await renderViaHTTP(appPort, '/hello')
37-
await waitFor(3000)
3836
await killApp(app)
3937
expect(output).toMatch(/Duplicate page detected/)
4038
})

test/integration/dynamic-routing/test/index.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ function runTests(dev) {
304304
expect(html).toMatch(/onmpost:.*pending/)
305305

306306
const browser = await webdriver(appPort, '/on-mount/post-1')
307-
await waitFor(1000)
308307
const text = await browser.eval(`document.body.innerHTML`)
309308
expect(text).toMatch(/onmpost:.*post-1/)
310309
})
@@ -316,14 +315,12 @@ function runTests(dev) {
316315

317316
it('should update with a hash in the URL', async () => {
318317
const browser = await webdriver(appPort, '/on-mount/post-1#abc')
319-
await waitFor(1000)
320318
const text = await browser.eval(`document.body.innerHTML`)
321319
expect(text).toMatch(/onmpost:.*post-1/)
322320
})
323321

324322
it('should scroll to a hash on mount', async () => {
325323
const browser = await webdriver(appPort, '/on-mount/post-1#item-400')
326-
await waitFor(1000)
327324

328325
const text = await browser.eval(`document.body.innerHTML`)
329326
expect(text).toMatch(/onmpost:.*post-1/)
@@ -334,7 +331,6 @@ function runTests(dev) {
334331

335332
it('should scroll to a hash on client-side navigation', async () => {
336333
const browser = await webdriver(appPort, '/')
337-
await waitFor(1000)
338334
await browser.elementByCss('#view-dynamic-with-hash').click()
339335
await browser.waitForElementByCss('p')
340336

0 commit comments

Comments
 (0)