2022-05-20 14:24:00 +02:00
|
|
|
import { getPageStaticInfo } from 'next/dist/build/analysis/get-page-static-info'
|
2024-01-02 15:20:05 +01:00
|
|
|
import { PAGE_TYPES } from 'next/dist/lib/page-types'
|
2022-03-02 18:41:41 +01:00
|
|
|
import { join } from 'path'
|
|
|
|
|
|
|
|
const fixtureDir = join(__dirname, 'fixtures')
|
|
|
|
|
2023-04-21 00:37:38 +02:00
|
|
|
function createNextConfig() {
|
|
|
|
return {}
|
2022-03-30 22:21:41 +02:00
|
|
|
}
|
|
|
|
|
2022-09-07 18:28:15 +02:00
|
|
|
describe('parse page static info', () => {
|
2022-03-02 18:41:41 +01:00
|
|
|
it('should parse nodejs runtime correctly', async () => {
|
2022-09-07 18:28:15 +02:00
|
|
|
const { runtime, ssr, ssg } = await getPageStaticInfo({
|
2022-05-20 14:24:00 +02:00
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/nodejs-ssr.js'),
|
|
|
|
nextConfig: createNextConfig(),
|
2024-01-02 15:20:05 +01:00
|
|
|
pageType: PAGE_TYPES.PAGES,
|
2022-05-20 14:24:00 +02:00
|
|
|
})
|
2022-03-02 18:41:41 +01:00
|
|
|
expect(runtime).toBe('nodejs')
|
2022-09-07 18:28:15 +02:00
|
|
|
expect(ssr).toBe(true)
|
|
|
|
expect(ssg).toBe(false)
|
2022-03-02 18:41:41 +01:00
|
|
|
})
|
|
|
|
|
2022-05-13 19:48:53 +02:00
|
|
|
it('should parse static runtime correctly', async () => {
|
2022-09-07 18:28:15 +02:00
|
|
|
const { runtime, ssr, ssg } = await getPageStaticInfo({
|
2022-05-20 14:24:00 +02:00
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/nodejs.js'),
|
|
|
|
nextConfig: createNextConfig(),
|
2024-01-02 15:20:05 +01:00
|
|
|
pageType: PAGE_TYPES.PAGES,
|
2022-05-20 14:24:00 +02:00
|
|
|
})
|
2022-05-13 19:48:53 +02:00
|
|
|
expect(runtime).toBe(undefined)
|
2022-09-07 18:28:15 +02:00
|
|
|
expect(ssr).toBe(false)
|
|
|
|
expect(ssg).toBe(false)
|
2022-05-13 19:48:53 +02:00
|
|
|
})
|
|
|
|
|
2022-03-02 18:41:41 +01:00
|
|
|
it('should parse edge runtime correctly', async () => {
|
2022-05-20 14:24:00 +02:00
|
|
|
const { runtime } = await getPageStaticInfo({
|
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/edge.js'),
|
|
|
|
nextConfig: createNextConfig(),
|
2024-01-02 15:20:05 +01:00
|
|
|
pageType: PAGE_TYPES.PAGES,
|
2022-05-20 14:24:00 +02:00
|
|
|
})
|
2022-06-27 03:02:24 +02:00
|
|
|
expect(runtime).toBe('experimental-edge')
|
2022-03-02 18:41:41 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return undefined if no runtime is specified', async () => {
|
2022-05-20 14:24:00 +02:00
|
|
|
const { runtime } = await getPageStaticInfo({
|
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/static.js'),
|
|
|
|
nextConfig: createNextConfig(),
|
2024-01-02 15:20:05 +01:00
|
|
|
pageType: PAGE_TYPES.PAGES,
|
2022-05-20 14:24:00 +02:00
|
|
|
})
|
2022-03-02 18:41:41 +01:00
|
|
|
expect(runtime).toBe(undefined)
|
|
|
|
})
|
2022-09-07 18:28:15 +02:00
|
|
|
|
|
|
|
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(),
|
2024-01-02 15:20:05 +01:00
|
|
|
pageType: PAGE_TYPES.PAGES,
|
2022-09-07 18:28:15 +02:00
|
|
|
})
|
|
|
|
expect(ssr).toBe(true)
|
|
|
|
expect(ssg).toBe(false)
|
|
|
|
})
|
2022-03-15 14:14:18 +01:00
|
|
|
})
|