Added missing EventEmitter2 type to Cypress and cy + missing ru… (#6066)

* Added EventEmitter2 type to Cypress and cy.

* Added missing runUrl

* runUrl is optional

* Fixed typo.

Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
This commit is contained in:
Kukhyeon Heo
2020-01-08 00:05:48 +09:00
committed by Gleb Bahmutov
parent 16deee4145
commit 11bd06b6ee
5 changed files with 32 additions and 9 deletions

View File

@@ -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",

View File

@@ -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

13
cli/types/index.d.ts vendored
View File

@@ -30,6 +30,15 @@
// hmm, how to load it better?
/// <reference path="./cypress-npm-api.d.ts" />
// 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

View File

@@ -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<void>
cypress.run() // $ExpectType Promise<CypressRunResult>

View File

@@ -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({