From bff96a4d797e6db454b46480a03c42fabf1f9f22 Mon Sep 17 00:00:00 2001 From: KHeo Date: Mon, 2 May 2022 17:47:14 +0900 Subject: [PATCH 1/3] fix: remove unnecessary eventemittor2 type definitions from cy, Cypress --- cli/types/cypress-eventemitter.d.ts | 18 +++++++++++++++++- cli/types/cypress-global-vars.d.ts | 4 ++-- cli/types/tests/actions.ts | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cli/types/cypress-eventemitter.d.ts b/cli/types/cypress-eventemitter.d.ts index 3e6e39800fa1..da0b0cdf2258 100644 --- a/cli/types/cypress-eventemitter.d.ts +++ b/cli/types/cypress-eventemitter.d.ts @@ -1,7 +1,23 @@ // Cypress, cy, Log inherits EventEmitter. type EventEmitter2 = import("eventemitter2").EventEmitter2 -interface EventEmitter extends EventEmitter2 { +type event = import("eventemitter2").event +type eventNS = import("eventemitter2").eventNS +type ListenerFn = import("eventemitter2").ListenerFn +type Listener = import("eventemitter2").Listener +type OnOptions = import("eventemitter2").OnOptions + +interface CyActions extends Cypress.Actions { + (event: event | eventNS, listener: ListenerFn, options?: boolean|OnOptions): this|Listener +} + +interface CyEventEmitter { + once: CyActions + on: CyActions + off: CyActions + emit: EventEmitter2['emit'] + removeListener: EventEmitter2['removeListener'] + removeAllListeners: EventEmitter2['removeAllListeners'] proxyTo: (cy: Cypress.cy) => null emitMap: (eventName: string, args: any[]) => Array<(...args: any[]) => any> emitThen: (eventName: string, args: any[]) => Bluebird.BluebirdStatic diff --git a/cli/types/cypress-global-vars.d.ts b/cli/types/cypress-global-vars.d.ts index d108bfa3c7f7..ddeaa326a9ef 100644 --- a/cli/types/cypress-global-vars.d.ts +++ b/cli/types/cypress-global-vars.d.ts @@ -7,7 +7,7 @@ cy.get('button').click() cy.get('.result').contains('Expected text') ``` */ -declare const cy: Cypress.cy & EventEmitter +declare const cy: Cypress.cy & CyEventEmitter /** * Global variable `Cypress` holds common utilities and constants. @@ -19,4 +19,4 @@ Cypress.version // => "1.4.0" Cypress._ // => Lodash _ ``` */ -declare const Cypress: Cypress.Cypress & EventEmitter +declare const Cypress: Cypress.Cypress & CyEventEmitter diff --git a/cli/types/tests/actions.ts b/cli/types/tests/actions.ts index 014c43dad9da..294a47347380 100644 --- a/cli/types/tests/actions.ts +++ b/cli/types/tests/actions.ts @@ -87,3 +87,17 @@ namespace CypressActionCommandOptionTests { cy.get('el').click({scrollBehavior: false}) cy.get('el').click({scrollBehavior: true}) // $ExpectError } + +namespace CyEventEmitterTests { + cy.waitFor() // $ExpectError + cy.prependListener() // $ExpectError + cy.on('random', () => {}) + cy.removeAllListeners() + cy.removeListener('a', () => {}) + + Cypress.waitFor() // $ExpectError + Cypress.prependListener() // $ExpectError + Cypress.on('random', () => {}) + Cypress.removeAllListeners() + Cypress.removeListener('a', () => {}) +} From e1660280c742f5cafd2a1bd5fb9e842a8a16facd Mon Sep 17 00:00:00 2001 From: KHeo Date: Mon, 9 May 2022 16:29:33 +0900 Subject: [PATCH 2/3] feedback. --- cli/types/cypress-eventemitter.d.ts | 18 +----------------- cli/types/tests/actions.ts | 5 +++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/cli/types/cypress-eventemitter.d.ts b/cli/types/cypress-eventemitter.d.ts index da0b0cdf2258..86d2587f722b 100644 --- a/cli/types/cypress-eventemitter.d.ts +++ b/cli/types/cypress-eventemitter.d.ts @@ -1,23 +1,7 @@ // Cypress, cy, Log inherits EventEmitter. type EventEmitter2 = import("eventemitter2").EventEmitter2 -type event = import("eventemitter2").event -type eventNS = import("eventemitter2").eventNS -type ListenerFn = import("eventemitter2").ListenerFn -type Listener = import("eventemitter2").Listener -type OnOptions = import("eventemitter2").OnOptions - -interface CyActions extends Cypress.Actions { - (event: event | eventNS, listener: ListenerFn, options?: boolean|OnOptions): this|Listener -} - -interface CyEventEmitter { - once: CyActions - on: CyActions - off: CyActions - emit: EventEmitter2['emit'] - removeListener: EventEmitter2['removeListener'] - removeAllListeners: EventEmitter2['removeAllListeners'] +interface CyEventEmitter extends Omit { proxyTo: (cy: Cypress.cy) => null emitMap: (eventName: string, args: any[]) => Array<(...args: any[]) => any> emitThen: (eventName: string, args: any[]) => Bluebird.BluebirdStatic diff --git a/cli/types/tests/actions.ts b/cli/types/tests/actions.ts index 294a47347380..910f531d94b9 100644 --- a/cli/types/tests/actions.ts +++ b/cli/types/tests/actions.ts @@ -88,15 +88,16 @@ namespace CypressActionCommandOptionTests { cy.get('el').click({scrollBehavior: true}) // $ExpectError } +// https://github.com/cypress-io/cypress/pull/21286 +// `waitFor` doesn't exist in Node EventEmitter +// and it confuses the users with `cy.wait` namespace CyEventEmitterTests { cy.waitFor() // $ExpectError - cy.prependListener() // $ExpectError cy.on('random', () => {}) cy.removeAllListeners() cy.removeListener('a', () => {}) Cypress.waitFor() // $ExpectError - Cypress.prependListener() // $ExpectError Cypress.on('random', () => {}) Cypress.removeAllListeners() Cypress.removeListener('a', () => {}) From 498dcde9eb1a91f54ffaccf8f63eb1f2f7a78435 Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 10 May 2022 14:48:58 +0900 Subject: [PATCH 3/3] fix trailing whitespace error. --- cli/types/tests/actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/tests/actions.ts b/cli/types/tests/actions.ts index 910f531d94b9..831aaee0fe84 100644 --- a/cli/types/tests/actions.ts +++ b/cli/types/tests/actions.ts @@ -89,7 +89,7 @@ namespace CypressActionCommandOptionTests { } // https://github.com/cypress-io/cypress/pull/21286 -// `waitFor` doesn't exist in Node EventEmitter +// `waitFor` doesn't exist in Node EventEmitter // and it confuses the users with `cy.wait` namespace CyEventEmitterTests { cy.waitFor() // $ExpectError