Skip to content

Commit

Permalink
feat: run component cleanup if it's registered
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 7, 2024
1 parent 21d2af9 commit 4daaebc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/browser/src/client/tester/tester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SpyModule, collectTests, setupCommonEnv, startTests } from 'vitest/browser'
import { page } from '@vitest/browser/context'
import { channel, client, onCancel } from '@vitest/browser/client'
import { getBrowserState, getConfig, getWorkerState } from '../utils'
import { setupDialogsSpy } from './dialog'
Expand All @@ -8,6 +9,8 @@ import { browserHashMap, initiateRunner } from './runner'
import { VitestBrowserClientMocker } from './mocker'
import { setupExpectDom } from './expect-element'

const cleanupSymbol = Symbol.for('vitest:component-cleanup')

const url = new URL(location.href)
const reloadStart = url.searchParams.get('__reloadStart')

Expand Down Expand Up @@ -123,6 +126,18 @@ async function executeTests(method: 'run' | 'collect', files: string[]) {
}
}
finally {
try {
if (cleanupSymbol in page) {
(page[cleanupSymbol] as any)()
}
}
catch (error: any) {
await client.rpc.onUnhandledError({
name: error.name,
message: error.message,
stack: String(error.stack),
}, 'Cleanup Error')
}
state.environmentTeardownRun = true
debug('finished running tests')
done(files)
Expand Down

0 comments on commit 4daaebc

Please sign in to comment.