Skip to content

Commit 6380e00

Browse files
committed
e2e test
1 parent 8f94e8a commit 6380e00

10 files changed

Lines changed: 299 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "tanstack-solid-start-e2e-nitro-query",
3+
"private": true,
4+
"sideEffects": false,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite dev --port 3000",
8+
"dev:e2e": "vite dev",
9+
"build": "vite build && tsc --noEmit",
10+
"preview": "vite preview",
11+
"start": "pnpx srvx --prod -s ../client dist/server/server.js",
12+
"test:e2e": "rm -rf port*.txt; playwright test --project=chromium"
13+
},
14+
"dependencies": {
15+
"@tanstack/solid-query": "^5.90.9",
16+
"@tanstack/solid-router": "workspace:^",
17+
"@tanstack/solid-router-ssr-query": "workspace:^",
18+
"@tanstack/solid-start": "workspace:^",
19+
"nitro": "^3.0.1-alpha.1",
20+
"solid-js": "^1.9.10",
21+
"vite": "^8.0.0"
22+
},
23+
"dependenciesMeta": {
24+
"@tanstack/solid-router-ssr-query": {
25+
"injected": true
26+
}
27+
},
28+
"devDependencies": {
29+
"@playwright/test": "^1.50.1",
30+
"@tanstack/router-e2e-utils": "workspace:^",
31+
"@types/node": "^22.10.2",
32+
"typescript": "^6.0.2",
33+
"vite-plugin-solid": "^2.11.11"
34+
}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import { getTestServerPort } from '@tanstack/router-e2e-utils'
3+
import packageJson from './package.json' with { type: 'json' }
4+
5+
const PORT = await getTestServerPort(packageJson.name)
6+
const baseURL = `http://localhost:${PORT}`
7+
8+
const mode = process.env.MODE ?? 'dev'
9+
const isDev = mode === 'dev'
10+
11+
export default defineConfig({
12+
testDir: './tests',
13+
workers: 1,
14+
reporter: [['line']],
15+
use: { baseURL },
16+
webServer: {
17+
command: isDev
18+
? `PORT=${PORT} pnpm dev:e2e`
19+
: `pnpm build && PORT=${PORT} pnpm start`,
20+
url: baseURL,
21+
reuseExistingServer: !process.env.CI,
22+
stdout: 'pipe',
23+
},
24+
projects: [
25+
{
26+
name: 'chromium',
27+
use: { ...devices['Desktop Chrome'] },
28+
},
29+
],
30+
})
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* eslint-disable */
2+
3+
// @ts-nocheck
4+
5+
// noinspection JSUnusedGlobalSymbols
6+
7+
// This file was automatically generated by TanStack Router.
8+
// You should NOT make any changes in this file as it will be overwritten.
9+
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
10+
11+
import { Route as rootRouteImport } from './routes/__root'
12+
import { Route as IndexRouteImport } from './routes/index'
13+
14+
const IndexRoute = IndexRouteImport.update({
15+
id: '/',
16+
path: '/',
17+
getParentRoute: () => rootRouteImport,
18+
} as any)
19+
20+
export interface FileRoutesByFullPath {
21+
'/': typeof IndexRoute
22+
}
23+
export interface FileRoutesByTo {
24+
'/': typeof IndexRoute
25+
}
26+
export interface FileRoutesById {
27+
__root__: typeof rootRouteImport
28+
'/': typeof IndexRoute
29+
}
30+
export interface FileRouteTypes {
31+
fileRoutesByFullPath: FileRoutesByFullPath
32+
fullPaths: '/'
33+
fileRoutesByTo: FileRoutesByTo
34+
to: '/'
35+
id: '__root__' | '/'
36+
fileRoutesById: FileRoutesById
37+
}
38+
export interface RootRouteChildren {
39+
IndexRoute: typeof IndexRoute
40+
}
41+
42+
declare module '@tanstack/solid-router' {
43+
interface FileRoutesByPath {
44+
'/': {
45+
id: '/'
46+
path: '/'
47+
fullPath: '/'
48+
preLoaderRoute: typeof IndexRouteImport
49+
parentRoute: typeof rootRouteImport
50+
}
51+
}
52+
}
53+
54+
const rootRouteChildren: RootRouteChildren = {
55+
IndexRoute: IndexRoute,
56+
}
57+
export const routeTree = rootRouteImport
58+
._addFileChildren(rootRouteChildren)
59+
._addFileTypes<FileRouteTypes>()
60+
61+
import type { getRouter } from './router.tsx'
62+
import type { createStart } from '@tanstack/solid-start'
63+
declare module '@tanstack/solid-start' {
64+
interface Register {
65+
ssr: true
66+
router: Awaited<ReturnType<typeof getRouter>>
67+
}
68+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { QueryClient } from '@tanstack/solid-query'
2+
import { createRouter } from '@tanstack/solid-router'
3+
import { setupRouterSsrQueryIntegration } from '@tanstack/solid-router-ssr-query'
4+
import { routeTree } from './routeTree.gen'
5+
6+
export function getRouter() {
7+
const queryClient = new QueryClient()
8+
const router = createRouter({
9+
routeTree,
10+
context: { queryClient },
11+
defaultPreload: 'intent',
12+
})
13+
setupRouterSsrQueryIntegration({ router, queryClient })
14+
return router
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference types="vite/client" />
2+
import {
3+
HeadContent,
4+
Scripts,
5+
createRootRouteWithContext,
6+
} from '@tanstack/solid-router'
7+
import { HydrationScript } from 'solid-js/web'
8+
import type { QueryClient } from '@tanstack/solid-query'
9+
10+
export const Route = createRootRouteWithContext<{
11+
queryClient: QueryClient
12+
}>()({
13+
shellComponent: RootDocument,
14+
})
15+
16+
function RootDocument(props: { children?: any }) {
17+
return (
18+
<html>
19+
<head>
20+
<HydrationScript />
21+
<HeadContent />
22+
</head>
23+
<body>
24+
{props.children}
25+
<Scripts />
26+
</body>
27+
</html>
28+
)
29+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createFileRoute } from '@tanstack/solid-router'
2+
import { createQuery } from '@tanstack/solid-query'
3+
4+
export const Route = createFileRoute('/')({
5+
component: Home,
6+
})
7+
8+
function Home() {
9+
const query = createQuery(() => ({
10+
queryKey: ['nitro-query-e2e'],
11+
queryFn: () => Promise.resolve('ok'),
12+
initialData: 'ok',
13+
}))
14+
return (
15+
<div>
16+
<h1>Nitro Query E2E</h1>
17+
<div data-testid="query-data">{query.data}</div>
18+
</div>
19+
)
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect } from '@playwright/test'
2+
import { test } from '@tanstack/router-e2e-utils'
3+
4+
test('direct visit to a createQuery route renders without SSR error', async ({
5+
page,
6+
}) => {
7+
const errors: Array<string> = []
8+
page.on('pageerror', (err) => errors.push(err.message))
9+
10+
await page.goto('/')
11+
12+
await expect(page.getByTestId('query-data')).toHaveText('ok')
13+
expect(errors.join('\n')).not.toContain('defaultQueryOptions')
14+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"include": ["**/*.ts", "**/*.tsx"],
3+
"compilerOptions": {
4+
"strict": true,
5+
"esModuleInterop": true,
6+
"jsx": "preserve",
7+
"jsxImportSource": "solid-js",
8+
"module": "ESNext",
9+
"moduleResolution": "Bundler",
10+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
11+
"isolatedModules": true,
12+
"resolveJsonModule": true,
13+
"skipLibCheck": true,
14+
"target": "ES2022",
15+
"allowJs": true,
16+
"forceConsistentCasingInFileNames": true,
17+
"noEmit": true,
18+
"types": ["vite/client"]
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vite'
2+
import { tanstackStart } from '@tanstack/solid-start/plugin/vite'
3+
import solid from 'vite-plugin-solid'
4+
import { nitro } from 'nitro/vite'
5+
6+
export default defineConfig({
7+
plugins: [nitro(), tanstackStart(), solid({ ssr: true })],
8+
})

‎pnpm-lock.yaml‎

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)