Skip to content

Commit 9d21d2d

Browse files
committed
test: group e2e tests
1 parent ebca2c2 commit 9d21d2d

File tree

2 files changed

+105
-23
lines changed

2 files changed

+105
-23
lines changed

e2e/__snapshots__/routes.spec.ts.snap

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`generates the routes 1`] = `
3+
exports[`e2e routes > generates the routes 1`] = `
44
"export const routes = [
55
{
66
path: '/',
@@ -120,3 +120,47 @@ exports[`generates the routes 1`] = `
120120
]
121121
"
122122
`;
123+
124+
exports[`e2e routes > works with mixed extensions 1`] = `
125+
"export const routes = [
126+
{
127+
path: '/',
128+
name: '/',
129+
component: () => import('/multi-extensions/index.vue'),
130+
/* no children */
131+
},
132+
{
133+
path: '/about',
134+
name: '/about',
135+
component: () => import('/multi-extensions/about.vue'),
136+
/* no children */
137+
},
138+
{
139+
path: '/docs',
140+
/* internal name: '/docs' */
141+
/* no component */
142+
children: [
143+
{
144+
path: ':lang',
145+
/* internal name: '/docs/[lang]' */
146+
/* no component */
147+
children: [
148+
{
149+
path: '',
150+
name: '/docs/[lang]/',
151+
component: () => import('/multi-extensions/docs/index.md'),
152+
/* no children */
153+
},
154+
{
155+
path: ':pathMatch(.*)',
156+
name: '/docs/[lang]/[...pathMatch]',
157+
component: () => import('/multi-extensions/docs/[...pathMatch].vue'),
158+
/* no children */
159+
}
160+
],
161+
}
162+
],
163+
}
164+
]
165+
"
166+
`;

e2e/routes.spec.ts

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { expect, it } from 'vitest'
1+
import { describe, expect, it } from 'vitest'
22
import { createRoutesContext } from '../src/core/context'
3-
import { DEFAULT_OPTIONS, resolveOptions } from '../src/options'
4-
import { fileURLToPath, URL } from 'url'
3+
import { resolveOptions } from '../src/options'
4+
import { fileURLToPath, URL } from 'node:url'
55
import { normalize, join } from 'pathe'
66

77
const __dirname = fileURLToPath(new URL('./', import.meta.url))
@@ -10,24 +10,62 @@ const __dirname = fileURLToPath(new URL('./', import.meta.url))
1010
* This is a simple full test to check that all filenames are valid in different environment (windows, mac, linux).
1111
*/
1212

13-
it('generates the routes', async () => {
14-
const context = createRoutesContext(
15-
resolveOptions({
16-
// dts: join(__dirname, './__types.d.ts'),
17-
dts: false,
18-
logs: false,
19-
routesFolder: [{ src: join(__dirname, './fixtures/filenames/routes') }],
20-
})
21-
)
13+
describe('e2e routes', () => {
14+
it('generates the routes', async () => {
15+
const context = createRoutesContext(
16+
resolveOptions({
17+
// dts: join(__dirname, './__types.d.ts'),
18+
dts: false,
19+
logs: false,
20+
watch: false,
21+
routesFolder: [{ src: join(__dirname, './fixtures/filenames/routes') }],
22+
})
23+
)
2224

23-
await context.scanPages()
24-
expect(
25-
context
26-
.generateRoutes()
27-
.replace(
28-
/import\(["'](.+?)["']\)/g,
29-
(_, filePath) => `import('${normalize(filePath)}')`
30-
)
31-
.replace(/(import\(["'])(?:.+?)fixtures\/filenames/gi, '$1')
32-
).toMatchSnapshot()
25+
await context.scanPages()
26+
expect(
27+
context
28+
.generateRoutes()
29+
.replace(
30+
/import\(["'](.+?)["']\)/g,
31+
(_, filePath) => `import('${normalize(filePath)}')`
32+
)
33+
.replace(/(import\(["'])(?:.+?)fixtures\/filenames/gi, '$1')
34+
).toMatchSnapshot()
35+
})
36+
37+
it.skip('works with mixed extensions', async () => {
38+
const context = createRoutesContext(
39+
resolveOptions({
40+
dts: false,
41+
logs: false,
42+
watch: false,
43+
routesFolder: [
44+
{
45+
src: join(__dirname, './fixtures/filenames/multi-extensions'),
46+
exclude: join(
47+
__dirname,
48+
'./fixtures/filenames/multi-extensions/docs'
49+
),
50+
},
51+
{
52+
src: join(__dirname, './fixtures/filenames/multi-extensions/docs'),
53+
extensions: ['.md', '.vue'],
54+
path: 'docs/[lang]/',
55+
},
56+
],
57+
})
58+
)
59+
60+
await context.scanPages()
61+
expect(
62+
context
63+
.generateRoutes()
64+
.replace(
65+
/import\(["'](.+?)["']\)/g,
66+
(_, filePath) => `import('${normalize(filePath)}')`
67+
)
68+
.replace(/(import\(["'])(?:.+?)fixtures\/filenames/gi, '$1')
69+
).toMatchSnapshot()
70+
})
3371
})

0 commit comments

Comments
 (0)