Skip to content

Commit

Permalink
test: Add React tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Dec 15, 2024
1 parent 516b2cb commit 869ca26
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 166 deletions.
2 changes: 1 addition & 1 deletion packages/e2e/react-router/v6/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default defineConfig(() => ({
plugins: [react()],
build: {
target: 'es2022',
sourcemap: 'inline' as const
sourcemap: true
}
}))
5 changes: 5 additions & 0 deletions packages/e2e/react/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'e2e-shared/cypress.config'

export default defineConfig({
baseUrl: 'http://localhost:3002'
})
4 changes: 4 additions & 0 deletions packages/e2e/react/cypress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
e2e/examples/
plugins/
screenshots/
videos/
11 changes: 11 additions & 0 deletions packages/e2e/react/cypress/e2e/shared/basic-io.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { testBasicIO } from 'e2e-shared/specs/basic-io.cy'

testBasicIO({
hook: 'useQueryState',
path: '/basic-io/useQueryState'
})

testBasicIO({
hook: 'useQueryStates',
path: '/basic-io/useQueryStates'
})
5 changes: 5 additions & 0 deletions packages/e2e/react/cypress/e2e/shared/hash-preservation.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testHashPreservation } from 'e2e-shared/specs/hash-preservation.cy'

testHashPreservation({
path: '/hash-preservation'
})
11 changes: 11 additions & 0 deletions packages/e2e/react/cypress/e2e/shared/push.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { testPush } from 'e2e-shared/specs/push.cy'

testPush({
path: '/push/useQueryState',
hook: 'useQueryState'
})

testPush({
path: '/push/useQueryStates',
hook: 'useQueryStates'
})
1 change: 1 addition & 0 deletions packages/e2e/react/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'e2e-shared/cypress/support/e2e'
22 changes: 11 additions & 11 deletions packages/e2e/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
"type": "module",
"scripts": {
"dev": "vite --port 3002",
"build": "tsc -b && vite build",
"preview": "vite preview",
"test": "pnpm run '/^test:/'",
"test:unit": "vitest",
"test:e2e": "echo 'todo: Implement e2e tests'"
"build": "vite build",
"start": "vite preview --port 3002",
"test": "pnpm run --stream '/^test:/'",
"test:types": "tsc -b",
"test:e2e": "start-server-and-test start http://localhost:3002 cypress:run",
"cypress:open": "cypress open",
"cypress:run": "cross-env FORCE_COLOR=3 cypress run --headless"
},
"dependencies": {
"nuqs": "workspace:*",
"react": "catalog:react19",
"react-dom": "catalog:react19"
},
"devDependencies": {
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^22.9.0",
"@types/react": "catalog:react19",
"@types/react-dom": "catalog:react19",
"@vitejs/plugin-react": "^4.3.3",
"globals": "^15.12.0",
"jsdom": "^25.0.1",
"cross-env": "^7.0.3",
"cypress": "catalog:e2e",
"e2e-shared": "workspace:*",
"start-server-and-test": "catalog:e2e",
"typescript": "^5.6.3",
"vite": "^5.4.11",
"vitest": "^2.1.5"
Expand Down
34 changes: 0 additions & 34 deletions packages/e2e/react/src/components/counter-button.test.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions packages/e2e/react/src/components/counter-button.tsx

This file was deleted.

38 changes: 0 additions & 38 deletions packages/e2e/react/src/components/search-input.test.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions packages/e2e/react/src/components/search-input.tsx

This file was deleted.

10 changes: 5 additions & 5 deletions packages/e2e/react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NuqsAdapter } from 'nuqs/adapters/next'
import { HydrationMarker } from 'e2e-shared/components/hydration-marker'
import { NuqsAdapter } from 'nuqs/adapters/react'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { CounterButton } from './components/counter-button'
import { SearchInput } from './components/search-input'
import { Router } from './routes'

createRoot(document.getElementById('root')!).render(
<StrictMode>
<HydrationMarker />
<NuqsAdapter>
<CounterButton />
<SearchInput />
<Router />
</NuqsAdapter>
</StrictMode>
)
18 changes: 18 additions & 0 deletions packages/e2e/react/src/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { JSX, lazy } from 'react'

// prettier-ignore
const routes: Record<string, React.LazyExoticComponent<() => JSX.Element>> = {
'/hash-preservation': lazy(() => import('./routes/hash-preservation')),
'/basic-io/useQueryState': lazy(() => import('./routes/basic-io.useQueryState')),
'/basic-io/useQueryStates': lazy(() => import('./routes/basic-io.useQueryStates')),
'/push/useQueryState': lazy(() => import('./routes/push.useQueryState')),
'/push/useQueryStates': lazy(() => import('./routes/push.useQueryStates')),
}

export function Router() {
const Route = routes[location.pathname]
if (!Route) {
return <>404 not found</>
}
return <Route />
}
3 changes: 3 additions & 0 deletions packages/e2e/react/src/routes/basic-io.useQueryState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { UseQueryStateBasicIO } from 'e2e-shared/specs/basic-io'

export default UseQueryStateBasicIO
3 changes: 3 additions & 0 deletions packages/e2e/react/src/routes/basic-io.useQueryStates.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { UseQueryStatesBasicIO } from 'e2e-shared/specs/basic-io'

export default UseQueryStatesBasicIO
3 changes: 3 additions & 0 deletions packages/e2e/react/src/routes/hash-preservation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { HashPreservation } from 'e2e-shared/specs/hash-preservation'

export default HashPreservation
3 changes: 3 additions & 0 deletions packages/e2e/react/src/routes/push.useQueryState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PushUseQueryState } from 'e2e-shared/specs/push'

export default PushUseQueryState
3 changes: 3 additions & 0 deletions packages/e2e/react/src/routes/push.useQueryStates.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PushUseQueryStates } from 'e2e-shared/specs/push'

export default PushUseQueryStates
2 changes: 1 addition & 1 deletion packages/e2e/react/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"types": ["node", "@testing-library/jest-dom"],
"types": ["node"],
"module": "ESNext",
"skipLibCheck": true,

Expand Down
15 changes: 15 additions & 0 deletions packages/e2e/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
{
"files": [],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["node", "vite/client"],
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"baseUrl": ".",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true
},
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/react/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"types": ["node", "@testing-library/jest-dom"],
"types": ["node"],
"module": "ESNext",
"skipLibCheck": true,

Expand Down
12 changes: 3 additions & 9 deletions packages/e2e/react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ import { defineConfig } from 'vite'
// https://vitejs.dev/config/
export default defineConfig(() => ({
plugins: [react()],
// Vitest configuration
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['vitest.setup.ts'],
include: ['**/*.test.?(c|m)[jt]s?(x)'],
env: {
IS_REACT_ACT_ENVIRONMENT: 'true'
}
build: {
target: 'es2022',
sourcemap: true
}
}))
8 changes: 0 additions & 8 deletions packages/e2e/react/vitest.setup.ts

This file was deleted.

Loading

0 comments on commit 869ca26

Please sign in to comment.