11/* eslint-env jest */
22
3+ import fs from 'fs-extra'
34import path from 'path'
45import { nextBuild } from 'next-test-utils'
56
@@ -15,4 +16,43 @@ describe('Invalid Page automatic static optimization', () => {
1516 expect ( stderr ) . toMatch ( / p a g e s \/ i n v a l i d / )
1617 expect ( stderr ) . toMatch ( / p a g e s \/ a l s o - i n v a l i d / )
1718 } )
19+
20+ it ( 'handles non-error correctly' , async ( ) => {
21+ const testPage = path . join ( appDir , 'pages/[slug].js' )
22+ await fs . rename ( path . join ( appDir , 'pages' ) , path . join ( appDir , 'pages-bak' ) )
23+
24+ await fs . ensureDir ( path . join ( appDir , 'pages' ) )
25+ await fs . writeFile (
26+ testPage ,
27+ `
28+ export default function Page() {
29+ return <p>hello world</p>
30+ }
31+
32+ export function getStaticPaths() {
33+ throw 'invalid API token'
34+ }
35+
36+ export function getStaticProps() {
37+ return {
38+ props: {
39+ hello: 'world'
40+ }
41+ }
42+ }
43+ `
44+ )
45+
46+ try {
47+ const { stderr } = await nextBuild ( appDir , [ ] , { stderr : true } )
48+ expect ( stderr ) . toMatch ( / i n v a l i d A P I t o k e n / )
49+ expect ( stderr ) . not . toMatch ( / w i t h o u t a R e a c t C o m p o n e n t / )
50+ } finally {
51+ await fs . remove ( path . join ( appDir , 'pages' ) )
52+ await fs . rename (
53+ path . join ( appDir , 'pages-bak' ) ,
54+ path . join ( appDir , 'pages' )
55+ )
56+ }
57+ } )
1858} )
0 commit comments