Skip to content

Commit db1774b

Browse files
test(react-start): make basic-tsr-config test more strict (#3611)
make basic-tsr-config test more strict: - #3597 --------- Co-authored-by: Sean Cassiere <[email protected]>
1 parent a119869 commit db1774b

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

e2e/react-start/basic-tsr-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "vinxi dev --port 3000",
88
"dev:e2e": "vinxi dev",
9-
"build": "vinxi build && tsc --noEmit",
9+
"build": "rimraf ./count.txt && vinxi build && tsc --noEmit",
1010
"start": "vinxi start",
1111
"test:e2e": "playwright test --project=chromium"
1212
},

e2e/react-start/basic-tsr-config/src/app/routes/index.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import fs from 'node:fs'
12
import { createFileRoute, useRouter } from '@tanstack/react-router'
23
import { createServerFn } from '@tanstack/react-start'
34

4-
let count = 0
5+
const filePath = 'count.txt'
56

6-
const getCount = createServerFn({ method: 'GET' }).handler(() => {
7-
return count
7+
const getCount = createServerFn({
8+
method: 'GET',
9+
}).handler(async () => {
10+
const number = await fs.promises.readFile(filePath, 'utf-8').catch(() => '0')
11+
return parseInt(number || '0')
812
})
913

1014
const updateCount = createServerFn({ method: 'POST' })
11-
.validator((addBy: number) => addBy)
12-
.handler(({ data: addBy }) => {
13-
count += addBy
15+
.validator((d: number) => d)
16+
.handler(async ({ data }) => {
17+
const count = await getCount()
18+
await fs.promises.writeFile(filePath, `${count + data}`)
1419
})
15-
1620
export const Route = createFileRoute('/')({
1721
component: Home,
1822
loader: async () => await getCount(),
@@ -24,6 +28,7 @@ function Home() {
2428

2529
return (
2630
<button
31+
data-testid="add-button"
2732
onClick={() => {
2833
updateCount({ data: 1 }).then(() => {
2934
router.invalidate()

e2e/react-start/basic-tsr-config/tests/app.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { expect, test } from '@playwright/test'
33
test('opening the app', async ({ page }) => {
44
await page.goto('/')
55

6-
await expect(page.getByText('Add 1 to 0?')).toBeTruthy()
7-
await page.click('button')
8-
await expect(page.getByText('Add 1 to 1?')).toBeTruthy()
6+
await expect(page.getByTestId('add-button')).toContainText('Add 1 to 0?')
7+
await page.getByTestId('add-button').click()
8+
await page.waitForLoadState('networkidle')
9+
await expect(page.getByTestId('add-button')).toContainText('Add 1 to 1?')
910
})

0 commit comments

Comments
 (0)