()
| 257 | } |
| 258 | |
| 259 | async function cleanup() { |
| 260 | const state = getWorkerState() |
| 261 | const config = getConfig() |
| 262 | const rpc = state.rpc as any as BrowserRPC |
| 263 | |
| 264 | const cleanupSymbol = Symbol.for('vitest:component-cleanup') |
| 265 | |
| 266 | if (cleanupSymbol in page) { |
| 267 | try { |
| 268 | await (page[cleanupSymbol] as any)() |
| 269 | } |
| 270 | catch (error: any) { |
| 271 | await unhandledError(error, 'Cleanup Error') |
| 272 | } |
| 273 | } |
| 274 | // need to cleanup for each tester |
| 275 | // since playwright keyboard API is stateful on page instance level |
| 276 | await userEvent.cleanup() |
| 277 | .catch(error => unhandledError(error, 'Cleanup Error')) |
| 278 | |
| 279 | await Promise.all( |
| 280 | getBrowserState().cleanups.map(fn => fn()), |
| 281 | ).catch(error => unhandledError(error, 'Cleanup Error')) |
| 282 | |
| 283 | // if isolation is disabled, Vitest reuses the same iframe and we |
| 284 | // don't need to switch the context back at all |
| 285 | if (contextSwitched) { |
| 286 | await rpc.wdioSwitchContext('parent') |
| 287 | .catch(error => unhandledError(error, 'Cleanup Error')) |
| 288 | } |
| 289 | await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.browser.isolate }).catch((error) => { |
| 290 | return unhandledError(error, 'Coverage Error') |
| 291 | }) |
| 292 | } |
| 293 | |
| 294 | function unhandledError(e: Error, type: string) { |
| 295 | return client.rpc.onUnhandledError({ |
no test coverage detected