Skip to content

Commit 51d55d3

Browse files
authored
test: remove runInBuild flag from withRetry (#18698)
1 parent 8ab04b7 commit 51d55d3

File tree

6 files changed

+27
-31
lines changed

6 files changed

+27
-31
lines changed

playground/cli/__tests__/cli.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from 'vitest'
22
import { port, streams } from './serve'
3-
import { editFile, page, withRetry } from '~utils'
3+
import { editFile, isServe, page, withRetry } from '~utils'
44

55
test('cli should work', async () => {
66
// this test uses a custom serve implementation, so regular helpers for browserLogs and goto don't work
@@ -20,7 +20,7 @@ test('cli should work', async () => {
2020
}
2121
})
2222

23-
test('should restart', async () => {
23+
test.runIf(isServe)('should restart', async () => {
2424
const logsLengthBeforeEdit = streams.server.out.length
2525
editFile('./vite.config.js', (content) => content)
2626
await withRetry(async () => {

playground/css/__tests__/css.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,13 @@ test('async css order', async () => {
528528
await withRetry(async () => {
529529
expect(await getColor('.async-green')).toMatchInlineSnapshot('"green"')
530530
expect(await getColor('.async-blue')).toMatchInlineSnapshot('"blue"')
531-
}, true)
531+
})
532532
})
533533

534534
test('async css order with css modules', async () => {
535535
await withRetry(async () => {
536536
expect(await getColor('.modules-pink')).toMatchInlineSnapshot('"pink"')
537-
}, true)
537+
})
538538
})
539539

540540
test('@import scss', async () => {

playground/glob-import/__tests__/glob-import.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ test('should work', async () => {
8787
await withRetry(async () => {
8888
const actual = await page.textContent('.result')
8989
expect(JSON.parse(actual)).toStrictEqual(allResult)
90-
}, true)
90+
})
9191
await withRetry(async () => {
9292
const actualEager = await page.textContent('.result-eager')
9393
expect(JSON.parse(actualEager)).toStrictEqual(allResult)
94-
}, true)
94+
})
9595
await withRetry(async () => {
9696
const actualNodeModules = await page.textContent('.result-node_modules')
9797
expect(JSON.parse(actualNodeModules)).toStrictEqual(nodeModulesResult)
98-
}, true)
98+
})
9999
})
100100

101101
test('import glob raw', async () => {
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from 'vitest'
22
import { port } from './serve'
3-
import { page, withRetry } from '~utils'
3+
import { isServe, page, withRetry } from '~utils'
44

55
const url = `http://localhost:${port}`
66

@@ -16,16 +16,19 @@ test('ssr.resolve.externalConditions affect externalized imports during ssr', as
1616
expect(await page.textContent('.external-react-server')).toMatch('edge.js')
1717
})
1818

19-
test('ssr.resolve settings do not affect non-ssr imports', async () => {
20-
await page.goto(url)
21-
await withRetry(async () => {
22-
expect(await page.textContent('.browser-no-external-react-server')).toMatch(
23-
'default.js',
24-
)
25-
})
26-
await withRetry(async () => {
27-
expect(await page.textContent('.browser-external-react-server')).toMatch(
28-
'default.js',
29-
)
30-
})
31-
})
19+
test.runIf(isServe)(
20+
'ssr.resolve settings do not affect non-ssr imports',
21+
async () => {
22+
await page.goto(url)
23+
await withRetry(async () => {
24+
expect(
25+
await page.textContent('.browser-no-external-react-server'),
26+
).toMatch('default.js')
27+
})
28+
await withRetry(async () => {
29+
expect(await page.textContent('.browser-external-react-server')).toMatch(
30+
'default.js',
31+
)
32+
})
33+
},
34+
)

playground/ssr/__tests__/ssr.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test.runIf(isServe)('html proxy is encoded', async () => {
4545
})
4646

4747
// run this at the end to reduce flakiness
48-
test('should restart ssr', async () => {
48+
test.runIf(isServe)('should restart ssr', async () => {
4949
editFile('./vite.config.ts', (content) => content)
5050
await withRetry(async () => {
5151
expect(serverLogs).toEqual(

playground/test-utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ export async function untilUpdated(
241241
/**
242242
* Retry `func` until it does not throw error.
243243
*/
244-
export async function withRetry(
245-
func: () => Promise<void>,
246-
runInBuild = false,
247-
): Promise<void> {
248-
if (isBuild && !runInBuild) return
244+
export async function withRetry(func: () => Promise<void>): Promise<void> {
249245
const maxTries = process.env.CI ? 200 : 50
250246
for (let tries = 0; tries < maxTries; tries++) {
251247
try {
@@ -263,10 +259,7 @@ export const expectWithRetry = <T>(getActual: () => Promise<T>) => {
263259
{
264260
get(_target, key) {
265261
return async (...args) => {
266-
await withRetry(
267-
async () => expect(await getActual())[key](...args),
268-
true,
269-
)
262+
await withRetry(async () => expect(await getActual())[key](...args))
270263
}
271264
},
272265
},

0 commit comments

Comments
 (0)