Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Mar 1, 2022
1 parent 84311c4 commit 94fc4ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export async function getPageRuntime(
const valueNode = declaration?.declarations?.[0]
if (type === 'ExportDeclaration' && valueNode?.id?.value === 'config') {
const props = valueNode.init.properties
console.log(props)
const runtimeKeyValue = props.find(
(prop: any) => prop.key.value === 'runtime'
)
Expand Down
8 changes: 8 additions & 0 deletions test/unit/fixtures/page-runtime/edge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Edge() {
return 'edge'
}

export const config = {
runtime: 'edge',
amp: false,
}
8 changes: 8 additions & 0 deletions test/unit/fixtures/page-runtime/nodejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Nodejs() {
return 'nodejs'
}

export const config = {
amp: false,
runtime: 'nodejs',
}
20 changes: 20 additions & 0 deletions test/unit/parse-page-runtime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getPageRuntime } from 'next/dist/build/entries'
import { join } from 'path'

const fixtureDir = join(__dirname, 'fixtures')

describe('parse page runtime config', () => {
it('should parse nodejs runtime correctly', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/nodejs.js')
)
expect(runtime).toBe('nodejs')
})

it('should parse edge runtime correctly', async () => {
const runtime = await getPageRuntime(
join(fixtureDir, 'page-runtime/edge.js')
)
expect(runtime).toBe('edge')
})
})

0 comments on commit 94fc4ca

Please sign in to comment.