-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test(vue-start): custom-basepath #6130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| node_modules | ||
| package-lock.json | ||
| yarn.lock | ||
|
|
||
| .DS_Store | ||
| .cache | ||
| .env | ||
| .vercel | ||
| .output | ||
|
|
||
| /build/ | ||
| /api/ | ||
| /server/build | ||
| /public/build | ||
| # Sentry Config File | ||
| .env.sentry-build-plugin | ||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| **/build | ||
| **/public | ||
| pnpm-lock.yaml | ||
| routeTree.gen.ts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import express from 'express' | ||
| import { toNodeHandler } from 'srvx/node' | ||
|
|
||
| const DEVELOPMENT = process.env.NODE_ENV === 'development' | ||
| const PORT = Number.parseInt(process.env.PORT || '3000') | ||
|
|
||
| const app = express() | ||
|
|
||
| if (DEVELOPMENT) { | ||
| const viteDevServer = await import('vite').then((vite) => | ||
| vite.createServer({ | ||
| server: { middlewareMode: true }, | ||
| }), | ||
| ) | ||
| app.use(viteDevServer.middlewares) | ||
| app.use(async (req, res, next) => { | ||
| try { | ||
| const { default: serverEntry } = | ||
| await viteDevServer.ssrLoadModule('./src/server.ts') | ||
| const handler = toNodeHandler(serverEntry.fetch) | ||
| await handler(req, res) | ||
| } catch (error) { | ||
| if (typeof error === 'object' && error instanceof Error) { | ||
| viteDevServer.ssrFixStacktrace(error) | ||
| } | ||
| next(error) | ||
| } | ||
| }) | ||
| } else { | ||
| const { default: handler } = await import('./dist/server/server.js') | ||
| const nodeHandler = toNodeHandler(handler.fetch) | ||
| app.use('/custom/basepath', express.static('dist/client')) | ||
| app.use(async (req, res, next) => { | ||
| try { | ||
| await nodeHandler(req, res) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| app.listen(PORT, () => { | ||
| console.log(`Server is running on http://localhost:${PORT}`) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "name": "tanstack-vue-start-e2e-custom-basepath", | ||
| "private": true, | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "cross-env NODE_ENV=development tsx express-server.ts", | ||
| "build": "vite build && tsc --noEmit", | ||
| "preview": "vite preview", | ||
| "start": "tsx express-server.ts", | ||
| "test:e2e": "rm -rf port*.txt; playwright test --project=chromium" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/vue-router": "workspace:^", | ||
| "@tanstack/vue-router-devtools": "workspace:^", | ||
| "@tanstack/vue-start": "workspace:^", | ||
| "express": "^4.21.2", | ||
| "redaxios": "^0.5.1", | ||
| "vue": "^3.5.25" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.50.1", | ||
| "@tailwindcss/postcss": "^4.1.15", | ||
| "@tanstack/router-e2e-utils": "workspace:^", | ||
| "@types/express": "^5.0.3", | ||
| "@types/node": "^22.10.2", | ||
| "cross-env": "^10.0.0", | ||
| "postcss": "^8.5.1", | ||
| "srvx": "^0.9.8", | ||
| "tailwindcss": "^4.1.17", | ||
| "tsx": "^4.20.3", | ||
| "typescript": "^5.7.2", | ||
| "vite": "^7.1.7", | ||
| "@vitejs/plugin-vue": "^6.0.3", | ||
| "@vitejs/plugin-vue-jsx": "^5.1.2", | ||
| "vite-tsconfig-paths": "^5.1.4" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
| import { | ||
| getDummyServerPort, | ||
| getTestServerPort, | ||
| } from '@tanstack/router-e2e-utils' | ||
| import packageJson from './package.json' with { type: 'json' } | ||
|
|
||
| const PORT = await getTestServerPort(packageJson.name) | ||
| const EXTERNAL_PORT = await getDummyServerPort(packageJson.name) | ||
| const baseURL = `http://localhost:${PORT}/custom/basepath` | ||
|
|
||
| /** | ||
| * See https://playwright.dev/docs/test-configuration. | ||
| */ | ||
| export default defineConfig({ | ||
| testDir: './tests', | ||
| workers: 1, | ||
|
|
||
| reporter: [['line']], | ||
|
|
||
| globalSetup: './tests/setup/global.setup.ts', | ||
| globalTeardown: './tests/setup/global.teardown.ts', | ||
|
|
||
| use: { | ||
| /* Base URL to use in actions like `await page.goto('/')`. */ | ||
| baseURL, | ||
| }, | ||
|
|
||
| webServer: { | ||
| command: `VITE_NODE_ENV="test" VITE_EXTERNAL_PORT=${EXTERNAL_PORT} pnpm build && VITE_NODE_ENV="test" VITE_EXTERNAL_PORT=${EXTERNAL_PORT} VITE_SERVER_PORT=${PORT} PORT=${PORT} pnpm start`, | ||
| url: baseURL, | ||
| reuseExistingServer: !process.env.CI, | ||
| stdout: 'pipe', | ||
| }, | ||
|
|
||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| ], | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export default { | ||
| plugins: { | ||
| '@tailwindcss/postcss': {}, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| console.log('SCRIPT_1 loaded') | ||
| window.SCRIPT_1 = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| console.log('SCRIPT_2 loaded') | ||
| window.SCRIPT_2 = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "", | ||
| "short_name": "", | ||
| "icons": [ | ||
| { | ||
| "src": "/android-chrome-192x192.png", | ||
| "sizes": "192x192", | ||
| "type": "image/png" | ||
| }, | ||
| { | ||
| "src": "/android-chrome-512x512.png", | ||
| "sizes": "512x512", | ||
| "type": "image/png" | ||
| } | ||
| ], | ||
| "theme_color": "#ffffff", | ||
| "background_color": "#ffffff", | ||
| "display": "standalone" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export function CustomMessage({ message }: { message: string }) { | ||
| return ( | ||
| <div class="py-2"> | ||
| <div class="italic">This is a custom message:</div> | ||
| <p>{message}</p> | ||
| </div> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { | ||
| ErrorComponent, | ||
| Link, | ||
| rootRouteId, | ||
| useMatch, | ||
| useRouter, | ||
| } from '@tanstack/vue-router' | ||
| import type { ErrorComponentProps } from '@tanstack/vue-router' | ||
|
|
||
| export function DefaultCatchBoundary({ error }: ErrorComponentProps) { | ||
| const router = useRouter() | ||
| const isRoot = useMatch({ | ||
| strict: false, | ||
| select: (state) => state.id === rootRouteId, | ||
| }) | ||
|
|
||
| console.error(error) | ||
|
|
||
| return ( | ||
| <div class="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6"> | ||
| <ErrorComponent error={error} /> | ||
| <div class="flex gap-2 items-center flex-wrap"> | ||
| <button | ||
| onClick={() => { | ||
| router.invalidate() | ||
| }} | ||
| class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Try Again | ||
| </button> | ||
| {isRoot.value ? ( | ||
| <Link | ||
| to="/" | ||
| class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Home | ||
| </Link> | ||
| ) : ( | ||
| <Link | ||
| to="/" | ||
| class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| onClick={(e: MouseEvent) => { | ||
| e.preventDefault() | ||
| window.history.back() | ||
| }} | ||
| > | ||
| Go Back | ||
| </Link> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||
| import { Link } from '@tanstack/vue-router' | ||||||
|
|
||||||
| export function NotFound({ children }: { children?: any }) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Replace The As per coding guidelines, TypeScript strict mode with extensive type safety should be used for all code. Apply this diff: -export function NotFound({ children }: { children?: any }) {
+export function NotFound({ children }: { children?: JSX.Element | string }) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| return ( | ||||||
| <div class="space-y-2 p-2" data-testid="default-not-found-component"> | ||||||
| <div class="text-gray-600 dark:text-gray-400"> | ||||||
| {children || <p>The page you are looking for does not exist.</p>} | ||||||
| </div> | ||||||
| <p class="flex items-center gap-2 flex-wrap"> | ||||||
| <button | ||||||
| onClick={() => window.history.back()} | ||||||
| class="bg-emerald-500 text-white px-2 py-1 rounded-sm uppercase font-black text-sm" | ||||||
| > | ||||||
| Go back | ||||||
| </button> | ||||||
| <Link | ||||||
| to="/" | ||||||
| class="bg-cyan-600 text-white px-2 py-1 rounded-sm uppercase font-black text-sm" | ||||||
| > | ||||||
| Start Over | ||||||
| </Link> | ||||||
| </p> | ||||||
| </div> | ||||||
| ) | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { ErrorComponent, ErrorComponentProps } from '@tanstack/vue-router' | ||
|
|
||
| export function PostErrorComponent({ error }: ErrorComponentProps) { | ||
| return <ErrorComponent error={error} /> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { ErrorComponent } from '@tanstack/vue-router' | ||
| import type { ErrorComponentProps } from '@tanstack/vue-router' | ||
|
|
||
| export function UserErrorComponent({ error }: ErrorComponentProps) { | ||
| return <ErrorComponent error={error} /> | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
workspace:*protocol for internal dependencies.The coding guidelines require using
workspace:*instead ofworkspace:^for internal monorepo dependencies.As per coding guidelines, apply this diff:
"dependencies": { - "@tanstack/vue-router": "workspace:^", - "@tanstack/vue-router-devtools": "workspace:^", - "@tanstack/vue-start": "workspace:^", + "@tanstack/vue-router": "workspace:*", + "@tanstack/vue-router-devtools": "workspace:*", + "@tanstack/vue-start": "workspace:*", "express": "^4.21.2", "redaxios": "^0.5.1", "vue": "^3.5.25" }, "devDependencies": { "@playwright/test": "^1.50.1", "@tailwindcss/postcss": "^4.1.15", - "@tanstack/router-e2e-utils": "workspace:^", + "@tanstack/router-e2e-utils": "workspace:*", "@types/express": "^5.0.3",Also applies to: 24-24
🤖 Prompt for AI Agents