2022-05-20 14:24:00 +02:00
|
|
|
import { getPageStaticInfo } from 'next/dist/build/analysis/get-page-static-info'
|
2022-03-02 18:41:41 +01:00
|
|
|
import { join } from 'path'
|
|
|
|
|
|
|
|
const fixtureDir = join(__dirname, 'fixtures')
|
|
|
|
|
2022-05-13 19:48:53 +02:00
|
|
|
function createNextConfig(runtime?: 'edge' | 'nodejs') {
|
2022-03-30 22:21:41 +02:00
|
|
|
return {
|
|
|
|
experimental: { reactRoot: true, runtime },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:41:41 +01:00
|
|
|
describe('parse page runtime config', () => {
|
|
|
|
it('should parse nodejs runtime correctly', async () => {
|
2022-05-20 14:24:00 +02:00
|
|
|
const { runtime } = await getPageStaticInfo({
|
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/nodejs-ssr.js'),
|
|
|
|
nextConfig: createNextConfig(),
|
|
|
|
})
|
2022-03-02 18:41:41 +01:00
|
|
|
expect(runtime).toBe('nodejs')
|
|
|
|
})
|
|
|
|
|
2022-05-13 19:48:53 +02:00
|
|
|
it('should parse static runtime correctly', async () => {
|
2022-05-20 14:24:00 +02:00
|
|
|
const { runtime } = await getPageStaticInfo({
|
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/nodejs.js'),
|
|
|
|
nextConfig: createNextConfig(),
|
|
|
|
})
|
2022-05-13 19:48:53 +02:00
|
|
|
expect(runtime).toBe(undefined)
|
|
|
|
})
|
|
|
|
|
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(),
|
|
|
|
})
|
2022-03-02 18:41:41 +01:00
|
|
|
expect(runtime).toBe('edge')
|
|
|
|
})
|
|
|
|
|
|
|
|
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(),
|
|
|
|
})
|
2022-03-02 18:41:41 +01:00
|
|
|
expect(runtime).toBe(undefined)
|
|
|
|
})
|
2022-03-15 14:14:18 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('fallback to the global runtime configuration', () => {
|
|
|
|
it('should fallback when gSP is defined and exported', async () => {
|
2022-05-20 14:24:00 +02:00
|
|
|
const { runtime } = await getPageStaticInfo({
|
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/fallback-with-gsp.js'),
|
|
|
|
nextConfig: createNextConfig('edge'),
|
|
|
|
})
|
2022-03-15 14:14:18 +01:00
|
|
|
expect(runtime).toBe('edge')
|
|
|
|
})
|
2022-03-08 21:55:14 +01:00
|
|
|
|
2022-03-15 14:14:18 +01:00
|
|
|
it('should fallback when gSP is re-exported from other module', async () => {
|
2022-05-20 14:24:00 +02:00
|
|
|
const { runtime } = await getPageStaticInfo({
|
|
|
|
pageFilePath: join(fixtureDir, 'page-runtime/fallback-re-export-gsp.js'),
|
|
|
|
nextConfig: createNextConfig('edge'),
|
|
|
|
})
|
2022-03-08 21:55:14 +01:00
|
|
|
expect(runtime).toBe('edge')
|
|
|
|
})
|
2022-03-02 18:41:41 +01:00
|
|
|
})
|