From 8bc0bbba2c5ef879a6ca42fe1f47c7451638b797 Mon Sep 17 00:00:00 2001 From: mtgto Date: Sat, 13 Mar 2021 15:59:35 +0900 Subject: [PATCH 1/4] Fix obsoleted urls and tests --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2b97d1e45..431a3eea2 100644 --- a/README.md +++ b/README.md @@ -206,11 +206,11 @@ property which do not require Node integration. #### client -Spectron uses [WebdriverIO](http://webdriver.io) and exposes the managed +Spectron uses [WebdriverIO](https://webdriver.io) and exposes the managed `client` property on the created `Application` instances. The `client` API is WebdriverIO's `browser` object. Documentation can be found -[here](http://webdriver.io/api.html). +[here](https://webdriver.io/docs/api). Several additional commands are provided specific to Electron. @@ -219,8 +219,10 @@ All the commands return a `Promise`. So if you wanted to get the text of an element you would do: ```js -app.client.getText('#error-alert').then(function (errorText) { - console.log('The #error-alert text content is ' + errorText) +app.client.$('#error-alert').then(function (element) { + element.getText().then(function (errorText) { + console.log('The #error-alert text content is ' + errorText) + }) }) ``` @@ -237,9 +239,8 @@ API in your tests you would do: ```js app.electron.clipboard.writeText('pasta') - .electron.clipboard.readText().then(function (clipboardText) { - console.log('The clipboard text is ' + clipboardText) - }) +const clipboardText = app.electron.clipboard.readText() +console.log('The clipboard text is ' + clipboardText) ``` #### browserWindow @@ -649,7 +650,7 @@ test.afterEach(t => { return t.context.app.stop(); }); -test(t => { +test('opens a window', t => { return t.context.app.client.waitUntilWindowLoaded() .getWindowCount().then(count => { t.is(count, 1); @@ -686,7 +687,7 @@ test.afterEach.always(async t => { await t.context.app.stop(); }); -test(async t => { +test('example', async t => { const app = t.context.app; await app.client.waitUntilWindowLoaded(); From 2f12d627a4d635bca5c7c9d15a4b834a815f72ee Mon Sep 17 00:00:00 2001 From: mtgto Date: Sat, 13 Mar 2021 16:00:08 +0900 Subject: [PATCH 2/4] Refactor type of SpectronWindow --- lib/spectron.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/spectron.d.ts b/lib/spectron.d.ts index 2fbeed8a2..487afc5e1 100644 --- a/lib/spectron.d.ts +++ b/lib/spectron.d.ts @@ -118,7 +118,9 @@ declare module 'spectron' { ): Promise; } - export interface SpectronWindow extends Electron.BrowserWindow { + type PromisedBrowserWindow = { [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends (...args: infer A) => infer R ? (...args: A) => Promise : undefined }; + + export interface SpectronWindow extends PromisedBrowserWindow { capturePage(): Promise; } @@ -126,7 +128,7 @@ declare module 'spectron' { savePage( fullPath: string, saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML', - callback?: (eror: Error) => void + callback?: (error: Error) => void ): boolean; savePage( fullPath: string, From 84bd7fc37524cd164631f6d803d5bd8aadb0bf16 Mon Sep 17 00:00:00 2001 From: mtgto Date: Sat, 13 Mar 2021 16:19:48 +0900 Subject: [PATCH 3/4] Define type of SpectronWindow from Electron.BrowserWindow --- lib/spectron.d.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/spectron.d.ts b/lib/spectron.d.ts index 487afc5e1..69300237a 100644 --- a/lib/spectron.d.ts +++ b/lib/spectron.d.ts @@ -118,11 +118,7 @@ declare module 'spectron' { ): Promise; } - type PromisedBrowserWindow = { [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends (...args: infer A) => infer R ? (...args: A) => Promise : undefined }; - - export interface SpectronWindow extends PromisedBrowserWindow { - capturePage(): Promise; - } + export type SpectronWindow = { [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends (...args: infer A) => infer R ? (...args: A) => Promise : undefined }; export interface SpectronWebContents extends Electron.WebContents { savePage( From 38044c886751880e3133311a85c40102feacf74e Mon Sep 17 00:00:00 2001 From: mtgto Date: Sat, 13 Mar 2021 16:22:09 +0900 Subject: [PATCH 4/4] Format by prettier --- lib/spectron.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/spectron.d.ts b/lib/spectron.d.ts index 69300237a..deee7cf55 100644 --- a/lib/spectron.d.ts +++ b/lib/spectron.d.ts @@ -118,7 +118,13 @@ declare module 'spectron' { ): Promise; } - export type SpectronWindow = { [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends (...args: infer A) => infer R ? (...args: A) => Promise : undefined }; + export type SpectronWindow = { + [P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends ( + ...args: infer A + ) => infer R + ? (...args: A) => Promise + : undefined; + }; export interface SpectronWebContents extends Electron.WebContents { savePage(