Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename events #2935

Merged
merged 15 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1789,10 +1789,10 @@ declare namespace Cypress {
*/
integrationFolder: string
/**
* Path to plugins file. (Pass false to disable)
* @default "cypress/plugins/index.js"
* Path to background file. (Pass false to disable)
* @default "cypress/background/index.js"
*/
pluginsFile: string
backgroundFile: string
/**
* Path to folder where screenshots will be saved from [cy.screenshot()](https://on.cypress.io/screenshot) command or after a headless or CI run’s test failure
* @default "cypress/screenshots"
Expand Down Expand Up @@ -3654,6 +3654,17 @@ declare namespace Cypress {
(fn: (currentSubject: Subject) => void): Chainable<Subject>
}


/**
* Page details included with actions like 'page:start'
*/
interface PageDetails {
win: Window
url: string
statusCode?: number
headers?: { [key: string]: string }
}

// for just a few events like "page:alert" it makes sense to allow passing cy.stub() or
// a user callback function. Others probably only need a callback function.

Expand Down Expand Up @@ -3718,22 +3729,22 @@ 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()` `onStart` callback. Useful to modify the window on a page transition.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'page:start', fn: (win: Window) => void): void
(action: 'page:start', fn: (details: PageDetails) => 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()` `onReady` callback.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'page:ready', fn: (win: Window) => void): void
(action: 'page:ready', fn: (details: PageDetails) => 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.
* Fires when your application is has unloaded and is navigating away. The real event object is provided to you. This event is not cancelable.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'before:window:unload', fn: (event: BeforeUnloadEvent) => void): void
(action: 'page:end', fn: (details: PageDetails) => void): void
/**
* Fires when your application is has unloaded and is navigating away. The real event object is provided to you. This event is not cancelable.
* 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
*/
(action: 'page:end', fn: (event: Event) => void): void
(action: 'before:window:unload', fn: (event: BeforeUnloadEvent) => void): void
/**
* Fires whenever Cypress detects that your application's URL has changed.
* @see https://on.cypress.io/catalog-of-events#App-Events
Expand All @@ -3748,7 +3759,7 @@ declare namespace Cypress {
* Fires whenever the viewport changes via a `cy.viewport()` or naturally when Cypress resets the viewport to the default between tests. Useful for debugging purposes.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'viewport:changed', fn: (viewport: Viewport) => void): void
(action: 'viewport:change', fn: (viewport: Viewport) => void): void
/**
* Fires whenever **Cypress** is scrolling your application. This event is fired when Cypress is {% url 'waiting for and calculating actionability' interacting-with-elements %}. It will scroll to 'uncover' elements currently being covered. This event is extremely useful to debug why Cypress may think an element is not interactive.
* @see https://on.cypress.io/catalog-of-events#App-Events
Expand All @@ -3758,22 +3769,22 @@ declare namespace Cypress {
* Fires when a cy command is first invoked and enqueued to be run later. Useful for debugging purposes if you're confused about the order in which commands will execute.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'command:enqueued', fn: (command: EnqueuedCommand) => void): void
(action: 'internal:commandEnqueue', fn: (command: EnqueuedCommand) => void): void
/**
* Fires when cy begins actually running and executing your command. Useful for debugging and understanding how the command queue is async.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'command:start', fn: (command: CommandQueue) => void): void
(action: 'internal:commandStart', fn: (command: CommandQueue) => void): void
/**
* Fires when cy finishes running and executing your command. Useful for debugging and understanding how commands are handled.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'command:end', fn: (command: CommandQueue) => void): void
(action: 'internal:commandEnd', fn: (command: CommandQueue) => void): void
/**
* Fires whenever a command begins its retrying routines. This is called on the trailing edge after Cypress has internally waited for the retry interval. Useful to understand **why** a command is retrying, and generally includes the actual error causing the retry to happen. When commands fail the final error is the one that actually bubbles up to fail the test. This event is essentially to debug why Cypress is failing.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'command:retry', fn: (command: CommandQueue) => void): void
(action: 'internal:commandRetry', fn: (command: CommandQueue) => void): void
/**
* Fires whenever a command emits this event so it can be displayed in the Command Log. Useful to see how internal cypress commands utilize the {% url 'Cypress.log()' cypress-log %} API.
* @see https://on.cypress.io/catalog-of-events#App-Events
Expand All @@ -3788,12 +3799,12 @@ declare namespace Cypress {
* Fires before the test and all **before** and **beforeEach** hooks run.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'test:run:start', fn: (attributes: ObjectLike, test: Mocha.ITest) => void): void
(action: 'test:start', fn: (attributes: ObjectLike, test: Mocha.ITest) => void): void
/**
* Fires after the test and all **afterEach** and **after** hooks run.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'test:run:end', fn: (attributes: ObjectLike, test: Mocha.ITest) => void): void
(action: 'test:end', fn: (attributes: ObjectLike, test: Mocha.ITest) => void): void
}

// $CommandQueue from `command_queue.coffee` - a lot to type. Might be more useful if it was written in TS
Expand Down
30 changes: 15 additions & 15 deletions cli/types/tests/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ Cypress.on('page:alert', (text) => {
text // $ExpectType string
})

Cypress.on('page:start', (win) => {
win // $ExpectType Window
Cypress.on('page:start', (details) => {
details // $ExpectType PageDetails
})

Cypress.on('page:ready', (win) => {
win // $ExpectType Window
Cypress.on('page:ready', (details) => {
details // $ExpectType PageDetails
})

Cypress.on('before:window:unload', (event) => {
event // $ExpectType BeforeUnloadEvent
Cypress.on('page:end', (details) => {
details // $ExpectType PageDetails
})

Cypress.on('page:end', (event) => {
event // $ExpectType Event
Cypress.on('before:window:unload', (event) => {
event // $ExpectType BeforeUnloadEvent
})

Cypress.on('page:url:changed', (url) => {
Expand All @@ -36,27 +36,27 @@ Cypress.on('test:fail', (error, mocha) => {
mocha // $ExpectType IRunnable
})

Cypress.on('viewport:changed', (viewport) => {
Cypress.on('viewport:change', (viewport) => {
viewport // $ExpectType Viewport
})

Cypress.on('internal:scrolled', ($el) => {
$el // $ExpectType JQuery<HTMLElement>
})

Cypress.on('command:enqueued', (command) => {
Cypress.on('internal:commandEnqueue', (command) => {
command // $ExpectType EnqueuedCommand
})

Cypress.on('command:start', (command) => {
Cypress.on('internal:commandStart', (command) => {
command // $ExpectType CommandQueue
})

Cypress.on('command:end', (command) => {
Cypress.on('internal:commandEnd', (command) => {
command // $ExpectType CommandQueue
})

Cypress.on('command:retry', (command) => {
Cypress.on('internal:commandRetry', (command) => {
command // $ExpectType CommandQueue
})

Expand All @@ -68,12 +68,12 @@ Cypress.on('log:changed', (log, interactive: boolean) => {
log // $ExpectTyped any
})

Cypress.on('test:run:start', (attributes , test) => {
Cypress.on('test:start', (attributes , test) => {
attributes // $ExpectType ObjectLike
test // $ExpectType ITest
})

Cypress.on('test:run:end', (attributes , test) => {
Cypress.on('test:end', (attributes , test) => {
attributes // $ExpectType ObjectLike
test // $ExpectType ITest
})
6 changes: 3 additions & 3 deletions packages/driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ after:add | Runner | Anyone | when all runnables have been added to the UI
runnables:ready | Runner | Anyone | when all runnables have been reduced to basic objects
mocha:start | Mocha | Cypress | when mocha runner triggers its 'start' event
suite:start | Mocha | Cypress | when mocha runner fires its 'suite' event
test:run:start:async | Cypress | Anyone | before any code has run for a particular test
test:run:start:async | Cypress | Cypress | before any hooks for a test have started
test:start:async | Cypress | Anyone | before any code has run for a particular test
test:start:async | Cypress | Cypress | before any hooks for a test have started
hook:start | Mocha | Cypress | when mocha runner fires its 'hook' event
test:start | Mocha | Cypress | when mocha runner fires its 'test' event
suite:end | Mocha | Cypress | when mocha runner fires its 'suite end' event
Expand All @@ -89,7 +89,7 @@ mocha:fail | Mocha | Cypress | when mocha runner fires its 'fail' event
test:end | Mocha | Cypress | when mocha runner fires its 'test end' event
test:results:ready | Runner | Anyone | when we receive the 'test:end' event
after:test:hooks | Cypress | Cypress | after all hooks have run for a test
test:run:end | Cypress | Anyone | after any code has run for a test
test:end | Cypress | Anyone | after any code has run for a test
mocha:end | Mocha | Cypress | when mocha runner fires its 'end' event
after:run | Runner | Anyone | after run has finished

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/actions/type.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ weekRegex = /^\d{4}-W(0[1-9]|[1-4]\d|5[0-3])$/
timeRegex = /^([0-1]\d|2[0-3]):[0-5]\d(:[0-5]\d)?(\.[0-9]{1,3})?$/

module.exports = (Commands, Cypress, cy, state, config) ->
Cypress.on "test:run:start", ->
Cypress.on "test:start", ->
$Keyboard.resetModifiers(state("document"), state("window"))

Commands.addAll({ prevSubject: "element" }, {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/agents.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

## before each of our tests we always want
## to reset the counts + the sandbox
Cypress.on("test:run:start", resetAndSetSandbox)
Cypress.on("test:start", resetAndSetSandbox)

wrap = (ctx, type, agent, obj, method, count) ->
if not count
Expand Down
6 changes: 3 additions & 3 deletions packages/driver/src/cy/commands/clock.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## this MUST be prepended else if we are stubbing or spying on
## global timers they will be reset in agents before this runs
## its reset function
Cypress.prependListener("test:run:start", reset)
Cypress.prependListener("test:start", reset)

Cypress.on "page:start", (contentWindow) ->
Cypress.on "page:start", ({ win }) ->
## if a clock has been created before this event (likely before
## a cy.visit(), then bind that clock to the new window
if clock
clock.bind(contentWindow)
clock.bind(win)

Commands.addAll({ type: "utility" }, {
clock: (subject, now, methods, options = {}) ->
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/cy/commands/connectors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

cleanup = ->
state("onInjectCommand", undefined)
cy.removeListener("command:enqueued", enqueuedCommand)
cy.removeListener("internal:commandEnqueue", enqueuedCommand)
return null

invokedCyCommand = false
Expand All @@ -61,7 +61,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

state("onInjectCommand", returnFalseIfThenable)

cy.once("command:enqueued", enqueuedCommand)
cy.once("internal:commandEnqueue", enqueuedCommand)

## this code helps juggle subjects forward
## the same way that promises work
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/cookies.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

automateCookies("clear:cookies", cookies, log, timeout)

Cypress.on "test:run:start:async", ->
Cypress.on "test:start:async", ->
## TODO: handle failure here somehow
## maybe by tapping into the Cypress reset
## stuff, or handling this in the runner itself?
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/local_storage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clearLocalStorage = (state, keys) ->

module.exports = (Commands, Cypress, cy, state, config) ->
## this MUST be prepended before anything else
Cypress.prependListener "test:run:start", ->
Cypress.prependListener "test:start", ->
try
## this may fail if the current
## window is bound to another origin
Expand Down
13 changes: 8 additions & 5 deletions packages/driver/src/cy/commands/navigation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ stabilityChanged = (Cypress, state, config, stable, event) ->
module.exports = (Commands, Cypress, cy, state, config) ->
reset()

Cypress.on("test:run:start", reset)
Cypress.on("test:start", reset)

Cypress.on "stability:changed", (bool, event) ->
## only send up page loading events when we're
Expand Down Expand Up @@ -284,7 +284,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
else
resp

Cypress.on "page:start", (contentWindow) ->
Cypress.on "page:start", ({ win }) ->
## TODO: just use a closure here
current = state("current")

Expand All @@ -295,7 +295,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
return if not runnable

options = _.last(current.get("args"))
options?.onStart?.call(runnable.ctx, contentWindow)
options?.onStart?.call(runnable.ctx, win)

Commands.addAll({
reload: (args...) ->
Expand Down Expand Up @@ -346,14 +346,17 @@ module.exports = (Commands, Cypress, cy, state, config) ->

options._log.snapshot("before", {next: "after"})

onPageReady = ({ win }) ->
resolve(win)

cleanup = ->
knownCommandCausedInstability = false

cy.removeListener("page:ready", resolve)
cy.removeListener("page:ready", onPageReady)

knownCommandCausedInstability = true

cy.once("page:ready", resolve)
cy.once("page:ready", onPageReady)

$utils.locReload(forceReload, state("window"))

Expand Down
6 changes: 3 additions & 3 deletions packages/driver/src/cy/commands/querying.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
restoreContains()

## restore before each test and whenever we stop
Cypress.on("test:run:start", restoreContains)
Cypress.on("test:start", restoreContains)
Cypress.on("stop", restoreContains)

Commands.addAll({
Expand Down Expand Up @@ -416,7 +416,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
fn.call(ctx, subject)

cleanup = ->
cy.removeListener("command:start", setWithinSubject)
cy.removeListener("internal:commandStart", setWithinSubject)

## we need a mechanism to know when we should remove
## our withinSubject so we dont accidentally keep it
Expand All @@ -443,7 +443,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## if next is defined then we know we'll eventually
## unbind these listeners
if next
cy.on("command:start", setWithinSubject)
cy.on("internal:commandStart", setWithinSubject)
else
## remove our listener if we happen to reach the end
## event which will finalize cleanup if there was no next obj
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/screenshot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ takeScreenshot = (Cypress, state, screenshotConfig, options = {}) ->
sendAsync("before:screenshot", getOptions(true))

after = ->
send("after:screenshot", getOptions(false))
send("screenshot", getOptions(false))

if disableTimersAndAnimations
cy.pauseTimers(false)
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/cy/commands/window.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## currentViewport could already be set due to previous runs
currentViewport ?= defaultViewport

Cypress.on "test:run:start:async", ->
Cypress.on "test:start:async", ->
## if we have viewportDefaults it means
## something has changed the default and we
## need to restore prior to running the next test
Expand All @@ -57,7 +57,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

## force our UI to change to the viewport and wait for it
## to be updated
Cypress.action "cy:viewport:changed", viewport, ->
Cypress.action "cy:viewport:change", viewport, ->
resolve(viewport)

Commands.addAll({
Expand Down
Loading