-
Notifications
You must be signed in to change notification settings - Fork 26k
/
parse-page-static-info.test.ts
79 lines (70 loc) · 2.61 KB
/
parse-page-static-info.test.ts
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
69
70
71
72
73
74
75
76
77
78
79
import { getPageStaticInfo } from 'next/dist/build/analysis/get-page-static-info'
import { join } from 'path'
const fixtureDir = join(__dirname, 'fixtures')
function createNextConfig(runtime?: 'experimental-edge' | 'nodejs') {
return {
experimental: { runtime },
}
}
describe('parse page static info', () => {
it('should parse nodejs runtime correctly', async () => {
const { runtime, ssr, ssg } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/nodejs-ssr.js'),
nextConfig: createNextConfig(),
})
expect(runtime).toBe('nodejs')
expect(ssr).toBe(true)
expect(ssg).toBe(false)
})
it('should parse static runtime correctly', async () => {
const { runtime, ssr, ssg } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/nodejs.js'),
nextConfig: createNextConfig(),
})
expect(runtime).toBe(undefined)
expect(ssr).toBe(false)
expect(ssg).toBe(false)
})
it('should parse edge runtime correctly', async () => {
const { runtime } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/edge.js'),
nextConfig: createNextConfig(),
})
expect(runtime).toBe('experimental-edge')
})
it('should return undefined if no runtime is specified', async () => {
const { runtime } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/static.js'),
nextConfig: createNextConfig(),
})
expect(runtime).toBe(undefined)
})
it('should parse ssr info with variable exported gSSP correctly', async () => {
const { ssr, ssg } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/ssr-variable-gssp.js'),
nextConfig: createNextConfig(),
})
expect(ssr).toBe(true)
expect(ssg).toBe(false)
})
})
describe('fallback to the global runtime configuration', () => {
it('should fallback when gSP is defined and exported', async () => {
const { runtime, ssr, ssg } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/fallback-with-gsp.js'),
nextConfig: createNextConfig('experimental-edge'),
})
expect(runtime).toBe('experimental-edge')
expect(ssr).toBe(false)
expect(ssg).toBe(true)
})
it('should fallback when gSP is re-exported from other module', async () => {
const { runtime, ssr, ssg } = await getPageStaticInfo({
pageFilePath: join(fixtureDir, 'page-runtime/fallback-re-export-gsp.js'),
nextConfig: createNextConfig('experimental-edge'),
})
expect(runtime).toBe('experimental-edge')
expect(ssr).toBe(false)
expect(ssg).toBe(true)
})
})