Skip to content

Commit cbb5f2b

Browse files
committed
test: add resolver tests
1 parent 57ce797 commit cbb5f2b

File tree

14 files changed

+266
-68
lines changed

14 files changed

+266
-68
lines changed

e2e/hmr/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
playground-tmp-*
2+
playground-routes-tmp-*
3+
playground-resolver-tmp-*

e2e/hmr/fixtures/vite-server.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ type ViteFixtures = {
1010
baseURL: string
1111
projectRoot: string
1212
applyEditFile: (sourceFilePath: string, newContentFilePath: string) => void
13+
playgroundName: string
1314
}
1415

15-
const sourceDir = fileURLToPath(new URL('../playground', import.meta.url))
16-
1716
export const test = base.extend<ViteFixtures>({
17+
// @ts-expect-error: all options are scoped per worker
18+
playgroundName: ['', { scope: 'worker', option: true }],
19+
1820
// @ts-expect-error: we need to compute projectRoot per worker
1921
projectRoot: [
20-
async ({}, use, testInfo) => {
22+
async ({ playgroundName }, use, testInfo) => {
2123
const fixtureDir = fileURLToPath(
2224
new URL(
23-
`../playground-tmp-worker-${testInfo.workerIndex}`,
25+
`../playground-tmp-${playgroundName}-worker-${testInfo.workerIndex}`,
2426
import.meta.url
2527
)
2628
)
@@ -32,8 +34,9 @@ export const test = base.extend<ViteFixtures>({
3234

3335
// @ts-expect-error: type matched what is passed to use(server)
3436
devServer: [
35-
async ({ projectRoot }, use) => {
37+
async ({ projectRoot, playgroundName }, use) => {
3638
const fixtureDir = projectRoot
39+
const sourceDir = fileURLToPath(new URL(`../playground`, import.meta.url))
3740

3841
fs.rmSync(fixtureDir, { force: true, recursive: true })
3942
fs.cpSync(sourceDir, fixtureDir, {
@@ -50,7 +53,7 @@ export const test = base.extend<ViteFixtures>({
5053
// Start a real Vite dev server with your plugin(s) & config.
5154
// If you already have vite.config.ts, omit configFile:false and rely on it.
5255
const server = await createServer({
53-
configFile: path.join(fixtureDir, 'vite.config.ts'),
56+
configFile: path.join(fixtureDir, `vite.config.${playgroundName}.ts`),
5457
// If you need to inline the plugin directly, you could do:
5558
// configFile: false,
5659
// plugins: [myPlugin()],

e2e/hmr/playground/edits/src/pages/hmr-alias-define-page-with-alias.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ definePage({
77
<template>
88
<main>
99
<h1>HMR Alias Test</h1>
10-
<pre data-testid="route-path">{{ $route.path }}</pre>
1110
</main>
1211
</template>

e2e/hmr/playground/edits/src/pages/hmr-path-define-page-with-custom-path.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ definePage({
66

77
<template>
88
<main>
9-
<h1>HMR Path Test</h1>
10-
<pre data-testid="route-path">{{ $route.path }}</pre>
9+
<h1 data-testid="title">HMR Path Test</h1>
1110
</main>
1211
</template>

e2e/hmr/playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"private": true,
33
"name": "fixture-hmr",
44
"scripts": {
5+
"dev": "vite -c vite.config.routes.ts",
56
"build": "vite build"
67
}
78
}

e2e/hmr/playground/src/App.vue

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
<script setup lang="ts">
2+
import { ref } from 'vue';
3+
import { useRouter } from 'vue-router';
4+
5+
const to = ref('')
6+
const router = useRouter()
7+
8+
function navigate() {
9+
if (to.value) {
10+
router.push(to.value)
11+
}
12+
}
13+
</script>
14+
115
<template>
216
<nav>
317
<ul>
418
<li><RouterLink to="/">Home</RouterLink></li>
5-
<li>
6-
<RouterLink to="/custom-path" data-testid="custom-path-link"
7-
>Custom path after change</RouterLink
8-
>
9-
</li>
1019
</ul>
1120
</nav>
21+
22+
<pre data-testid="route">{{ $route.fullPath }}</pre>
23+
<form @submit.prevent="navigate" data-testid="navigator">
24+
<input type="text" v-model="to" data-testid="goto" placeholder="/about" />
25+
<button type="submit">Go</button>
26+
</form>
27+
1228
<hr />
1329

1430
<RouterView />
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<main>
33
<h1>HMR Alias Test</h1>
4-
<pre data-testid="route-path">{{ $route.path }}</pre>
54
</main>
65
</template>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<main>
33
<h1>HMR Path Test</h1>
4-
<pre data-testid="route-path">{{ $route.path }}</pre>
54
</main>
65
</template>
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { defineConfig } from 'vite'
22
import { fileURLToPath, URL } from 'node:url'
3-
import VueRouter from '../../../src/vite'
4-
import Vue from '@vitejs/plugin-vue'
53

64
const root = fileURLToPath(new URL('./', import.meta.url))
75

@@ -20,15 +18,4 @@ export default defineConfig({
2018
build: {
2119
sourcemap: true,
2220
},
23-
24-
plugins: [
25-
VueRouter({
26-
root,
27-
// logs: true,
28-
// defaults to false on CI
29-
watch: true,
30-
// getRouteName: getPascalCaseRouteName,
31-
}),
32-
Vue(),
33-
],
3421
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { mergeConfig } from 'vite'
2+
import baseConfig from './vite.config.base.ts'
3+
import { fileURLToPath, URL } from 'node:url'
4+
import VueRouter from '../../../src/vite'
5+
import Vue from '@vitejs/plugin-vue'
6+
7+
const root = fileURLToPath(new URL('./', import.meta.url))
8+
9+
export default mergeConfig(baseConfig, {
10+
plugins: [
11+
VueRouter({
12+
root,
13+
// logs: true,
14+
// defaults to false on CI
15+
watch: true,
16+
experimental: {
17+
paramParsers: true,
18+
},
19+
}),
20+
Vue(),
21+
],
22+
})

0 commit comments

Comments
 (0)