|
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
|
@@ -117,30 +127,13 @@ export interface SpectronClient extends WebdriverIO.BrowserObject {
|
117 | 127 | ): Promise<AccessibilityAuditResult>;
|
118 | 128 | }
|
119 | 129 |
|
120 |
| -export type SpectronWindow = { |
121 |
| - [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends ( |
122 |
| - ...args: infer A |
123 |
| - ) => infer R |
124 |
| - ? (...args: A) => Promise<R> |
125 |
| - : undefined; |
| 130 | +export type SpectronElectron = { |
| 131 | + [K in keyof typeof Electron]: MakeMethodsAsync<typeof Electron[K]>; |
126 | 132 | };
|
127 | 133 |
|
128 |
| -export interface SpectronWebContents extends Electron.WebContents { |
129 |
| - savePage( |
130 |
| - fullPath: string, |
131 |
| - saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML', |
132 |
| - callback?: (error: Error) => void |
133 |
| - ): boolean; |
134 |
| - savePage( |
135 |
| - fullPath: string, |
136 |
| - saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML' |
137 |
| - ): Promise<void>; |
138 |
| - savePage( |
139 |
| - fullPath: string, |
140 |
| - saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML' |
141 |
| - ): any; |
142 |
| - executeJavaScript(code: string, userGesture?: boolean): Promise<any>; |
143 |
| -} |
| 134 | +export type SpectronWindow = MakeMethodsAsync<Electron.BrowserWindow>; |
| 135 | + |
| 136 | +export type SpectronWebContents = MakeMethodsAsync<Electron.WebContents>; |
144 | 137 |
|
145 | 138 | type BasicAppSettings = {
|
146 | 139 | /**
|
@@ -260,7 +253,7 @@ export class Application {
|
260 | 253 | * Each Electron module is exposed as a property on the electron property so you can
|
261 | 254 | * think of it as an alias for require('electron') from within your app.
|
262 | 255 | */
|
263 |
| - electron: Electron.RemoteMainInterface; |
| 256 | + electron: SpectronElectron; |
264 | 257 | /**
|
265 | 258 | * The browserWindow property is an alias for require('electron').remote.getCurrentWindow().
|
266 | 259 | * It provides you access to the current BrowserWindow and contains all the APIs.
|
|
0 commit comments