Skip to content

Commit 160f5a7

Browse files
committed
test: Add React tests
1 parent 4bb102d commit 160f5a7

25 files changed

+149
-166
lines changed

packages/e2e/react-router/v6/vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export default defineConfig(() => ({
66
plugins: [react()],
77
build: {
88
target: 'es2022',
9-
sourcemap: 'inline' as const
9+
sourcemap: true
1010
}
1111
}))

packages/e2e/react/cypress.config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from 'e2e-shared/cypress.config'
2+
3+
export default defineConfig({
4+
baseUrl: 'http://localhost:3002'
5+
})

packages/e2e/react/cypress/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
e2e/examples/
2+
plugins/
3+
screenshots/
4+
videos/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { testBasicIO } from 'e2e-shared/specs/basic-io.cy'
2+
3+
testBasicIO({
4+
hook: 'useQueryState',
5+
path: '/basic-io/useQueryState'
6+
})
7+
8+
testBasicIO({
9+
hook: 'useQueryStates',
10+
path: '/basic-io/useQueryStates'
11+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { testHashPreservation } from 'e2e-shared/specs/hash-preservation.cy'
2+
3+
testHashPreservation({
4+
path: '/hash-preservation'
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { testPush } from 'e2e-shared/specs/push.cy'
2+
3+
testPush({
4+
path: '/push/useQueryState',
5+
hook: 'useQueryState'
6+
})
7+
8+
testPush({
9+
path: '/push/useQueryStates',
10+
hook: 'useQueryStates'
11+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'e2e-shared/cypress/support/e2e'

packages/e2e/react/package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite --port 3002",
8-
"build": "tsc -b && vite build",
9-
"preview": "vite preview",
10-
"test": "pnpm run '/^test:/'",
11-
"test:unit": "vitest",
12-
"test:e2e": "echo 'todo: Implement e2e tests'"
8+
"build": "vite build",
9+
"start": "vite preview --port 3002",
10+
"test": "pnpm run --stream '/^test:/'",
11+
"test:types": "tsc -b",
12+
"test:e2e": "start-server-and-test start http://localhost:3002 cypress:run",
13+
"cypress:open": "cypress open",
14+
"cypress:run": "cross-env FORCE_COLOR=3 cypress run --headless"
1315
},
1416
"dependencies": {
1517
"nuqs": "workspace:*",
1618
"react": "catalog:react19",
1719
"react-dom": "catalog:react19"
1820
},
1921
"devDependencies": {
20-
"@testing-library/dom": "^10.4.0",
21-
"@testing-library/jest-dom": "^6.6.3",
22-
"@testing-library/react": "^16.0.1",
23-
"@testing-library/user-event": "^14.5.2",
2422
"@types/node": "^22.9.0",
2523
"@types/react": "catalog:react19",
2624
"@types/react-dom": "catalog:react19",
2725
"@vitejs/plugin-react": "^4.3.3",
28-
"globals": "^15.12.0",
29-
"jsdom": "^25.0.1",
26+
"cross-env": "^7.0.3",
27+
"cypress": "catalog:e2e",
28+
"e2e-shared": "workspace:*",
29+
"start-server-and-test": "catalog:e2e",
3030
"typescript": "^5.6.3",
3131
"vite": "^5.4.11",
3232
"vitest": "^2.1.5"

packages/e2e/react/src/components/counter-button.test.tsx

-34
This file was deleted.

packages/e2e/react/src/components/counter-button.tsx

-9
This file was deleted.

packages/e2e/react/src/components/search-input.test.tsx

-38
This file was deleted.

packages/e2e/react/src/components/search-input.tsx

-15
This file was deleted.

packages/e2e/react/src/main.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { NuqsAdapter } from 'nuqs/adapters/next'
1+
import { HydrationMarker } from 'e2e-shared/components/hydration-marker'
2+
import { NuqsAdapter } from 'nuqs/adapters/react'
23
import { StrictMode } from 'react'
34
import { createRoot } from 'react-dom/client'
4-
import { CounterButton } from './components/counter-button'
5-
import { SearchInput } from './components/search-input'
5+
import { Router } from './routes'
66

77
createRoot(document.getElementById('root')!).render(
88
<StrictMode>
9+
<HydrationMarker />
910
<NuqsAdapter>
10-
<CounterButton />
11-
<SearchInput />
11+
<Router />
1212
</NuqsAdapter>
1313
</StrictMode>
1414
)

packages/e2e/react/src/routes.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { JSX, lazy } from 'react'
2+
3+
// prettier-ignore
4+
const routes: Record<string, React.LazyExoticComponent<() => JSX.Element>> = {
5+
'/hash-preservation': lazy(() => import('./routes/hash-preservation')),
6+
'/basic-io/useQueryState': lazy(() => import('./routes/basic-io.useQueryState')),
7+
'/basic-io/useQueryStates': lazy(() => import('./routes/basic-io.useQueryStates')),
8+
'/push/useQueryState': lazy(() => import('./routes/push.useQueryState')),
9+
'/push/useQueryStates': lazy(() => import('./routes/push.useQueryStates')),
10+
}
11+
12+
export function Router() {
13+
const Route = routes[location.pathname]
14+
if (!Route) {
15+
return <>404 not found</>
16+
}
17+
return <Route />
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { UseQueryStateBasicIO } from 'e2e-shared/specs/basic-io'
2+
3+
export default UseQueryStateBasicIO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { UseQueryStatesBasicIO } from 'e2e-shared/specs/basic-io'
2+
3+
export default UseQueryStatesBasicIO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { HashPreservation } from 'e2e-shared/specs/hash-preservation'
2+
3+
export default HashPreservation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { PushUseQueryState } from 'e2e-shared/specs/push'
2+
3+
export default PushUseQueryState
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { PushUseQueryStates } from 'e2e-shared/specs/push'
2+
3+
export default PushUseQueryStates

packages/e2e/react/tsconfig.app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"target": "ES2020",
44
"useDefineForClassFields": true,
55
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6-
"types": ["node", "@testing-library/jest-dom"],
6+
"types": ["node"],
77
"module": "ESNext",
88
"skipLibCheck": true,
99

packages/e2e/react/tsconfig.json

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
{
22
"files": [],
3+
"compilerOptions": {
4+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
5+
"types": ["node", "vite/client"],
6+
"target": "ES2022",
7+
"module": "ES2022",
8+
"moduleResolution": "bundler",
9+
"jsx": "react-jsx",
10+
"baseUrl": ".",
11+
"esModuleInterop": true,
12+
"verbatimModuleSyntax": true,
13+
"noEmit": true,
14+
"resolveJsonModule": true,
15+
"skipLibCheck": true,
16+
"strict": true
17+
},
318
"references": [
419
{ "path": "./tsconfig.app.json" },
520
{ "path": "./tsconfig.node.json" }

packages/e2e/react/tsconfig.node.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2022",
44
"lib": ["ES2023"],
5-
"types": ["node", "@testing-library/jest-dom"],
5+
"types": ["node"],
66
"module": "ESNext",
77
"skipLibCheck": true,
88

packages/e2e/react/vite.config.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ import { defineConfig } from 'vite'
44
// https://vitejs.dev/config/
55
export default defineConfig(() => ({
66
plugins: [react()],
7-
// Vitest configuration
8-
test: {
9-
globals: true,
10-
environment: 'jsdom',
11-
setupFiles: ['vitest.setup.ts'],
12-
include: ['**/*.test.?(c|m)[jt]s?(x)'],
13-
env: {
14-
IS_REACT_ACT_ENVIRONMENT: 'true'
15-
}
7+
build: {
8+
target: 'es2022',
9+
sourcemap: true
1610
}
1711
}))

packages/e2e/react/vitest.setup.ts

-8
This file was deleted.

0 commit comments

Comments
 (0)