diff --git a/cli/package.json b/cli/package.json index 041933890e..df66a41a51 100644 --- a/cli/package.json +++ b/cli/package.json @@ -37,6 +37,7 @@ "commander": "2.15.1", "common-tags": "1.8.0", "debug": "3.2.6", + "eventemitter2": "4.1.2", "execa": "0.10.0", "executable": "4.1.1", "extract-zip": "1.6.7", diff --git a/cli/types/cypress-npm-api.d.ts b/cli/types/cypress-npm-api.d.ts index 37409b7a0d..3a30518b34 100644 --- a/cli/types/cypress-npm-api.d.ts +++ b/cli/types/cypress-npm-api.d.ts @@ -461,6 +461,11 @@ declare module 'cypress' { totalPassed: number totalPending: number totalSkipped: number + /** + * If Cypress test run is being recorded, full url will be provided. + * @see https://on.cypress.io/dashboard-introduction + */ + runUrl?: string runs: RunResult[] browserPath: string browserName: string diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index 9567231bd3..b8d618c2c5 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -30,6 +30,15 @@ // hmm, how to load it better? /// +// Cypress, cy, Log inherits EventEmitter. +type EventEmitter2 = import("eventemitter2").EventEmitter2 + +interface EventEmitter extends EventEmitter2 { + proxyTo: (cy: Cypress.cy) => null + emitMap: (eventName: string, args: any[]) => Array<(...args: any[]) => any> + emitThen: (eventName: string, args: any[]) => Bluebird.BluebirdStatic +} + // Cypress adds chai expect and assert to global declare const expect: Chai.ExpectStatic declare const assert: Chai.AssertStatic @@ -4506,7 +4515,7 @@ cy.get('button').click() cy.get('.result').contains('Expected text') ``` */ -declare const cy: Cypress.cy +declare const cy: Cypress.cy & EventEmitter /** * Global variable `Cypress` holds common utilities and constants. @@ -4518,4 +4527,4 @@ Cypress.version // => "1.4.0" Cypress._ // => Lodash _ ``` */ -declare const Cypress: Cypress.Cypress +declare const Cypress: Cypress.Cypress & EventEmitter diff --git a/cli/types/tests/cypress-npm-api-test.ts b/cli/types/tests/cypress-npm-api-test.ts index d2045f7245..eb5e5730e3 100644 --- a/cli/types/tests/cypress-npm-api-test.ts +++ b/cli/types/tests/cypress-npm-api-test.ts @@ -11,6 +11,7 @@ cypress.run().then(results => { results // $ExpectType CypressRunResult results.failures // $ExpectType number | undefined results.message // $ExpectType string | undefined + results.runUrl // $ExpectType string | undefined }) cypress.open() // $ExpectType Promise cypress.run() // $ExpectType Promise diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 2a177a0500..63b83adbe3 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -63,13 +63,20 @@ stub() expect(stub).to.have.been.calledOnce cy.wrap(stub).should('have.been.calledOnce') -// window:confirm stubbing -Cypress.on('window:confirm', () => { }) -Cypress.on('window:confirm', cy.spy()) -Cypress.on('window:confirm', cy.stub()) -cy.on('window:confirm', () => { }) -cy.on('window:confirm', cy.spy()) -cy.on('window:confirm', cy.stub()) +namespace EventInterfaceTests { + // window:confirm stubbing + Cypress.on('window:confirm', () => { }) + Cypress.on('window:confirm', cy.spy()) + Cypress.on('window:confirm', cy.stub()) + cy.on('window:confirm', () => { }) + cy.on('window:confirm', cy.spy()) + cy.on('window:confirm', cy.stub()) + + Cypress.removeListener('fail', () => {}) + Cypress.removeAllListeners('fail') + cy.removeListener('fail', () => {}) + cy.removeAllListeners('fail') +} // specifying HTTP method directly in the options object cy.request({