Skip to content

Commit

Permalink
Ensure non-error thrown in getStaticPaths shows correctly (#33753)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 27, 2022
1 parent 7ec49be commit 6aef15d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Expand Up @@ -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)
}
Expand Down
@@ -1,5 +1,6 @@
/* eslint-env jest */

import fs from 'fs-extra'
import path from 'path'
import { nextBuild } from 'next-test-utils'

Expand All @@ -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')
)
}
})
})

0 comments on commit 6aef15d

Please sign in to comment.