Skip to content

Commit

Permalink
fix(browser): remove hacky retry (#5971)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jun 25, 2024
1 parent 0eda99d commit 2a2c908
Showing 1 changed file with 1 addition and 60 deletions.
61 changes: 1 addition & 60 deletions packages/browser/src/client/tester/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,6 @@ function debug(...args: unknown[]) {
}
}

async function tryCall<T>(
fn: () => Promise<T>,
): Promise<T | false | undefined> {
try {
return await fn()
}
catch (err: any) {
const now = Date.now()
// try for 30 seconds
const canTry = !reloadStart || now - Number(reloadStart) < 30_000
const errorStack = (() => {
if (!err) {
return null
}
return err.stack?.includes(err.message)
? err.stack
: `${err.message}\n${err.stack}`
})()
debug(
'failed to resolve runner',
'trying again:',
canTry,
'time is',
now,
'reloadStart is',
reloadStart,
':\n',
errorStack,
)
if (!canTry) {
const error = serializeError(
new Error('Vitest failed to load its runner after 30 seconds.'),
)
error.cause = serializeError(err)

await client.rpc.onUnhandledError(error, 'Preload Error')
return false
}

if (!reloadStart) {
const newUrl = new URL(location.href)
newUrl.searchParams.set('__reloadStart', now.toString())
debug('set the new url because reload start is not set to', newUrl)
location.href = newUrl.toString()
}
else {
debug('reload the iframe because reload start is set', location.href)
location.reload()
}
}
}

async function prepareTestEnvironment(files: string[]) {
debug('trying to resolve runner', `${reloadStart}`)
const config = getConfig()
Expand Down Expand Up @@ -142,7 +90,7 @@ async function runTests(files: string[]) {

// if importing /@id/ failed, we reload the page waiting until Vite prebundles it
try {
preparedData = await tryCall(() => prepareTestEnvironment(files))
preparedData = await prepareTestEnvironment(files)
}
catch (error) {
debug('data cannot be loaded because it threw an error')
Expand All @@ -151,13 +99,6 @@ async function runTests(files: string[]) {
return
}

// cannot load data, finish the test
if (preparedData === false) {
debug('data cannot be loaded, finishing the test')
done(files)
return
}

// page is reloading
if (!preparedData) {
debug('page is reloading, waiting for the next run')
Expand Down

0 comments on commit 2a2c908

Please sign in to comment.