|
7 | 7 | import * as Electron from 'electron'; |
8 | 8 | import * as WebdriverIO from 'webdriverio'; |
9 | 9 |
|
| 10 | +type MethodsOf<T> = { |
| 11 | + [K in keyof T]: T[K] extends (...args: any) => any ? K : never; |
| 12 | +}[keyof T]; |
| 13 | + |
| 14 | +type MakeAsync<T> = T extends (...args: infer A) => infer R |
| 15 | + ? (...args: A) => Promise<R extends PromiseLike<infer T> ? T : R> |
| 16 | + : never; |
| 17 | + |
| 18 | +type MakeMethodsAsync<T> = { [K in MethodsOf<T>]: MakeAsync<T[K]> }; |
| 19 | + |
10 | 20 | interface AccessibilityAuditOptions { |
11 | 21 | /** |
12 | 22 | * true to ignore failures with a severity of 'Warning' and only |
@@ -111,30 +121,13 @@ export interface SpectronClient extends WebdriverIO.Browser<'async'> { |
111 | 121 | ): Promise<AccessibilityAuditResult>; |
112 | 122 | } |
113 | 123 |
|
114 | | -export type SpectronWindow = { |
115 | | - [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends ( |
116 | | - ...args: infer A |
117 | | - ) => infer R |
118 | | - ? (...args: A) => Promise<R> |
119 | | - : undefined; |
| 124 | +export type SpectronElectron = { |
| 125 | + [K in keyof typeof Electron]: MakeMethodsAsync<typeof Electron[K]>; |
120 | 126 | }; |
121 | 127 |
|
122 | | -export interface SpectronWebContents extends Electron.WebContents { |
123 | | - savePage( |
124 | | - fullPath: string, |
125 | | - saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML', |
126 | | - callback?: (error: Error) => void |
127 | | - ): boolean; |
128 | | - savePage( |
129 | | - fullPath: string, |
130 | | - saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML' |
131 | | - ): Promise<void>; |
132 | | - savePage( |
133 | | - fullPath: string, |
134 | | - saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML' |
135 | | - ): any; |
136 | | - executeJavaScript(code: string, userGesture?: boolean): Promise<any>; |
137 | | -} |
| 128 | +export type SpectronWindow = MakeMethodsAsync<Electron.BrowserWindow>; |
| 129 | + |
| 130 | +export type SpectronWebContents = MakeMethodsAsync<Electron.WebContents>; |
138 | 131 |
|
139 | 132 | type BasicAppSettings = { |
140 | 133 | /** |
@@ -254,7 +247,7 @@ export class Application { |
254 | 247 | * Each Electron module is exposed as a property on the electron property so you can |
255 | 248 | * think of it as an alias for require('electron') from within your app. |
256 | 249 | */ |
257 | | - electron: typeof Electron; |
| 250 | + electron: SpectronElectron; |
258 | 251 | /** |
259 | 252 | * The browserWindow property is an alias for require('electron').remote.getCurrentWindow(). |
260 | 253 | * It provides you access to the current BrowserWindow and contains all the APIs. |
|
0 commit comments