-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: downgrade fatal crash error for
<Link>
component (#596)
- Loading branch information
1 parent
2cbfd70
commit 1205fc5
Showing
5 changed files
with
134 additions
and
3 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,17 @@ | ||
import * as React from 'react'; | ||
import { Link } from '@shuvi/runtime'; | ||
|
||
// @note test purpose to trigger runtime error | ||
const TO = undefined as unknown as string; | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
Demo runtime error - Link component missing required `prop.to` | ||
<br /> | ||
<button id="button-link-without-to"> | ||
<Link to={TO}>Click to trigger a fatal error at runtime</Link> | ||
</button> | ||
</div> | ||
); | ||
} |
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,53 @@ | ||
import { AppCtx, Page, devFixture, serveFixture } from '../utils'; | ||
|
||
let ctx: AppCtx; | ||
let page: Page; | ||
|
||
jest.setTimeout(5 * 60 * 1000); | ||
|
||
describe('link prop.to - [dev mode]', () => { | ||
beforeAll(async () => { | ||
ctx = await devFixture('basic', { ssr: true }); | ||
}); | ||
afterAll(async () => { | ||
await ctx.close(); | ||
}); | ||
afterEach(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test(`immediately show the "Internal Application Error" page`, async () => { | ||
page = await ctx.browser.page(ctx.url('/fatal-link-demo')); | ||
expect(await page.$text('#__APP')).toContain( | ||
`500` // 500 error | ||
); | ||
expect(await page.$text('#__APP')).toContain( | ||
`Cannot read properties of undefined (reading 'pathname')` | ||
); | ||
}); | ||
}); | ||
|
||
describe('link prop.to - [prod mode]', () => { | ||
beforeAll(async () => { | ||
ctx = await serveFixture('basic', { ssr: true }); | ||
}); | ||
afterAll(async () => { | ||
await ctx.close(); | ||
}); | ||
afterEach(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test(`downgrade fatal crashes`, async () => { | ||
page = await ctx.browser.page(ctx.url('/fatal-link-demo')); | ||
|
||
// 1. without causing an immediate page crash. | ||
expect(await page.$text('#button-link-without-to')).toContain( | ||
'Click to trigger a fatal error at runtime' | ||
); | ||
|
||
// 2. Only after user clicks <Link>, page re-render and display the "Internal Application Error" page. | ||
await page.click('#button-link-without-to'); | ||
expect(await page.$text('#__APP')).toContain('Internal Application Error'); | ||
}); | ||
}); |
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,17 @@ | ||
import * as React from 'react'; | ||
import { Link } from '@shuvi/runtime'; | ||
|
||
// @note test purpose to trigger runtime error | ||
const TO = undefined; | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
Demo runtime error - Link component missing required `prop.to` | ||
<br /> | ||
<button id="button-link-without-to"> | ||
<Link to={TO}>Click to trigger a fatal error at runtime</Link> | ||
</button> | ||
</div> | ||
); | ||
} |