/
index.test.js
57 lines (49 loc) · 1.35 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
/* eslint-env jest */
import { join } from 'path'
import {
renderViaHTTP,
fetchViaHTTP,
findPort,
launchApp,
killApp,
} from 'next-test-utils'
// test suites
import rendering from './rendering'
import client from './client'
import csp from './csp'
const context = {
output: '',
}
const collectOutput = (message) => {
context.output += message
}
describe('Document and App', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(join(__dirname, '../'), context.appPort, {
onStdout: collectOutput,
onStderr: collectOutput,
nodeArgs: [
'-r',
join(__dirname, '../../../lib/react-17-require-hook.js'),
],
})
// pre-build all pages at the start
await Promise.all([renderViaHTTP(context.appPort, '/')])
})
afterAll(() => killApp(context.server))
it('should not have any missing key warnings', async () => {
await renderViaHTTP(context.appPort, '/')
expect(context.output).not.toMatch(
/Each child in a list should have a unique "key" prop/
)
})
rendering(
context,
'Rendering via HTTP',
(p, q) => renderViaHTTP(context.appPort, p, q),
(p, q) => fetchViaHTTP(context.appPort, p, q)
)
client(context, (p, q) => renderViaHTTP(context.appPort, p, q))
csp(context, (p, q) => renderViaHTTP(context.appPort, p, q))
})