-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(router): catch all routes should work now
- Loading branch information
1 parent
68b1f96
commit 15cde8e
Showing
12 changed files
with
168 additions
and
0 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
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,52 @@ | ||
import { AppCtx, Page, devFixture } from '../utils'; | ||
|
||
let ctx: AppCtx; | ||
let page: Page; | ||
|
||
jest.setTimeout(5 * 60 * 1000); | ||
|
||
describe('catch-all', () => { | ||
beforeAll(async () => { | ||
ctx = await devFixture('catch-all'); | ||
}); | ||
afterAll(async () => { | ||
await ctx.close(); | ||
}); | ||
afterEach(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test('should exact match home page', async () => { | ||
page = await ctx.browser.page(ctx.url('/home')); | ||
await page.waitForSelector('[id="home-page"]'); | ||
expect(await page.$text('[id="global-layout"]')).toBe('/layout.js'); | ||
expect(await page.$text('[id="home-page"]')).toBe('/home/page.js'); | ||
expect(await page.$text('[id="home-layout"]')).toBe('/home/layout.js'); | ||
}); | ||
|
||
test('should match catchAll', async () => { | ||
page = await ctx.browser.page(ctx.url('/other')); | ||
await page.waitForSelector('[id="catchAll-page"]'); | ||
expect(await page.$text('[id="global-layout"]')).toBe('/layout.js'); | ||
expect(await page.$text('[id="catchAll-page"]')).toBe('/$/page.js'); | ||
expect(await page.$text('[id="catchAll-layout"]')).toBe('/$/layout.js'); | ||
}); | ||
|
||
test('should match /:symbol/calc', async () => { | ||
page = await ctx.browser.page(ctx.url('/symbol/calc')); | ||
await page.waitForSelector('[id="calc-page"]'); | ||
expect(await page.$text('[id="global-layout"]')).toBe('/layout.js'); | ||
expect(await page.$text('[id="calc-page"]')).toBe('/$symbol/calc/page.js'); | ||
expect(await page.$text('[id="calc-layout"]')).toBe( | ||
'/$symbol/calc/layout.js' | ||
); | ||
}); | ||
|
||
test('/symbol/calc2 should match catchAll', async () => { | ||
page = await ctx.browser.page(ctx.url('/symbol/calc2')); | ||
await page.waitForSelector('[id="catchAll-page"]'); | ||
expect(await page.$text('[id="global-layout"]')).toBe('/layout.js'); | ||
expect(await page.$text('[id="catchAll-page"]')).toBe('/$/page.js'); | ||
expect(await page.$text('[id="catchAll-layout"]')).toBe('/$/layout.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,6 @@ | ||
{ | ||
"name": "fixture-catch-all", | ||
"dependencies": { | ||
"shuvi": "workspace:*" | ||
} | ||
} |
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 { | ||
ssr: true | ||
}; |
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,10 @@ | ||
import { RouterView } from '@shuvi/runtime'; | ||
|
||
const Layout = () => ( | ||
<div> | ||
<div id="catchAll-layout">/$/layout.js</div> | ||
<RouterView /> | ||
</div> | ||
); | ||
|
||
export default Layout; |
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 @@ | ||
export default function Index() { | ||
return ( | ||
<> | ||
<div id="catchAll-page">/$/page.js</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RouterView } from '@shuvi/runtime'; | ||
|
||
const Layout = () => ( | ||
<div> | ||
<div id="calc-layout">/$symbol/calc/layout.js</div> | ||
<RouterView /> | ||
</div> | ||
); | ||
|
||
export default Layout; |
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 @@ | ||
export default function Index() { | ||
return ( | ||
<> | ||
<div id="calc-page">/$symbol/calc/page.js</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RouterView } from '@shuvi/runtime'; | ||
|
||
const Layout = () => ( | ||
<div> | ||
<div id="home-layout">/home/layout.js</div> | ||
<RouterView /> | ||
</div> | ||
); | ||
|
||
export default Layout; |
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 @@ | ||
export default function Index() { | ||
return ( | ||
<> | ||
<div id="home-page">/home/page.js</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RouterView } from '@shuvi/runtime'; | ||
|
||
const GlobalLayout = () => ( | ||
<div> | ||
<div id="global-layout">/layout.js</div> | ||
<RouterView /> | ||
</div> | ||
); | ||
|
||
export default GlobalLayout; |