Commit 89b22d29 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Fix missing getStaticProps error in serverless mode (#9532)

* Make sure to show missing getStaticProps error in serverless mode

* Update test
parent 45832e44
......@@ -99,10 +99,11 @@ const nextServerlessLoader: loader.Loader = function() {
const Component = ComponentInfo.default
export default Component
export const unstable_getStaticProps = ComponentInfo['unstable_getStaticProp' + 's']
${
isDynamicRoute(page)
? "export const unstable_getStaticPaths = ComponentInfo['unstable_getStaticPath' + 's']"
: ''
: 'export const unstable_getStaticPaths = undefined'
}
export const config = ComponentInfo['confi' + 'g'] || {}
export const _app = App
......@@ -112,6 +113,7 @@ const nextServerlessLoader: loader.Loader = function() {
Document,
buildManifest,
unstable_getStaticProps,
unstable_getStaticPaths,
reactLoadableManifest,
canonicalBase: "${canonicalBase}",
buildId: "${buildId}",
......
export async function unstable_getStaticPaths() {
return ['/hello', '/world']
}
export default () => <p>something is missing 🤔</p>
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import fs from 'fs-extra'
import {
renderViaHTTP,
nextBuild,
launchApp,
findPort,
killApp,
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = join(__dirname, '../')
const nextConfig = join(appDir, 'next.config.js')
const errorRegex = /unstable_getStaticPaths was added without a unstable_getStaticProps in/
describe('Catches Missing getStaticProps', () => {
afterAll(() => fs.remove(nextConfig))
it('should catch it in dev mode', async () => {
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
const html = await renderViaHTTP(appPort, '/hello')
await killApp(app)
expect(html).toMatch(errorRegex)
})
it('should catch it in server build mode', async () => {
await fs.remove(nextConfig)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(stderr).toMatch(errorRegex)
})
it('should catch it in serverless mode', async () => {
await fs.writeFile(
nextConfig,
`module.exports = { target: 'serverless' }`,
'utf8'
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(stderr).toMatch(errorRegex)
})
})
......@@ -256,29 +256,6 @@ const runTests = (dev = false) => {
await fs.writeFile(indexPage, origContent)
}
})
it('should show error when getStaticPaths is used without getStaticProps', async () => {
const pagePath = join(appDir, 'pages/no-getStaticProps.js')
await fs.writeFile(
pagePath,
`
export async function unstable_getStaticPaths() {
return []
}
export default () => 'hi'
`,
'utf8'
)
const html = await renderViaHTTP(appPort, '/no-getStaticProps')
await fs.remove(pagePath)
await waitFor(500)
expect(html).toMatch(
/unstable_getStaticPaths was added without a unstable_getStaticProps in/
)
})
} else {
it('should should use correct caching headers for a no-revalidate page', async () => {
const initialRes = await fetchViaHTTP(appPort, '/something')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment