Skip to content

Commit 7e1c594

Browse files
chore: stabilize tests
1 parent c79b396 commit 7e1c594

6 files changed

Lines changed: 114 additions & 53 deletions

File tree

‎e2e/react-start/basic/src/routes/__root.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/// <reference types="vite/client" />
22
import * as React from 'react'
33
import {
4+
ClientOnly,
45
HeadContent,
56
Link,
67
Outlet,
78
Scripts,
89
createRootRoute,
10+
useRouterState,
911
} from '@tanstack/react-router'
1012

1113
import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
@@ -92,6 +94,11 @@ const RouterDevtools =
9294
)
9395

9496
function RootDocument({ children }: { children: React.ReactNode }) {
97+
const { isLoading, status } = useRouterState({
98+
select: (state) => ({ isLoading: state.isLoading, status: state.status }),
99+
structuralSharing: true,
100+
})
101+
95102
return (
96103
<html>
97104
<head>
@@ -209,6 +216,12 @@ function RootDocument({ children }: { children: React.ReactNode }) {
209216
</Link>
210217
</div>
211218
<hr />
219+
<ClientOnly>
220+
<div hidden>
221+
<b data-testid="router-isLoading">{isLoading ? 'true' : 'false'}</b>
222+
<b data-testid="router-status">{status}</b>
223+
</div>
224+
</ClientOnly>
212225
{children}
213226
<div className="inline-div">This is an inline styled div</div>
214227
<React.Suspense fallback={null}>

‎e2e/react-start/basic/tests/redirect.spec.ts‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import queryString from 'node:querystring'
2-
import { expect } from '@playwright/test'
2+
import { expect, type Page } from '@playwright/test'
33
import combinateImport from 'combinate'
44
import {
55
getDummyServerPort,
@@ -15,6 +15,19 @@ const e2ePortKey = getE2EPortKey()
1515
const PORT = await getTestServerPort(e2ePortKey)
1616

1717
const EXTERNAL_HOST_PORT = await getDummyServerPort(e2ePortKey)
18+
const POSTS_URL = `http://localhost:${PORT}/posts`
19+
20+
async function waitForRouterIdle(page: Page) {
21+
await expect(page.getByTestId('router-isLoading')).toHaveText('false')
22+
await expect(page.getByTestId('router-status')).toHaveText('idle')
23+
}
24+
25+
async function waitForPostsIndex(page: Page) {
26+
await page.waitForURL(POSTS_URL)
27+
expect(page.url()).toBe(POSTS_URL)
28+
await waitForRouterIdle(page)
29+
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
30+
}
1831

1932
test.describe('redirects', () => {
2033
test.describe('internal', () => {
@@ -37,7 +50,7 @@ test.describe('redirects', () => {
3750
`via-${thrower}${reloadDocument ? '-reloadDocument' : ''}`,
3851
)
3952

40-
await page.waitForLoadState('networkidle')
53+
await waitForRouterIdle(page)
4154
let requestHappened = false
4255

4356
const requestPromise = new Promise<void>((resolve) => {
@@ -65,10 +78,7 @@ test.describe('redirects', () => {
6578

6679
await link.click()
6780

68-
const url = `http://localhost:${PORT}/posts`
69-
await page.waitForURL(url)
70-
expect(page.url()).toBe(url)
71-
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
81+
await waitForPostsIndex(page)
7282
expect(fullPageLoad).toBe(reloadDocument)
7383
})
7484
},
@@ -84,12 +94,8 @@ test.describe('redirects', () => {
8494
page,
8595
}) => {
8696
await page.goto(`/redirect/internal/via-${thrower}`)
87-
await page.waitForLoadState('networkidle')
88-
89-
const url = `http://localhost:${PORT}/posts`
9097

91-
expect(page.url()).toBe(url)
92-
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
98+
await waitForPostsIndex(page)
9399
})
94100
})
95101
})
@@ -110,7 +116,7 @@ test.describe('redirects', () => {
110116

111117
if (scenario === 'navigate') {
112118
await page.goto(`/redirect/external?${q}`)
113-
await page.waitForLoadState('networkidle')
119+
await waitForRouterIdle(page)
114120
const link = page.getByTestId(`via-${thrower}`)
115121
await link.focus()
116122
await link.click()
@@ -147,7 +153,7 @@ test.describe('redirects', () => {
147153

148154
if (scenario === 'navigate') {
149155
await page.goto(`/redirect/${target}/serverFn?${q}`)
150-
await page.waitForLoadState('networkidle')
156+
await waitForRouterIdle(page)
151157

152158
const link = page.getByTestId(
153159
`via-${thrower}${reloadDocument ? '-reloadDocument' : ''}`,
@@ -158,22 +164,23 @@ test.describe('redirects', () => {
158164
})
159165

160166
await link.focus()
161-
await page.waitForLoadState('networkidle')
167+
await waitForRouterIdle(page)
162168
await link.click()
163169
} else {
164170
await page.goto(`/redirect/${target}/serverFn/via-${thrower}?${q}`)
165171
}
166172

167173
const url =
168174
target === 'internal'
169-
? `http://localhost:${PORT}/posts`
175+
? POSTS_URL
170176
: `http://localhost:${EXTERNAL_HOST_PORT}/`
171177

172178
await page.waitForURL(url)
173179

174180
expect(page.url()).toBe(url)
175181

176182
if (target === 'internal' && scenario === 'navigate') {
183+
await waitForRouterIdle(page)
177184
await expect(
178185
page.getByTestId('PostsIndexComponent'),
179186
).toBeInViewport()
@@ -201,7 +208,7 @@ test.describe('redirects', () => {
201208

202209
await page.goto(`/redirect/${target}/serverFn/via-useServerFn?${q}`)
203210

204-
await page.waitForLoadState('networkidle')
211+
await waitForRouterIdle(page)
205212

206213
const button = page.getByTestId('redirect-on-click')
207214

@@ -214,11 +221,12 @@ test.describe('redirects', () => {
214221

215222
const url =
216223
target === 'internal'
217-
? `http://localhost:${PORT}/posts`
224+
? POSTS_URL
218225
: `http://localhost:${EXTERNAL_HOST_PORT}/`
219226
await page.waitForURL(url)
220227
expect(page.url()).toBe(url)
221228
if (target === 'internal') {
229+
await waitForRouterIdle(page)
222230
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
223231
expect(fullPageLoad).toBe(reloadDocument)
224232
}

‎e2e/solid-start/basic/src/routes/__root.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/// <reference types="vite/client" />
22
import {
3+
ClientOnly,
34
HeadContent,
45
Link,
56
Outlet,
67
Scripts,
78
createRootRoute,
9+
useRouterState,
810
} from '@tanstack/solid-router'
911

1012
import { TanStackRouterDevtoolsInProd } from '@tanstack/solid-router-devtools'
@@ -65,6 +67,10 @@ export const Route = createRootRoute({
6567
})
6668

6769
function RootComponent() {
70+
const routerState = useRouterState({
71+
select: (state) => ({ isLoading: state.isLoading, status: state.status }),
72+
})
73+
6874
return (
6975
<html>
7076
<head>
@@ -156,6 +162,14 @@ function RootComponent() {
156162
This Route Does Not Exist
157163
</Link>
158164
</div>
165+
<ClientOnly>
166+
<div hidden>
167+
<b data-testid="router-isLoading">
168+
{routerState().isLoading ? 'true' : 'false'}
169+
</b>
170+
<b data-testid="router-status">{routerState().status}</b>
171+
</div>
172+
</ClientOnly>
159173
<Outlet />
160174
<div class="inline-div">This is an inline styled div</div>
161175
<TanStackRouterDevtoolsInProd />

‎e2e/solid-start/basic/tests/redirect.spec.ts‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import queryString from 'node:querystring'
2-
import { expect } from '@playwright/test'
2+
import { expect, type Page } from '@playwright/test'
33
import combinateImport from 'combinate'
44
import {
55
getDummyServerPort,
@@ -14,6 +14,19 @@ const combinate = (combinateImport as any).default as typeof combinateImport
1414
const e2ePortKey = getE2EPortKey()
1515
const PORT = await getTestServerPort(e2ePortKey)
1616
const EXTERNAL_HOST_PORT = await getDummyServerPort(e2ePortKey)
17+
const POSTS_URL = `http://localhost:${PORT}/posts`
18+
19+
async function waitForRouterIdle(page: Page) {
20+
await expect(page.getByTestId('router-isLoading')).toHaveText('false')
21+
await expect(page.getByTestId('router-status')).toHaveText('idle')
22+
}
23+
24+
async function waitForPostsIndex(page: Page) {
25+
await page.waitForURL(POSTS_URL)
26+
expect(page.url()).toBe(POSTS_URL)
27+
await waitForRouterIdle(page)
28+
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
29+
}
1730

1831
test.describe('redirects', () => {
1932
const internalNavigationTestMatrix = combinate({
@@ -34,7 +47,7 @@ test.describe('redirects', () => {
3447
`via-${thrower}${reloadDocument ? '-reloadDocument' : ''}`,
3548
)
3649

37-
await page.waitForLoadState('networkidle')
50+
await waitForRouterIdle(page)
3851
let requestHappened = false
3952

4053
const requestPromise = new Promise<void>((resolve) => {
@@ -62,11 +75,7 @@ test.describe('redirects', () => {
6275

6376
await link.click()
6477

65-
const url = `http://localhost:${PORT}/posts`
66-
67-
await page.waitForURL(url)
68-
expect(page.url()).toBe(url)
69-
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
78+
await waitForPostsIndex(page)
7079
expect(fullPageLoad).toBe(reloadDocument)
7180
})
7281
},
@@ -83,12 +92,7 @@ test.describe('redirects', () => {
8392
}) => {
8493
await page.goto(`/redirect/internal/via-${thrower}`)
8594

86-
const url = `http://localhost:${PORT}/posts`
87-
88-
await page.waitForURL(url)
89-
expect(page.url()).toBe(url)
90-
await page.waitForLoadState('networkidle')
91-
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
95+
await waitForPostsIndex(page)
9296
})
9397
})
9498

@@ -107,7 +111,7 @@ test.describe('redirects', () => {
107111

108112
if (scenario === 'navigate') {
109113
await page.goto(`/redirect/external?${q}`)
110-
await page.waitForLoadState('networkidle')
114+
await waitForRouterIdle(page)
111115
const link = page.getByTestId(`via-${thrower}`)
112116
await link.focus()
113117
await link.click()
@@ -142,7 +146,7 @@ test.describe('redirects', () => {
142146

143147
if (scenario === 'navigate') {
144148
await page.goto(`/redirect/${target}/serverFn?${q}`)
145-
await page.waitForLoadState('networkidle')
149+
await waitForRouterIdle(page)
146150
const link = page.getByTestId(
147151
`via-${thrower}${reloadDocument ? '-reloadDocument' : ''}`,
148152
)
@@ -157,11 +161,12 @@ test.describe('redirects', () => {
157161

158162
const url =
159163
target === 'internal'
160-
? `http://localhost:${PORT}/posts`
164+
? POSTS_URL
161165
: `http://localhost:${EXTERNAL_HOST_PORT}/`
162166
await page.waitForURL(url)
163167
expect(page.url()).toBe(url)
164168
if (target === 'internal' && scenario === 'navigate') {
169+
await waitForRouterIdle(page)
165170
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
166171
expect(fullPageLoad).toBe(reloadDocument)
167172
}
@@ -185,7 +190,7 @@ test.describe('redirects', () => {
185190

186191
await page.goto(`/redirect/${target}/serverFn/via-useServerFn?${q}`)
187192

188-
await page.waitForLoadState('networkidle')
193+
await waitForRouterIdle(page)
189194

190195
const button = page.getByTestId('redirect-on-click')
191196

@@ -198,11 +203,12 @@ test.describe('redirects', () => {
198203

199204
const url =
200205
target === 'internal'
201-
? `http://localhost:${PORT}/posts`
206+
? POSTS_URL
202207
: `http://localhost:${EXTERNAL_HOST_PORT}/`
203208
await page.waitForURL(url)
204209
expect(page.url()).toBe(url)
205210
if (target === 'internal') {
211+
await waitForRouterIdle(page)
206212
await expect(page.getByTestId('PostsIndexComponent')).toBeInViewport()
207213
expect(fullPageLoad).toBe(reloadDocument)
208214
}

‎e2e/vue-start/basic/src/routes/__root.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/// <reference types="vite/client" />
22
import {
33
Body,
4+
ClientOnly,
45
HeadContent,
56
Html,
67
Link,
78
Outlet,
89
Scripts,
910
createRootRoute,
11+
useRouterState,
1012
} from '@tanstack/vue-router'
1113

1214
import { TanStackRouterDevtoolsInProd } from '@tanstack/vue-router-devtools'
@@ -66,6 +68,10 @@ export const Route = createRootRoute({
6668
})
6769

6870
function RootComponent() {
71+
const routerState = useRouterState({
72+
select: (state) => ({ isLoading: state.isLoading, status: state.status }),
73+
})
74+
6975
return (
7076
<Html>
7177
<head>
@@ -156,6 +162,14 @@ function RootComponent() {
156162
This Route Does Not Exist
157163
</Link>
158164
</div>
165+
<ClientOnly>
166+
<div hidden>
167+
<b data-testid="router-isLoading">
168+
{routerState.value.isLoading ? 'true' : 'false'}
169+
</b>
170+
<b data-testid="router-status">{routerState.value.status}</b>
171+
</div>
172+
</ClientOnly>
159173
<Outlet />
160174
<div class="inline-div">This is an inline styled div</div>
161175
<TanStackRouterDevtoolsInProd />

0 commit comments

Comments
 (0)