Skip to content

Commit ad9e001

Browse files
authored
test: remove runInBuild flag from editFile and untilUpdated (#395)
1 parent 2e368a6 commit ad9e001

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

playground/react-classic/__tests__/react.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('should update', async () => {
1111
expect(await page.textContent('button')).toMatch('count is: 1')
1212
})
1313

14-
test('should hmr', async () => {
14+
test.runIf(isServe)('should hmr', async () => {
1515
editFile('App.jsx', (code) => code.replace('Vite + React', 'Updated'))
1616
await untilUpdated(() => page.textContent('h1'), 'Hello Updated')
1717
// preserve state

playground/react-emotion/__tests__/react.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from 'vitest'
2-
import { editFile, getColor, page, untilUpdated } from '~utils'
2+
import { editFile, getColor, isServe, page, untilUpdated } from '~utils'
33

44
test('should render', async () => {
55
expect(await page.textContent('h1')).toMatch(
@@ -13,7 +13,7 @@ test('should update', async () => {
1313
expect(await page.textContent('button')).toMatch('count is: 1')
1414
})
1515

16-
test('should hmr', async () => {
16+
test.runIf(isServe)('should hmr', async () => {
1717
editFile('App.jsx', (code) =>
1818
code.replace('Vite + React + @emotion/react', 'Updated'),
1919
)
@@ -42,12 +42,14 @@ test('should update button style', async () => {
4242

4343
expect(await getButtonBorderStyle()).toMatch('2px solid rgb(0, 0, 0)')
4444

45-
editFile('Counter.jsx', (code) =>
46-
code.replace('border: 2px solid #000', 'border: 4px solid red'),
47-
)
45+
if (isServe) {
46+
editFile('Counter.jsx', (code) =>
47+
code.replace('border: 2px solid #000', 'border: 4px solid red'),
48+
)
4849

49-
await untilUpdated(getButtonBorderStyle, '4px solid rgb(255, 0, 0)')
50+
await untilUpdated(getButtonBorderStyle, '4px solid rgb(255, 0, 0)')
5051

51-
// preserve state
52-
expect(await page.textContent('button')).toMatch('count is: 1')
52+
// preserve state
53+
expect(await page.textContent('button')).toMatch('count is: 1')
54+
}
5355
})

playground/react/__tests__/react.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test('should update', async () => {
1818
expect(await page.textContent('#state-button')).toMatch('count is: 1')
1919
})
2020

21-
test('should hmr', async () => {
21+
test.runIf(isServe)('should hmr', async () => {
2222
editFile('App.jsx', (code) =>
2323
code.replace('Vite + React', 'Vite + React Updated'),
2424
)

playground/ssr-react/__tests__/ssr-react.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ test('client navigation', async () => {
7070
await untilUpdated(() => page.textContent('a[href="/about"]'), 'About')
7171
await page.click('a[href="/about"]')
7272
await untilUpdated(() => page.textContent('h1'), 'About')
73-
editFile('src/pages/About.jsx', (code) =>
74-
code.replace('<h1>About', '<h1>changed'),
75-
)
76-
await untilUpdated(() => page.textContent('h1'), 'changed')
73+
74+
if (!isBuild) {
75+
editFile('src/pages/About.jsx', (code) =>
76+
code.replace('<h1>About', '<h1>changed'),
77+
)
78+
await untilUpdated(() => page.textContent('h1'), 'changed')
79+
}
7780
})

playground/test-utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fs from 'node:fs'
55
import path from 'node:path'
66
import type { ConsoleMessage, ElementHandle } from 'playwright-chromium'
77
import { expect } from 'vitest'
8-
import { isBuild, page, testDir } from './vitestSetup'
8+
import { page, testDir } from './vitestSetup'
99

1010
export * from './vitestSetup'
1111

@@ -69,9 +69,7 @@ export function readFile(filename: string): string {
6969
export function editFile(
7070
filename: string,
7171
replacer: (str: string) => string,
72-
runInBuild: boolean = false,
7372
): void {
74-
if (isBuild && !runInBuild) return
7573
filename = path.resolve(testDir, filename)
7674
const content = fs.readFileSync(filename, 'utf-8')
7775
const modified = replacer(content)
@@ -92,9 +90,7 @@ export function removeFile(filename: string): void {
9290
export async function untilUpdated(
9391
poll: () => string | Promise<string>,
9492
expected: string,
95-
runInBuild = false,
9693
): Promise<void> {
97-
if (isBuild && !runInBuild) return
9894
const maxTries = process.env.CI ? 100 : 50
9995
for (let tries = 0; tries < maxTries; tries++) {
10096
const actual = (await poll()) ?? ''

0 commit comments

Comments
 (0)