-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add nitro e2e suites #6274
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
Open
birkskyum
wants to merge
1
commit into
main
Choose a base branch
from
nitro-prerender-test-suites
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,615
−23
Open
add nitro e2e suites #6274
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| node_modules | ||
| .DS_Store | ||
| .cache | ||
| .env | ||
| dist | ||
| .output | ||
| .nitro | ||
|
|
||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "name": "tanstack-react-start-e2e-basic-nitro-spa", | ||
| "private": true, | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev:v2": "vite dev -c vite.config.v2.ts --port 3000", | ||
| "dev:v3": "vite dev -c vite.config.v3.ts --port 3000", | ||
| "dev:e2e:v2": "vite dev -c vite.config.v2.ts", | ||
| "dev:e2e:v3": "vite dev -c vite.config.v3.ts", | ||
| "build:v2": "vite build -c vite.config.v2.ts && tsc --noEmit", | ||
| "build:v3": "vite build -c vite.config.v3.ts && tsc --noEmit", | ||
| "preview:v2": "vite preview -c vite.config.v2.ts", | ||
| "preview:v3": "vite preview -c vite.config.v3.ts", | ||
| "test:e2e:shared": "rm -rf port*.txt; playwright test --project=chromium", | ||
| "test:e2e:v2": "rm -rf .output dist .nitro && NITRO_VARIANT=v2 pnpm run test:e2e:shared", | ||
| "test:e2e:v3": "rm -rf .output dist .nitro && NITRO_VARIANT=v3 pnpm run test:e2e:shared", | ||
| "test:e2e": "pnpm run test:e2e:v2 && pnpm run test:e2e:v3" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/react-router": "workspace:^", | ||
| "@tanstack/react-router-devtools": "workspace:^", | ||
| "@tanstack/react-start": "workspace:^", | ||
| "react": "^19.0.0", | ||
| "react-dom": "^19.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.50.1", | ||
| "@tailwindcss/postcss": "^4.1.15", | ||
| "@tanstack/router-e2e-utils": "workspace:^", | ||
| "@tanstack/nitro-v2-vite-plugin": "workspace:^", | ||
| "@types/node": "^22.10.2", | ||
| "@types/react": "^19.0.8", | ||
| "@types/react-dom": "^19.0.3", | ||
| "nitro": "npm:nitro-nightly@latest", | ||
| "postcss": "^8.5.1", | ||
| "tailwindcss": "^4.1.15", | ||
| "typescript": "^5.7.2", | ||
| "vite": "^7.1.7", | ||
| "vite-tsconfig-paths": "^5.1.4" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
| import { getTestServerPort } from '@tanstack/router-e2e-utils' | ||
| import packageJson from './package.json' with { type: 'json' } | ||
|
|
||
| const PORT = await getTestServerPort(packageJson.name) | ||
| const baseURL = `http://localhost:${PORT}` | ||
| const nitroVariant = process.env.NITRO_VARIANT | ||
| if (nitroVariant !== 'v2' && nitroVariant !== 'v3') { | ||
| throw new Error('Set NITRO_VARIANT to "v2" or "v3" for Nitro e2e tests.') | ||
| } | ||
| const buildScript = nitroVariant === 'v2' ? 'build:v2' : 'build:v3' | ||
| const buildCommand = `pnpm run ${buildScript}` | ||
|
|
||
| /** | ||
| * See https://playwright.dev/docs/test-configuration. | ||
| */ | ||
| export default defineConfig({ | ||
| testDir: './tests', | ||
| workers: 1, | ||
|
|
||
| reporter: [['line']], | ||
|
|
||
| use: { | ||
| /* Base URL to use in actions like `await page.goto('/')`. */ | ||
| baseURL, | ||
| }, | ||
|
|
||
| webServer: { | ||
| // Note: We run node directly instead of vite preview because Nitro's | ||
| // configurePreviewServer spawns on a random port. The prerendering during | ||
| // build uses vite.preview() correctly. | ||
| command: `${buildCommand} && PORT=${PORT} node .output/server/index.mjs`, | ||
| url: baseURL, | ||
| reuseExistingServer: !process.env.CI, | ||
| stdout: 'pipe', | ||
| }, | ||
|
|
||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| ], | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export default { | ||
| plugins: { | ||
| '@tailwindcss/postcss': {}, | ||
| }, | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
53 changes: 53 additions & 0 deletions
53
e2e/react-start/basic-nitro-spa/src/components/DefaultCatchBoundary.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { | ||
| ErrorComponent, | ||
| Link, | ||
| rootRouteId, | ||
| useMatch, | ||
| useRouter, | ||
| } from '@tanstack/react-router' | ||
| import type { ErrorComponentProps } from '@tanstack/react-router' | ||
|
|
||
| export function DefaultCatchBoundary({ error }: ErrorComponentProps) { | ||
| const router = useRouter() | ||
| const isRoot = useMatch({ | ||
| strict: false, | ||
| select: (state) => state.id === rootRouteId, | ||
| }) | ||
|
|
||
| console.error(error) | ||
|
|
||
| return ( | ||
| <div className="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6"> | ||
| <ErrorComponent error={error} /> | ||
| <div className="flex gap-2 items-center flex-wrap"> | ||
| <button | ||
| onClick={() => { | ||
| router.invalidate() | ||
| }} | ||
| className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Try Again | ||
| </button> | ||
| {isRoot ? ( | ||
| <Link | ||
| to="/" | ||
| className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Home | ||
| </Link> | ||
| ) : ( | ||
| <Link | ||
| to="/" | ||
| className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| onClick={(e) => { | ||
| e.preventDefault() | ||
| window.history.back() | ||
| }} | ||
| > | ||
| Go Back | ||
| </Link> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
25 changes: 25 additions & 0 deletions
25
e2e/react-start/basic-nitro-spa/src/components/NotFound.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Link } from '@tanstack/react-router' | ||
|
|
||
| export function NotFound({ children }: { children?: any }) { | ||
| return ( | ||
| <div className="space-y-2 p-2" data-testid="default-not-found-component"> | ||
| <div className="text-gray-600 dark:text-gray-400"> | ||
| {children || <p>The page you are looking for does not exist.</p>} | ||
| </div> | ||
| <p className="flex items-center gap-2 flex-wrap"> | ||
| <button | ||
| onClick={() => window.history.back()} | ||
| className="bg-emerald-500 text-white px-2 py-1 rounded-sm uppercase font-black text-sm" | ||
| > | ||
| Go back | ||
| </button> | ||
| <Link | ||
| to="/" | ||
| className="bg-cyan-600 text-white px-2 py-1 rounded-sm uppercase font-black text-sm" | ||
| > | ||
| Start Over | ||
| </Link> | ||
| </p> | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* eslint-disable */ | ||
|
|
||
| // @ts-nocheck | ||
|
|
||
| // noinspection JSUnusedGlobalSymbols | ||
|
|
||
| // This file was automatically generated by TanStack Router. | ||
| // You should NOT make any changes in this file as it will be overwritten. | ||
| // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. | ||
|
|
||
| import { Route as rootRouteImport } from './routes/__root' | ||
| import { Route as StaticRouteImport } from './routes/static' | ||
| import { Route as IndexRouteImport } from './routes/index' | ||
|
|
||
| const StaticRoute = StaticRouteImport.update({ | ||
| id: '/static', | ||
| path: '/static', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const IndexRoute = IndexRouteImport.update({ | ||
| id: '/', | ||
| path: '/', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
|
|
||
| export interface FileRoutesByFullPath { | ||
| '/': typeof IndexRoute | ||
| '/static': typeof StaticRoute | ||
| } | ||
| export interface FileRoutesByTo { | ||
| '/': typeof IndexRoute | ||
| '/static': typeof StaticRoute | ||
| } | ||
| export interface FileRoutesById { | ||
| __root__: typeof rootRouteImport | ||
| '/': typeof IndexRoute | ||
| '/static': typeof StaticRoute | ||
| } | ||
| export interface FileRouteTypes { | ||
| fileRoutesByFullPath: FileRoutesByFullPath | ||
| fullPaths: '/' | '/static' | ||
| fileRoutesByTo: FileRoutesByTo | ||
| to: '/' | '/static' | ||
| id: '__root__' | '/' | '/static' | ||
| fileRoutesById: FileRoutesById | ||
| } | ||
| export interface RootRouteChildren { | ||
| IndexRoute: typeof IndexRoute | ||
| StaticRoute: typeof StaticRoute | ||
| } | ||
|
|
||
| declare module '@tanstack/react-router' { | ||
| interface FileRoutesByPath { | ||
| '/static': { | ||
| id: '/static' | ||
| path: '/static' | ||
| fullPath: '/static' | ||
| preLoaderRoute: typeof StaticRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/': { | ||
| id: '/' | ||
| path: '/' | ||
| fullPath: '/' | ||
| preLoaderRoute: typeof IndexRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const rootRouteChildren: RootRouteChildren = { | ||
| IndexRoute: IndexRoute, | ||
| StaticRoute: StaticRoute, | ||
| } | ||
| export const routeTree = rootRouteImport | ||
| ._addFileChildren(rootRouteChildren) | ||
| ._addFileTypes<FileRouteTypes>() | ||
|
|
||
| import type { getRouter } from './router.tsx' | ||
| import type { createStart } from '@tanstack/react-start' | ||
| declare module '@tanstack/react-start' { | ||
| interface Register { | ||
| ssr: true | ||
| router: Awaited<ReturnType<typeof getRouter>> | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { createRouter } from '@tanstack/react-router' | ||
| import { routeTree } from './routeTree.gen' | ||
| import { DefaultCatchBoundary } from './components/DefaultCatchBoundary' | ||
| import { NotFound } from './components/NotFound' | ||
|
|
||
| export function getRouter() { | ||
| const router = createRouter({ | ||
| routeTree, | ||
| defaultPreload: 'intent', | ||
| defaultErrorComponent: DefaultCatchBoundary, | ||
| defaultNotFoundComponent: () => <NotFound />, | ||
| scrollRestoration: true, | ||
| }) | ||
|
|
||
| return router | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /// <reference types="vite/client" /> | ||
| import { | ||
| HeadContent, | ||
| Link, | ||
| Scripts, | ||
| createRootRoute, | ||
| } from '@tanstack/react-router' | ||
| import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' | ||
| import * as React from 'react' | ||
| import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary' | ||
| import { NotFound } from '~/components/NotFound' | ||
| import appCss from '~/styles/app.css?url' | ||
| import { seo } from '~/utils/seo' | ||
|
|
||
| export const Route = createRootRoute({ | ||
| head: () => ({ | ||
| meta: [ | ||
| { | ||
| charSet: 'utf-8', | ||
| }, | ||
| { | ||
| name: 'viewport', | ||
| content: 'width=device-width, initial-scale=1', | ||
| }, | ||
| ...seo({ | ||
| title: 'TanStack Start + Nitro E2E Test', | ||
| description: 'Testing nitro integration with TanStack Start', | ||
| }), | ||
| ], | ||
| links: [ | ||
| { rel: 'stylesheet', href: appCss }, | ||
| { rel: 'icon', href: '/favicon.ico' }, | ||
| ], | ||
| }), | ||
| errorComponent: DefaultCatchBoundary, | ||
| notFoundComponent: () => <NotFound />, | ||
| shellComponent: RootDocument, | ||
| }) | ||
|
|
||
| function RootDocument({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <html> | ||
| <head> | ||
| <HeadContent /> | ||
| </head> | ||
| <body> | ||
| <div className="p-2 flex gap-2 text-lg"> | ||
| <Link | ||
| to="/" | ||
| activeProps={{ | ||
| className: 'font-bold', | ||
| }} | ||
| activeOptions={{ exact: true }} | ||
| > | ||
| Home | ||
| </Link> | ||
| <Link | ||
| to="/static" | ||
| activeProps={{ | ||
| className: 'font-bold', | ||
| }} | ||
| > | ||
| Static | ||
| </Link> | ||
| </div> | ||
| <hr /> | ||
| {children} | ||
| <TanStackRouterDevtools position="bottom-right" /> | ||
| <Scripts /> | ||
| </body> | ||
| </html> | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion | 🟠 Major
Replace
anytype withReact.ReactNodefor strict type safety.The
childrenparameter usesany, which violates TypeScript strict mode guidelines. UseReact.ReactNodefor proper type safety.As per coding guidelines, TypeScript strict mode with extensive type safety should be used for all TypeScript files.
🔎 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents