Skip to content

Commit 8628d01

Browse files
authored
test(vue-router): rsbuild suites (#6117)
1 parent a6134ff commit 8628d01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1500
-47
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Local
2+
.DS_Store
3+
*.local
4+
*.log*
5+
6+
# Dist
7+
node_modules
8+
dist/
9+
dist-hash/
10+
11+
# IDE
12+
.vscode/*
13+
!.vscode/extensions.json
14+
.idea
15+
16+
# E2E
17+
src/routeTree.gen.ts
18+
test-results/
19+
/playwright-report/
20+
/blob-report/
21+
/playwright/.cache/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example
2+
3+
To run this example:
4+
5+
- `pnpm install`
6+
- `pnpm dev`
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "tanstack-router-e2e-vue-rspack-basic-file-based",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "rsbuild dev --port 3000",
7+
"build": "rsbuild build && tsc --noEmit",
8+
"preview": "rsbuild preview",
9+
"start": "rsbuild preview",
10+
"test:e2e": "rm -rf port*.txt; playwright test --project=chromium"
11+
},
12+
"dependencies": {
13+
"@tanstack/vue-router": "workspace:^",
14+
"@tanstack/vue-router-devtools": "workspace:^",
15+
"redaxios": "^0.5.1",
16+
"vue": "^3.5.16"
17+
},
18+
"devDependencies": {
19+
"@playwright/test": "^1.50.1",
20+
"@rsbuild/core": "^1.2.4",
21+
"@rsbuild/plugin-babel": "^1.0.6",
22+
"@rsbuild/plugin-vue": "^1.2.2",
23+
"@rsbuild/plugin-vue-jsx": "^1.1.1",
24+
"@tailwindcss/postcss": "^4.1.15",
25+
"@tanstack/router-e2e-utils": "workspace:^",
26+
"@tanstack/router-plugin": "workspace:^",
27+
"@tanstack/virtual-file-routes": "workspace:^",
28+
"postcss": "^8.5.1",
29+
"tailwindcss": "^4.1.17",
30+
"typescript": "^5.7.2",
31+
"vue-tsc": "^3.1.5"
32+
}
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import {
3+
getDummyServerPort,
4+
getTestServerPort,
5+
} from '@tanstack/router-e2e-utils'
6+
import packageJson from './package.json' with { type: 'json' }
7+
8+
const PORT = await getTestServerPort(packageJson.name)
9+
const EXTERNAL_PORT = await getDummyServerPort(packageJson.name)
10+
const baseURL = `http://localhost:${PORT}`
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
workers: 1,
17+
18+
reporter: [['line']],
19+
20+
globalSetup: './tests/setup/global.setup.ts',
21+
globalTeardown: './tests/setup/global.teardown.ts',
22+
23+
use: {
24+
/* Base URL to use in actions like `await page.goto('/')`. */
25+
baseURL,
26+
},
27+
28+
webServer: {
29+
command: `PUBLIC_NODE_ENV="test" PUBLIC_EXTERNAL_PORT=${EXTERNAL_PORT} PUBLIC_SERVER_PORT=${PORT} pnpm build && PUBLIC_NODE_ENV="test" PUBLIC_EXTERNAL_PORT=${EXTERNAL_PORT} PUBLIC_SERVER_PORT=${PORT} pnpm preview --port ${PORT}`,
30+
url: baseURL,
31+
reuseExistingServer: !process.env.CI,
32+
stdout: 'pipe',
33+
},
34+
35+
projects: [
36+
{
37+
name: 'chromium',
38+
use: { ...devices['Desktop Chrome'] },
39+
},
40+
],
41+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
plugins: {
3+
'@tailwindcss/postcss': {},
4+
},
5+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { defineConfig } from '@rsbuild/core'
2+
import { pluginVue } from '@rsbuild/plugin-vue'
3+
import { pluginVueJsx } from '@rsbuild/plugin-vue-jsx'
4+
import { tanstackRouter } from '@tanstack/router-plugin/rspack'
5+
import { pluginBabel } from '@rsbuild/plugin-babel'
6+
7+
export default defineConfig({
8+
plugins: [
9+
pluginBabel({
10+
include: /\.(?:jsx|tsx)$/,
11+
}),
12+
pluginVue(),
13+
pluginVueJsx(),
14+
],
15+
source: {
16+
define: {
17+
// Rsbuild only defines `import.meta.env.PUBLIC_*` when the env var exists.
18+
// When it doesn't, rspack can transform `import.meta.env` to `void 0`, which
19+
// makes `import.meta.env.PUBLIC_*` crash at runtime.
20+
'import.meta.env.PUBLIC_NODE_ENV': JSON.stringify(
21+
process.env.PUBLIC_NODE_ENV ?? '',
22+
),
23+
'import.meta.env.PUBLIC_EXTERNAL_PORT': JSON.stringify(
24+
process.env.PUBLIC_EXTERNAL_PORT ?? '',
25+
),
26+
},
27+
},
28+
tools: {
29+
rspack: {
30+
plugins: [tanstackRouter({ target: 'vue', autoCodeSplitting: true })],
31+
},
32+
},
33+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { RouterProvider, createRouter } from '@tanstack/vue-router'
2+
3+
import { routeTree } from './routeTree.gen'
4+
import './styles.css'
5+
6+
// Set up a Router instance
7+
const router = createRouter({
8+
routeTree,
9+
defaultPreload: 'intent',
10+
scrollRestoration: true,
11+
})
12+
13+
// Register things for typesafety
14+
declare module '@tanstack/vue-router' {
15+
interface Register {
16+
router: typeof router
17+
}
18+
}
19+
const App = () => {
20+
return <RouterProvider router={router} />
21+
}
22+
23+
export default App
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@rsbuild/core/types" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createApp } from 'vue'
2+
import App from './app'
3+
4+
const rootEl = document.getElementById('root')
5+
6+
if (!rootEl?.innerHTML) {
7+
createApp({
8+
setup() {
9+
return () => <App />
10+
},
11+
}).mount('#root')
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { notFound } from '@tanstack/vue-router'
2+
import axios from 'redaxios'
3+
4+
export type PostType = {
5+
id: string
6+
title: string
7+
body: string
8+
}
9+
10+
let queryURL = 'https://jsonplaceholder.typicode.com'
11+
12+
if (import.meta.env.PUBLIC_NODE_ENV === 'test') {
13+
queryURL = `http://localhost:${import.meta.env.PUBLIC_EXTERNAL_PORT}`
14+
}
15+
16+
export const fetchPost = async (postId: string) => {
17+
console.info(`Fetching post with id ${postId}...`)
18+
const post = await axios
19+
.get<PostType>(`${queryURL}/posts/${postId}`)
20+
.then((r) => r.data)
21+
.catch((err) => {
22+
if (err.status === 404) {
23+
throw notFound()
24+
}
25+
throw err
26+
})
27+
28+
return post
29+
}
30+
31+
export const fetchPosts = async () => {
32+
console.info('Fetching posts...')
33+
return axios
34+
.get<Array<PostType>>(`${queryURL}/posts`)
35+
.then((r) => r.data.slice(0, 10))
36+
}

0 commit comments

Comments
 (0)