From 956de3bfa2ef70d28361c53126c87198a677a93e Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 28 Feb 2023 17:17:46 +0800 Subject: [PATCH] test: test for dynamic routes --- __tests__/e2e/.vitepress/config.ts | 13 +++++++++++++ __tests__/e2e/__snapshots__/home.test.ts.snap | 2 +- __tests__/e2e/dynamic-routes/[id].md | 8 ++++++++ __tests__/e2e/dynamic-routes/[id].paths.ts | 8 ++++++++ __tests__/e2e/dynamic-routes/dynamic-routes.test.ts | 11 +++++++++++ __tests__/e2e/multi-sidebar/index.test.ts | 3 ++- .../e2e/static-data/__snapshots__/data.test.ts.snap | 2 +- 7 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 __tests__/e2e/dynamic-routes/[id].md create mode 100644 __tests__/e2e/dynamic-routes/[id].paths.ts create mode 100644 __tests__/e2e/dynamic-routes/dynamic-routes.test.ts diff --git a/__tests__/e2e/.vitepress/config.ts b/__tests__/e2e/.vitepress/config.ts index d0b971fc..a31d3517 100644 --- a/__tests__/e2e/.vitepress/config.ts +++ b/__tests__/e2e/.vitepress/config.ts @@ -38,6 +38,19 @@ const sidebar: DefaultTheme.Config['sidebar'] = { link: '/multi-sidebar/' } ] + }, + { + text: 'Dynamic Routes', + items: [ + { + text: 'Foo', + link: '/dynamic-routes/foo' + }, + { + text: 'Bar', + link: '/dynamic-routes/bar' + } + ] } ], '/multi-sidebar/': [ diff --git a/__tests__/e2e/__snapshots__/home.test.ts.snap b/__tests__/e2e/__snapshots__/home.test.ts.snap index 0c5972fc..ab5ce9c2 100644 --- a/__tests__/e2e/__snapshots__/home.test.ts.snap +++ b/__tests__/e2e/__snapshots__/home.test.ts.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Vitest Snapshot v1 exports[`render correct content > main content 1`] = ` [ diff --git a/__tests__/e2e/dynamic-routes/[id].md b/__tests__/e2e/dynamic-routes/[id].md new file mode 100644 index 00000000..a1ca54a0 --- /dev/null +++ b/__tests__/e2e/dynamic-routes/[id].md @@ -0,0 +1,8 @@ + + + + +
{{ page.params }}
diff --git a/__tests__/e2e/dynamic-routes/[id].paths.ts b/__tests__/e2e/dynamic-routes/[id].paths.ts new file mode 100644 index 00000000..3eca4d91 --- /dev/null +++ b/__tests__/e2e/dynamic-routes/[id].paths.ts @@ -0,0 +1,8 @@ +export default { + async paths() { + return [ + { params: { id: 'foo' }, content: `# Foo` }, + { params: { id: 'bar' }, content: `# Bar` } + ] + } +} diff --git a/__tests__/e2e/dynamic-routes/dynamic-routes.test.ts b/__tests__/e2e/dynamic-routes/dynamic-routes.test.ts new file mode 100644 index 00000000..5829ae89 --- /dev/null +++ b/__tests__/e2e/dynamic-routes/dynamic-routes.test.ts @@ -0,0 +1,11 @@ +describe('dynamic routes', () => { + test('render correct content', async () => { + await goto('/dynamic-routes/foo') + expect(await page.textContent('h1')).toMatch('Foo') + expect(await page.textContent('pre.params')).toMatch('"id": "foo"') + + await goto('/dynamic-routes/bar') + expect(await page.textContent('h1')).toMatch('Bar') + expect(await page.textContent('pre.params')).toMatch('"id": "bar"') + }) +}) diff --git a/__tests__/e2e/multi-sidebar/index.test.ts b/__tests__/e2e/multi-sidebar/index.test.ts index 294b3630..b26b3d5b 100644 --- a/__tests__/e2e/multi-sidebar/index.test.ts +++ b/__tests__/e2e/multi-sidebar/index.test.ts @@ -13,7 +13,8 @@ describe('test multi sidebar sort root', () => { 'Frontmatter', '& code', 'Static Data', - 'Multi Sidebar Test' + 'Multi Sidebar Test', + 'Dynamic Routes' ]) }) }) diff --git a/__tests__/e2e/static-data/__snapshots__/data.test.ts.snap b/__tests__/e2e/static-data/__snapshots__/data.test.ts.snap index 6f0bc57a..0e000a37 100644 --- a/__tests__/e2e/static-data/__snapshots__/data.test.ts.snap +++ b/__tests__/e2e/static-data/__snapshots__/data.test.ts.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Vitest Snapshot v1 exports[`static data file support in vite 3 > render correct content 1`] = ` [