/
index.test.js
61 lines (52 loc) · 1.47 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
/* eslint-env jest */
import { join } from 'path'
import cheerio from 'cheerio'
import {
findPort,
launchApp,
killApp,
renderViaHTTP,
nextBuild,
nextStart,
} from 'next-test-utils'
const appDir = join(__dirname, '..')
let appPort
let app
const runTests = () => {
it('should merge _app pageProps and getServerSideProps props', async () => {
const html = await renderViaHTTP(appPort, '/gssp')
const $ = cheerio.load(html)
expect(JSON.parse($('p').text())).toEqual({ hi: 'hi', hello: 'world' })
})
it('should merge _app pageProps and getStaticProps props', async () => {
const html = await renderViaHTTP(appPort, '/gsp')
const $ = cheerio.load(html)
expect(JSON.parse($('p').text())).toEqual({ hi: 'hi', hello: 'world' })
})
}
describe('pageProps GSSP conflict', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
const { code } = await nextBuild(appDir)
if (code !== 0) throw new Error(`build failed with code ${code}`)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
})