From 961b4cfd5fb730bbc45aa5db24bbbac59832f12e Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Tue, 3 Mar 2020 12:08:06 +0000 Subject: [PATCH 01/11] Correct window type Previously this would type error: ```ts cy.window().then(window => window.eval('1')); ``` --- cli/types/cypress.d.ts | 2 +- cli/types/index.d.ts | 66 +++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index cb4adf2ca055..758816334c05 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -2001,7 +2001,7 @@ declare namespace Cypress { }) ``` */ - window(options?: Partial): Chainable + window(options?: Partial): Chainable /** * Scopes all subsequent cy commands to within this element. diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index 8da316edd19d..da33750d3beb 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -1,33 +1,33 @@ -// Project: https://www.cypress.io -// GitHub: https://github.com/cypress-io/cypress -// Definitions by: Gert Hengeveld -// Mike Woudenberg -// Robbert van Markus -// Nicholas Boll -// TypeScript Version: 3.0 -// Updated by the Cypress team: https://www.cypress.io/about/ - -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// - -// jQuery includes dependency "sizzle" that provides types -// so we include it too in "node_modules/sizzle". -// This way jQuery can load it using 'reference types="sizzle"' directive - -// load ambient declaration for "cypress" NPM module -// hmm, how to load it better? -/// - -/// -/// -/// -/// +// Project: https://www.cypress.io +// GitHub: https://github.com/cypress-io/cypress +// Definitions by: Gert Hengeveld +// Mike Woudenberg +// Robbert van Markus +// Nicholas Boll +// TypeScript Version: 3.0 +// Updated by the Cypress team: https://www.cypress.io/about/ + +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// + +// jQuery includes dependency "sizzle" that provides types +// so we include it too in "node_modules/sizzle". +// This way jQuery can load it using 'reference types="sizzle"' directive + +// load ambient declaration for "cypress" NPM module +// hmm, how to load it better? +/// + +/// +/// +/// +/// From d5a6b1431dae867bad69dc436f13d77b325a8f59 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Tue, 3 Mar 2020 16:50:00 +0000 Subject: [PATCH 02/11] Upgrade minimum TS version from 2.9 to 3.4 `globalThis` was added in 3.4. --- cli/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index da33750d3beb..173ef6115412 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -4,7 +4,7 @@ // Mike Woudenberg // Robbert van Markus // Nicholas Boll -// TypeScript Version: 3.0 +// TypeScript Version: 3.4 // Updated by the Cypress team: https://www.cypress.io/about/ /// From 8ca418f7483e16b3c1bac127cd640c6c2d1c3a0a Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Tue, 3 Mar 2020 16:56:02 +0000 Subject: [PATCH 03/11] Add test --- cli/types/tests/kitchen-sink.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index ad0d299b102e..3e7320907d2f 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -142,3 +142,5 @@ namespace BlobTests { dateUrl // $ExpectType string }) } + +cy.window().then(window => window.eval('1')) \ No newline at end of file From f45708f8560297a455871d8eac36b1c7783801f1 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Tue, 3 Mar 2020 19:05:46 +0000 Subject: [PATCH 04/11] Format --- cli/types/tests/kitchen-sink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 3e7320907d2f..c159b127279a 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -143,4 +143,4 @@ namespace BlobTests { }) } -cy.window().then(window => window.eval('1')) \ No newline at end of file +cy.window().then(window => window.eval('1')) From cb339ca3b23385b4d9e392181793f9efc9ae8b6e Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Tue, 10 Mar 2020 17:31:54 +0000 Subject: [PATCH 05/11] Test type --- cli/types/tests/kitchen-sink.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index c159b127279a..17ac189a2d61 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -143,4 +143,8 @@ namespace BlobTests { }) } -cy.window().then(window => window.eval('1')) +cy.window().then(window => { + const windowTest: Window & typeof globalThis = window + + window.eval('1')' +}) From 1f91375e9e6b110a476828bd385c13a3c9b3e753 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Wed, 18 Mar 2020 13:43:25 +0000 Subject: [PATCH 06/11] Expect type --- cli/types/tests/kitchen-sink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 17ac189a2d61..31e8739eaef5 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -144,7 +144,7 @@ namespace BlobTests { } cy.window().then(window => { - const windowTest: Window & typeof globalThis = window + window // $ExpectType Window & typeof globalThis window.eval('1')' }) From ce80b820d6caa43ede78ce983206f62eb1c4bbe7 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Wed, 18 Mar 2020 13:44:22 +0000 Subject: [PATCH 07/11] Fix syntax error --- cli/types/tests/kitchen-sink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 31e8739eaef5..75f5b7538c41 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -146,5 +146,5 @@ namespace BlobTests { cy.window().then(window => { window // $ExpectType Window & typeof globalThis - window.eval('1')' + window.eval('1') }) From 20fa3e0acce1ade4e446d5c26f843830037d96a6 Mon Sep 17 00:00:00 2001 From: KHeo Date: Thu, 25 Jun 2020 10:58:55 +0900 Subject: [PATCH 08/11] Add ApplicationWindow type for user-defined properties in Window object --- cli/types/cypress.d.ts | 7 ++++++- cli/types/tests/kitchen-sink.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 758816334c05..5cca2224795a 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -107,6 +107,11 @@ declare namespace Cypress { fromAutWindow: WindowPosition & { x: number, y: number } } + /** + * The interface for user-defined properties in Window object. + */ + interface ApplicationWindow {} // tslint:disable-line + /** * Several libraries are bundled with Cypress by default. * @@ -2001,7 +2006,7 @@ declare namespace Cypress { }) ``` */ - window(options?: Partial): Chainable + window(options?: Partial): Chainable /** * Scopes all subsequent cy commands to within this element. diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 75f5b7538c41..add8e6afdb69 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -144,7 +144,7 @@ namespace BlobTests { } cy.window().then(window => { - window // $ExpectType Window & typeof globalThis + window // $ExpectType Window & typeof globalThis & ApplicationWindow window.eval('1') }) From 5961445309e3345e4d58f9ab821de981a78662af Mon Sep 17 00:00:00 2001 From: KHeo Date: Thu, 25 Jun 2020 11:02:06 +0900 Subject: [PATCH 09/11] Fix comment. --- cli/types/cypress.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 5cca2224795a..5c4b56a73f38 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -108,7 +108,7 @@ declare namespace Cypress { } /** - * The interface for user-defined properties in Window object. + * The interface for user-defined properties in Window object under test. */ interface ApplicationWindow {} // tslint:disable-line From b8a76f2f53d2c55c00053203ef91e4629d2306ba Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 30 Jun 2020 11:52:24 +0900 Subject: [PATCH 10/11] crlf -> lf. --- cli/types/index.d.ts | 66 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index 173ef6115412..64600eb51430 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -1,33 +1,33 @@ -// Project: https://www.cypress.io -// GitHub: https://github.com/cypress-io/cypress -// Definitions by: Gert Hengeveld -// Mike Woudenberg -// Robbert van Markus -// Nicholas Boll -// TypeScript Version: 3.4 -// Updated by the Cypress team: https://www.cypress.io/about/ - -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// - -// jQuery includes dependency "sizzle" that provides types -// so we include it too in "node_modules/sizzle". -// This way jQuery can load it using 'reference types="sizzle"' directive - -// load ambient declaration for "cypress" NPM module -// hmm, how to load it better? -/// - -/// -/// -/// -/// +// Project: https://www.cypress.io +// GitHub: https://github.com/cypress-io/cypress +// Definitions by: Gert Hengeveld +// Mike Woudenberg +// Robbert van Markus +// Nicholas Boll +// TypeScript Version: 3.4 +// Updated by the Cypress team: https://www.cypress.io/about/ + +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// + +// jQuery includes dependency "sizzle" that provides types +// so we include it too in "node_modules/sizzle". +// This way jQuery can load it using 'reference types="sizzle"' directive + +// load ambient declaration for "cypress" NPM module +// hmm, how to load it better? +/// + +/// +/// +/// +/// From 43f22c56a7d1ce0fda1405eb7c6983bbb0d2164b Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 30 Jun 2020 18:31:24 +0900 Subject: [PATCH 11/11] Test more APIs. --- cli/types/cypress.d.ts | 29 +++++++++++++++++------------ cli/types/tests/actions.ts | 4 ++-- cli/types/tests/cypress-tests.ts | 18 ++++++++++++++++++ cli/types/tests/kitchen-sink.ts | 2 +- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 5c4b56a73f38..63989cb36bb2 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -107,6 +107,11 @@ declare namespace Cypress { fromAutWindow: WindowPosition & { x: number, y: number } } + /** + * Window type for Application Under Test(AUT) + */ + type AUTWindow = Window & typeof globalThis & ApplicationWindow + /** * The interface for user-defined properties in Window object under test. */ @@ -1043,7 +1048,7 @@ declare namespace Cypress { * * @see https://on.cypress.io/go */ - go(direction: HistoryDirection | number, options?: Partial): Chainable + go(direction: HistoryDirection | number, options?: Partial): Chainable /** * Get the current URL hash of the page that is currently active. @@ -1380,7 +1385,7 @@ declare namespace Cypress { * @example * cy.reload() */ - reload(options?: Partial): Chainable + reload(options?: Partial): Chainable /** * Reload the page without cache * @@ -1391,7 +1396,7 @@ declare namespace Cypress { * cy.visit('http://localhost:3000/admin') * cy.reload(true) */ - reload(forceReload: boolean): Chainable + reload(forceReload: boolean): Chainable /** * Make an HTTP GET request. @@ -1934,8 +1939,8 @@ declare namespace Cypress { * }) * */ - visit(url: string, options?: Partial): Chainable - visit(options: Partial & { url: string }): Chainable + visit(url: string, options?: Partial): Chainable + visit(options: Partial & { url: string }): Chainable /** * Wait for a number of milliseconds. @@ -2006,7 +2011,7 @@ declare namespace Cypress { }) ``` */ - window(options?: Partial): Chainable + window(options?: Partial): Chainable /** * Scopes all subsequent cy commands to within this element. @@ -2720,16 +2725,16 @@ declare namespace Cypress { /** * Called before your page has loaded all of its resources. * - * @param {Window} contentWindow the remote page's window object + * @param {AUTWindow} contentWindow the remote page's window object */ - onBeforeLoad(win: Window): void + onBeforeLoad(win: AUTWindow): void /** * Called once your page has fired its load event. * - * @param {Window} contentWindow the remote page's window object + * @param {AUTWindow} contentWindow the remote page's window object */ - onLoad(win: Window): void + onLoad(win: AUTWindow): void /** * Cypress will automatically apply the right authorization headers @@ -4637,12 +4642,12 @@ declare namespace Cypress { * Fires as the page begins to load, but before any of your applications JavaScript has executed. This fires at the exact same time as `cy.visit()` `onBeforeLoad` callback. Useful to modify the window on a page transition. * @see https://on.cypress.io/catalog-of-events#App-Events */ - (action: 'window:before:load', fn: (win: Window) => void): void + (action: 'window:before:load', fn: (win: AUTWindow) => void): void /** * Fires after all your resources have finished loading after a page transition. This fires at the exact same time as a `cy.visit()` `onLoad` callback. * @see https://on.cypress.io/catalog-of-events#App-Events */ - (action: 'window:load', fn: (win: Window) => void): void + (action: 'window:load', fn: (win: AUTWindow) => void): void /** * Fires when your application is about to navigate away. The real event object is provided to you. Your app may have set a `returnValue` on the event, which is useful to assert on. * @see https://on.cypress.io/catalog-of-events#App-Events diff --git a/cli/types/tests/actions.ts b/cli/types/tests/actions.ts index ae407691ce85..b022c1a8af6a 100644 --- a/cli/types/tests/actions.ts +++ b/cli/types/tests/actions.ts @@ -12,11 +12,11 @@ Cypress.on('window:alert', (text) => { }) Cypress.on('window:before:load', (win) => { - win // $ExpectType Window + win // $ExpectType AUTWindow }) Cypress.on('window:load', (win) => { - win // $ExpectType Window + win // $ExpectType AUTWindow }) Cypress.on('window:before:unload', (event) => { diff --git a/cli/types/tests/cypress-tests.ts b/cli/types/tests/cypress-tests.ts index ccc8e1cba734..75a5c01ba75a 100644 --- a/cli/types/tests/cypress-tests.ts +++ b/cli/types/tests/cypress-tests.ts @@ -287,6 +287,24 @@ cy subject // $ExpectType undefined }) +namespace CypressAUTWindowTests { + cy.go(2).then((win) => { + win // $ExpectType AUTWindow + }) + + cy.reload().then((win) => { + win // $ExpectType AUTWindow + }) + + cy.visit('https://google.com').then(win => { + win // $ExpectType AUTWindow + }) + + cy.window().then(win => { + win // $ExpectType AUTWindow + }) +} + namespace CypressOnTests { Cypress.on('uncaught:exception', (error, runnable) => { error // $ExpectType Error diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index add8e6afdb69..e09a52e7084e 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -144,7 +144,7 @@ namespace BlobTests { } cy.window().then(window => { - window // $ExpectType Window & typeof globalThis & ApplicationWindow + window // $ExpectType AUTWindow window.eval('1') })