Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Mar 30, 2022
1 parent d380c06 commit 8de481d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/unit/parse-page-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ import { join } from 'path'

const fixtureDir = join(__dirname, 'fixtures')

function createNextConfig(runtime?: string) {
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')
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')
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')
join(fixtureDir, 'page-runtime/static.js'),
createNextConfig()
)
expect(runtime).toBe(undefined)
})
Expand All @@ -30,15 +39,15 @@ 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'),
'edge'
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'),
'edge'
createNextConfig('edge')
)
expect(runtime).toBe('edge')
})
Expand Down

0 comments on commit 8de481d

Please sign in to comment.