1
1
import {
2
- Page ,
3
2
Browser ,
4
3
BrowserContext ,
4
+ Page ,
5
+ BrowserContextOptions ,
6
+ LaunchOptions ,
5
7
BrowserType as PlaywrightBrowserType ,
6
8
ChromiumBrowser ,
7
9
FirefoxBrowser ,
8
10
WebKitBrowser ,
11
+ devices ,
9
12
} from 'playwright-core'
13
+ import { Config as JestConfig } from '@jest/types'
14
+ import { Context } from 'jest-runner/build/types'
15
+ import { Test } from 'jest-runner'
16
+ import { JestProcessManagerOptions } from 'jest-process-manager'
10
17
11
- type BrowserType = 'chromium' | 'firefox' | 'webkit'
18
+ // TODO Find out flexable ways to reuse constants
19
+ declare const IMPORT_KIND_PLAYWRIGHT = 'playwright'
12
20
13
- type GenericBrowser = PlaywrightBrowserType <
14
- WebKitBrowser | ChromiumBrowser | FirefoxBrowser
15
- >
21
+ declare const CHROMIUM = 'chromium'
22
+ declare const FIREFOX = 'firefox'
23
+ declare const WEBKIT = 'webkit'
16
24
17
- type SkipOption = {
25
+ declare const LAUNCH = 'LAUNCH'
26
+ declare const PERSISTENT = 'PERSISTENT'
27
+ declare const SERVER = 'SERVER'
28
+
29
+ export type BrowserType = typeof CHROMIUM | typeof FIREFOX | typeof WEBKIT
30
+
31
+ export type SkipOption = {
18
32
browsers : BrowserType [ ]
19
33
devices ?: string [ ] | RegExp
20
34
}
21
35
36
+ export type GenericBrowser = PlaywrightBrowserType <
37
+ WebKitBrowser | ChromiumBrowser | FirefoxBrowser
38
+ >
39
+
22
40
type ContextOptions = Parameters < GenericBrowser [ 'connect' ] > [ 0 ]
23
41
24
42
interface JestPlaywright {
@@ -83,16 +101,15 @@ interface JestParams<T> {
83
101
( options : T , name : string , fn ?: jest . ProvidesCallback , timeout ?: number ) : void
84
102
}
85
103
86
- // TODO Replace any
87
- interface JestPlaywrightDebug extends JestParams < any > {
104
+ interface JestPlaywrightTestDebug extends JestParams < JestPlaywrightConfig > {
88
105
( name : string , fn ?: jest . ProvidesCallback , timeout ?: number ) : void
89
- skip : JestParams < any > | JestPlaywrightDebug
90
- only : JestParams < any > | JestPlaywrightDebug
106
+ skip : JestParams < JestPlaywrightConfig > | JestPlaywrightTestDebug
107
+ only : JestParams < JestPlaywrightConfig > | JestPlaywrightTestDebug
91
108
}
92
109
93
- interface JestPlaywrightConfig extends JestParams < any > {
94
- skip : JestParams < any > | JestPlaywrightConfig
95
- only : JestParams < any > | JestPlaywrightConfig
110
+ interface JestPlaywrightTestConfig extends JestParams < JestPlaywrightConfig > {
111
+ skip : JestParams < JestPlaywrightConfig > | JestPlaywrightTestConfig
112
+ only : JestParams < JestPlaywrightConfig > | JestPlaywrightTestConfig
96
113
}
97
114
98
115
declare global {
@@ -105,8 +122,63 @@ declare global {
105
122
namespace jest {
106
123
interface It {
107
124
jestPlaywrightSkip : JestParams < SkipOption >
108
- jestPlaywrightDebug : JestPlaywrightDebug
109
- jestPlaywrightConfig : JestPlaywrightConfig
125
+ jestPlaywrightDebug : JestPlaywrightTestDebug
126
+ jestPlaywrightConfig : JestPlaywrightTestConfig
110
127
}
111
128
}
112
129
}
130
+
131
+ export type CustomDeviceType = BrowserContextOptions & {
132
+ name : string
133
+ }
134
+
135
+ export type DeviceType = CustomDeviceType | string | null
136
+
137
+ export type WsEndpointType = string | null
138
+
139
+ export type SelectorType = {
140
+ script : string | Function | { path ?: string ; content ?: string }
141
+ name : string
142
+ }
143
+
144
+ export type PlaywrightRequireType = BrowserType | typeof IMPORT_KIND_PLAYWRIGHT
145
+
146
+ export interface Playwright {
147
+ name : PlaywrightRequireType
148
+ instance : GenericBrowser
149
+ devices : typeof devices
150
+ }
151
+
152
+ type LaunchType = typeof LAUNCH | typeof SERVER | typeof PERSISTENT
153
+
154
+ type Options < T > = T & Partial < Record < BrowserType , T > >
155
+
156
+ export type ConnectOptions = Parameters < GenericBrowser [ 'connect' ] > [ 0 ]
157
+
158
+ export interface JestPlaywrightConfig {
159
+ launchType ?: LaunchType
160
+ launchOptions ?: Options < LaunchOptions >
161
+ connectOptions ?: Options < ConnectOptions >
162
+ contextOptions ?: Options < BrowserContextOptions >
163
+ userDataDir ?: string
164
+ exitOnPageError : boolean
165
+ browsers : BrowserType [ ]
166
+ devices ?: ( string | CustomDeviceType ) [ ] | RegExp
167
+ serverOptions ?: JestProcessManagerOptions
168
+ selectors ?: SelectorType [ ]
169
+ collectCoverage : boolean
170
+ }
171
+
172
+ export interface JestPlaywrightProjectConfig extends JestConfig . ProjectConfig {
173
+ browserName : BrowserType
174
+ wsEndpoint : WsEndpointType
175
+ device : DeviceType
176
+ }
177
+
178
+ interface JestPlaywrightContext extends Context {
179
+ config : JestPlaywrightProjectConfig
180
+ }
181
+
182
+ export interface JestPlaywrightTest extends Test {
183
+ context : JestPlaywrightContext
184
+ }
0 commit comments