forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-page-runtime.test.ts
55 lines (48 loc) · 1.59 KB
/
parse-page-runtime.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
import { getPageRuntime } from 'next/dist/build/entries'
import type { PageRuntime } from 'next/dist/server/config-shared'
import { join } from 'path'
const fixtureDir = join(__dirname, 'fixtures')
function createNextConfig(runtime?: PageRuntime) {
return {
experimental: { reactRoot: true, runtime },
}
}
describe('parse page runtime config', () => {
it('should parse nodejs runtime correctly', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/nodejs.js'),
createNextConfig()
)
expect(runtime).toBe('nodejs')
})
it('should parse edge runtime correctly', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/edge.js'),
createNextConfig()
)
expect(runtime).toBe('edge')
})
it('should return undefined if no runtime is specified', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/static.js'),
createNextConfig()
)
expect(runtime).toBe(undefined)
})
})
describe('fallback to the global runtime configuration', () => {
it('should fallback when gSP is defined and exported', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/fallback-with-gsp.js'),
createNextConfig('edge')
)
expect(runtime).toBe('edge')
})
it('should fallback when gSP is re-exported from other module', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/fallback-re-export-gsp.js'),
createNextConfig('edge')
)
expect(runtime).toBe('edge')
})
})