/
index.test.js
68 lines (61 loc) · 1.75 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import webdriver from 'next-webdriver'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
waitFor,
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..')
let output = ''
let appPort
let app
const handleOutput = msg => {
output += msg
}
describe('Empty Project', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: handleOutput,
onStderr: handleOutput,
})
})
afterAll(() => killApp(app))
it('It should show empty object warning on SSR', async () => {
output = ''
await renderViaHTTP(appPort, '/')
await waitFor(100)
expect(output).toMatch(/returned an empty object from `getInitialProps`/)
})
it('It should not show empty object warning for page without `getInitialProps`', async () => {
output = ''
await renderViaHTTP(appPort, '/static')
await waitFor(100)
expect(output).not.toMatch(
/returned an empty object from `getInitialProps`/
)
})
it('should show empty object warning during client transition', async () => {
const browser = await webdriver(appPort, '/static')
await browser.eval(`(function() {
window.gotWarn = false
const origWarn = console.warn
window.console.warn = function () {
if (arguments[0].match(/returned an empty object from \`getInitialProps\`/)) {
window.gotWarn = true
}
origWarn.apply(this, arguments)
}
window.next.router.replace('/another')
})()`)
await waitFor(1000)
const gotWarn = await browser.eval(`window.gotWarn`)
expect(gotWarn).toBe(true)
await browser.close()
})
})