-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update check for fallback pages during export (#33323)
This fixes our check for fallback pages during `next export` as we are currently erroring even when the erroneous pages are not included in the `exportPathMap`. This also adds additional tests to certify the expected behavior for the error. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have helpful link attached, see `contributing.md` Fixes: #29135
- Loading branch information
Showing
7 changed files
with
183 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
exportPathMap() { | ||
return { | ||
'/first': { page: '/[slug]' }, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { renderViaHTTP } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
describe('fallback export error', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'pages')), | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should have built', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
expect(html).toContain('index page') | ||
}) | ||
|
||
it('should not error with default exportPathMap', async () => { | ||
await next.stop() | ||
|
||
const result = await next.export() | ||
console.log(result.cliOutput) | ||
|
||
expect(result.exitCode).toBe(0) | ||
expect(result.cliOutput).not.toContain( | ||
'Found pages with `fallback` enabled' | ||
) | ||
}) | ||
|
||
it('should not error with valid exportPathMap', async () => { | ||
await next.stop() | ||
await next.patchFile( | ||
'next.config.js', | ||
` | ||
module.exports = { | ||
exportPathMap() { | ||
return { | ||
'/': { page: '/' }, | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
try { | ||
const result = await next.export() | ||
console.log(result.cliOutput) | ||
|
||
expect(result.exitCode).toBe(0) | ||
expect(result.cliOutput).not.toContain( | ||
'Found pages with `fallback` enabled' | ||
) | ||
} finally { | ||
await next.deleteFile('next.config.js') | ||
} | ||
}) | ||
|
||
it('should error with invalid exportPathMap', async () => { | ||
await next.stop() | ||
await next.patchFile( | ||
'next.config.js', | ||
` | ||
module.exports = { | ||
exportPathMap() { | ||
return { | ||
'/': { page: '/' }, | ||
'/second': { page: '/[...slug]' } | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
try { | ||
const result = await next.export() | ||
console.log(result.cliOutput) | ||
|
||
expect(result.exitCode).toBe(1) | ||
expect(result.cliOutput).toContain('Found pages with `fallback` enabled') | ||
} finally { | ||
await next.deleteFile('next.config.js') | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function getStaticProps() { | ||
return { | ||
props: { | ||
now: Date.now(), | ||
}, | ||
} | ||
} | ||
|
||
export function getStaticPaths() { | ||
return { | ||
paths: ['/first'], | ||
fallback: 'blocking', | ||
} | ||
} | ||
|
||
export default function Page() { | ||
return <p>catch-all page</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>index page</p> | ||
} |