1
1
import type { CancelReason } from '@vitest/runner'
2
2
import { getBrowserState } from './utils'
3
3
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
8
9
}
9
10
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
16
15
}
17
16
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
23
20
}
24
21
25
22
export interface GlobalChannelTestRunCanceledEvent {
26
23
type : 'cancel'
27
24
reason : CancelReason
28
25
}
29
26
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
+
30
45
export type GlobalChannelIncomingEvent = GlobalChannelTestRunCanceledEvent
31
46
32
47
export type IframeChannelIncomingEvent =
33
48
| IframeViewportEvent
34
- | IframeErrorEvent
35
- | IframeDoneEvent
36
49
37
- export type IframeChannelOutgoingEvent = never
50
+ export type IframeChannelOutgoingEvent =
51
+ | IframeExecuteEvent
52
+ | IframeCleanupEvent
53
+ | IframePrepareEvent
54
+ | IframeViewportFailEvent
55
+ | IframeViewportDoneEvent
38
56
39
57
export type IframeChannelEvent =
40
58
| IframeChannelIncomingEvent
@@ -44,17 +62,3 @@ export const channel: BroadcastChannel = new BroadcastChannel(
44
62
`vitest:${ getBrowserState ( ) . sessionId } ` ,
45
63
)
46
64
export 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