Ensure non-error thrown in getStaticPaths shows correctly (#33753)

This commit is contained in:
JJ Kasper 2022-01-27 16:31:54 -06:00 committed by GitHub
parent 7ec49be7ac
commit 6aef15dc23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View file

@ -1028,7 +1028,7 @@ export default async function build(
)
}
} catch (err) {
if (isError(err) && err.message !== 'INVALID_DEFAULT_EXPORT')
if (!isError(err) || err.message !== 'INVALID_DEFAULT_EXPORT')
throw err
invalidPages.add(page)
}

View file

@ -1,5 +1,6 @@
/* eslint-env jest */
import fs from 'fs-extra'
import path from 'path'
import { nextBuild } from 'next-test-utils'
@ -15,4 +16,43 @@ describe('Invalid Page automatic static optimization', () => {
expect(stderr).toMatch(/pages\/invalid/)
expect(stderr).toMatch(/pages\/also-invalid/)
})
it('handles non-error correctly', async () => {
const testPage = path.join(appDir, 'pages/[slug].js')
await fs.rename(path.join(appDir, 'pages'), path.join(appDir, 'pages-bak'))
await fs.ensureDir(path.join(appDir, 'pages'))
await fs.writeFile(
testPage,
`
export default function Page() {
return <p>hello world</p>
}
export function getStaticPaths() {
throw 'invalid API token'
}
export function getStaticProps() {
return {
props: {
hello: 'world'
}
}
}
`
)
try {
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toMatch(/invalid API token/)
expect(stderr).not.toMatch(/without a React Component/)
} finally {
await fs.remove(path.join(appDir, 'pages'))
await fs.rename(
path.join(appDir, 'pages-bak'),
path.join(appDir, 'pages')
)
}
})
})