Skip to content

Commit

Permalink
test: remove runInBuild flag from withRetry (#18698)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Nov 19, 2024
1 parent 8ab04b7 commit 51d55d3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions playground/cli/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'
import { port, streams } from './serve'
import { editFile, page, withRetry } from '~utils'
import { editFile, isServe, page, withRetry } from '~utils'

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

test('should restart', async () => {
test.runIf(isServe)('should restart', async () => {
const logsLengthBeforeEdit = streams.server.out.length
editFile('./vite.config.js', (content) => content)
await withRetry(async () => {
Expand Down
4 changes: 2 additions & 2 deletions playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@ test('async css order', async () => {
await withRetry(async () => {
expect(await getColor('.async-green')).toMatchInlineSnapshot('"green"')
expect(await getColor('.async-blue')).toMatchInlineSnapshot('"blue"')
}, true)
})
})

test('async css order with css modules', async () => {
await withRetry(async () => {
expect(await getColor('.modules-pink')).toMatchInlineSnapshot('"pink"')
}, true)
})
})

test('@import scss', async () => {
Expand Down
6 changes: 3 additions & 3 deletions playground/glob-import/__tests__/glob-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ test('should work', async () => {
await withRetry(async () => {
const actual = await page.textContent('.result')
expect(JSON.parse(actual)).toStrictEqual(allResult)
}, true)
})
await withRetry(async () => {
const actualEager = await page.textContent('.result-eager')
expect(JSON.parse(actualEager)).toStrictEqual(allResult)
}, true)
})
await withRetry(async () => {
const actualNodeModules = await page.textContent('.result-node_modules')
expect(JSON.parse(actualNodeModules)).toStrictEqual(nodeModulesResult)
}, true)
})
})

test('import glob raw', async () => {
Expand Down
31 changes: 17 additions & 14 deletions playground/ssr-conditions/__tests__/ssr-conditions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'
import { port } from './serve'
import { page, withRetry } from '~utils'
import { isServe, page, withRetry } from '~utils'

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

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

test('ssr.resolve settings do not affect non-ssr imports', async () => {
await page.goto(url)
await withRetry(async () => {
expect(await page.textContent('.browser-no-external-react-server')).toMatch(
'default.js',
)
})
await withRetry(async () => {
expect(await page.textContent('.browser-external-react-server')).toMatch(
'default.js',
)
})
})
test.runIf(isServe)(
'ssr.resolve settings do not affect non-ssr imports',
async () => {
await page.goto(url)
await withRetry(async () => {
expect(
await page.textContent('.browser-no-external-react-server'),
).toMatch('default.js')
})
await withRetry(async () => {
expect(await page.textContent('.browser-external-react-server')).toMatch(
'default.js',
)
})
},
)
2 changes: 1 addition & 1 deletion playground/ssr/__tests__/ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.runIf(isServe)('html proxy is encoded', async () => {
})

// run this at the end to reduce flakiness
test('should restart ssr', async () => {
test.runIf(isServe)('should restart ssr', async () => {
editFile('./vite.config.ts', (content) => content)
await withRetry(async () => {
expect(serverLogs).toEqual(
Expand Down
11 changes: 2 additions & 9 deletions playground/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ export async function untilUpdated(
/**
* Retry `func` until it does not throw error.
*/
export async function withRetry(
func: () => Promise<void>,
runInBuild = false,
): Promise<void> {
if (isBuild && !runInBuild) return
export async function withRetry(func: () => Promise<void>): Promise<void> {
const maxTries = process.env.CI ? 200 : 50
for (let tries = 0; tries < maxTries; tries++) {
try {
Expand All @@ -263,10 +259,7 @@ export const expectWithRetry = <T>(getActual: () => Promise<T>) => {
{
get(_target, key) {
return async (...args) => {
await withRetry(
async () => expect(await getActual())[key](...args),
true,
)
await withRetry(async () => expect(await getActual())[key](...args))
}
},
},
Expand Down

0 comments on commit 51d55d3

Please sign in to comment.