()
| 184 | installTransitionStyle() |
| 185 | |
| 186 | export function setupBrowserE2E(): BrowserUtils { |
| 187 | const pageErrorHandlers = new Map< |
| 188 | (...args: any[]) => void, |
| 189 | PageErrorHandler |
| 190 | >() |
| 191 | const initialHeadNodes = new Set<Node>(Array.from(document.head.childNodes)) |
| 192 | |
| 193 | function resetPageErrorHandlers() { |
| 194 | pageErrorHandlers.forEach(({ error, rejection }) => { |
| 195 | window.removeEventListener('error', error) |
| 196 | window.removeEventListener('unhandledrejection', rejection) |
| 197 | }) |
| 198 | pageErrorHandlers.clear() |
| 199 | } |
| 200 | |
| 201 | function resetHead() { |
| 202 | Array.from(document.head.childNodes).forEach(node => { |
| 203 | if ( |
| 204 | !initialHeadNodes.has(node) && |
| 205 | !( |
| 206 | node instanceof HTMLStyleElement && |
| 207 | node.dataset.vueTransitionE2e != null |
| 208 | ) |
| 209 | ) { |
| 210 | node.remove() |
| 211 | } |
| 212 | }) |
| 213 | } |
| 214 | |
| 215 | async function resetPage() { |
| 216 | // Browser mode runs in Vitest's iframe instead of loading transition.html. |
| 217 | // Keep these specs on the same global build that `test-e2e` prepares. |
| 218 | resetPageErrorHandlers() |
| 219 | await vueGlobalBuildReady |
| 220 | resetHead() |
| 221 | localStorage.clear() |
| 222 | sessionStorage.clear() |
| 223 | document.body.innerHTML = '<div id="app"></div>' |
| 224 | } |
| 225 | |
| 226 | function getElement<T extends Element = Element>(selector: string): T { |
| 227 | const el = document.querySelector<T>(selector) |
| 228 | if (!el) { |
| 229 | throw new Error(`Unable to find element: ${selector}`) |
| 230 | } |
| 231 | return el |
| 232 | } |
| 233 | |
| 234 | function createElementHandle<T extends Element>(node: T): ElementHandle<T> { |
| 235 | return { |
| 236 | async evaluate<R>(fn: (node: T) => R | Promise<R>) { |
| 237 | return (await fn(node)) as Awaited<R> |
| 238 | }, |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | function toExposedArg(arg: unknown) { |
| 243 | return arg instanceof Element ? createElementHandle(arg) : arg |
no outgoing calls
no test coverage detected