11import type { CancelReason } from '@vitest/runner'
22import { getBrowserState } from './utils'
33
4- export interface IframeDoneEvent {
5- type : 'done'
6- filenames : string [ ]
7- id : string
4+ export interface IframeViewportEvent {
5+ event : 'viewport'
6+ width : number
7+ height : number
8+ iframeId : string
89}
910
10- export interface IframeErrorEvent {
11- type : 'error'
12- error : any
13- errorType : string
14- files : string [ ]
15- id : string
11+ export interface IframeViewportFailEvent {
12+ event : 'viewport:fail'
13+ iframeId : string
14+ error : string
1615}
1716
18- export interface IframeViewportEvent {
19- type : 'viewport'
20- width : number
21- height : number
22- id : string
17+ export interface IframeViewportDoneEvent {
18+ event : 'viewport:done'
19+ iframeId : string
2320}
2421
2522export interface GlobalChannelTestRunCanceledEvent {
2623 type : 'cancel'
2724 reason : CancelReason
2825}
2926
27+ export interface IframeExecuteEvent {
28+ event : 'execute'
29+ method : 'run' | 'collect'
30+ files : string [ ]
31+ iframeId : string
32+ context : string
33+ }
34+
35+ export interface IframeCleanupEvent {
36+ event : 'cleanup'
37+ iframeId : string
38+ }
39+
40+ export interface IframePrepareEvent {
41+ event : 'prepare'
42+ iframeId : string
43+ }
44+
3045export type GlobalChannelIncomingEvent = GlobalChannelTestRunCanceledEvent
3146
3247export type IframeChannelIncomingEvent =
3348 | IframeViewportEvent
34- | IframeErrorEvent
35- | IframeDoneEvent
3649
37- export type IframeChannelOutgoingEvent = never
50+ export type IframeChannelOutgoingEvent =
51+ | IframeExecuteEvent
52+ | IframeCleanupEvent
53+ | IframePrepareEvent
54+ | IframeViewportFailEvent
55+ | IframeViewportDoneEvent
3856
3957export type IframeChannelEvent =
4058 | IframeChannelIncomingEvent
@@ -44,17 +62,3 @@ export const channel: BroadcastChannel = new BroadcastChannel(
4462 `vitest:${ getBrowserState ( ) . sessionId } ` ,
4563)
4664export const globalChannel : BroadcastChannel = new BroadcastChannel ( 'vitest:global' )
47-
48- export function waitForChannel ( event : IframeChannelOutgoingEvent [ 'type' ] ) : Promise < void > {
49- return new Promise < void > ( ( resolve ) => {
50- channel . addEventListener (
51- 'message' ,
52- ( e ) => {
53- if ( e . data ?. type === event ) {
54- resolve ( )
55- }
56- } ,
57- { once : true } ,
58- )
59- } )
60- }
0 commit comments