diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index edeadc88c28e..ee0ca942524a 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -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" @@ -3654,6 +3654,17 @@ declare namespace Cypress { (fn: (currentSubject: Subject) => void): Chainable } + + /** + * 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. @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/cli/types/tests/actions.ts b/cli/types/tests/actions.ts index 5fd9d3181b50..679686f9d973 100644 --- a/cli/types/tests/actions.ts +++ b/cli/types/tests/actions.ts @@ -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) => { @@ -36,7 +36,7 @@ Cypress.on('test:fail', (error, mocha) => { mocha // $ExpectType IRunnable }) -Cypress.on('viewport:changed', (viewport) => { +Cypress.on('viewport:change', (viewport) => { viewport // $ExpectType Viewport }) @@ -44,19 +44,19 @@ Cypress.on('internal:scrolled', ($el) => { $el // $ExpectType JQuery }) -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 }) @@ -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 }) diff --git a/packages/driver/README.md b/packages/driver/README.md index 7771f18a0cfb..af7f396bbac0 100644 --- a/packages/driver/README.md +++ b/packages/driver/README.md @@ -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 @@ -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 diff --git a/packages/driver/src/cy/commands/actions/type.coffee b/packages/driver/src/cy/commands/actions/type.coffee index 3b9acae6245b..77db9936f942 100644 --- a/packages/driver/src/cy/commands/actions/type.coffee +++ b/packages/driver/src/cy/commands/actions/type.coffee @@ -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" }, { diff --git a/packages/driver/src/cy/commands/agents.coffee b/packages/driver/src/cy/commands/agents.coffee index 85c36b3de78d..373068f28cf1 100644 --- a/packages/driver/src/cy/commands/agents.coffee +++ b/packages/driver/src/cy/commands/agents.coffee @@ -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 diff --git a/packages/driver/src/cy/commands/clock.coffee b/packages/driver/src/cy/commands/clock.coffee index 92ea126d06ef..0a4d30fea057 100644 --- a/packages/driver/src/cy/commands/clock.coffee +++ b/packages/driver/src/cy/commands/clock.coffee @@ -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 = {}) -> diff --git a/packages/driver/src/cy/commands/connectors.coffee b/packages/driver/src/cy/commands/connectors.coffee index 590c22558bf8..b748e79fd60a 100644 --- a/packages/driver/src/cy/commands/connectors.coffee +++ b/packages/driver/src/cy/commands/connectors.coffee @@ -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 @@ -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 diff --git a/packages/driver/src/cy/commands/cookies.coffee b/packages/driver/src/cy/commands/cookies.coffee index 8dee580b151e..bb6fb1f62da9 100644 --- a/packages/driver/src/cy/commands/cookies.coffee +++ b/packages/driver/src/cy/commands/cookies.coffee @@ -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? diff --git a/packages/driver/src/cy/commands/local_storage.coffee b/packages/driver/src/cy/commands/local_storage.coffee index 6278adbc178f..6bffaf39b0b6 100644 --- a/packages/driver/src/cy/commands/local_storage.coffee +++ b/packages/driver/src/cy/commands/local_storage.coffee @@ -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 diff --git a/packages/driver/src/cy/commands/navigation.coffee b/packages/driver/src/cy/commands/navigation.coffee index d2d239e72962..ef0a6044dbd3 100644 --- a/packages/driver/src/cy/commands/navigation.coffee +++ b/packages/driver/src/cy/commands/navigation.coffee @@ -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 @@ -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") @@ -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...) -> @@ -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")) diff --git a/packages/driver/src/cy/commands/querying.coffee b/packages/driver/src/cy/commands/querying.coffee index 1c048fc55863..943af26ca7e1 100644 --- a/packages/driver/src/cy/commands/querying.coffee +++ b/packages/driver/src/cy/commands/querying.coffee @@ -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({ @@ -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 @@ -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 diff --git a/packages/driver/src/cy/commands/screenshot.coffee b/packages/driver/src/cy/commands/screenshot.coffee index 74628871b963..2a2b0c7fc9a6 100644 --- a/packages/driver/src/cy/commands/screenshot.coffee +++ b/packages/driver/src/cy/commands/screenshot.coffee @@ -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) diff --git a/packages/driver/src/cy/commands/window.coffee b/packages/driver/src/cy/commands/window.coffee index 1eaee8b02905..d816dc3cf6f1 100644 --- a/packages/driver/src/cy/commands/window.coffee +++ b/packages/driver/src/cy/commands/window.coffee @@ -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 @@ -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({ diff --git a/packages/driver/src/cy/commands/xhr.coffee b/packages/driver/src/cy/commands/xhr.coffee index 907d05c15ad2..08f255081b50 100644 --- a/packages/driver/src/cy/commands/xhr.coffee +++ b/packages/driver/src/cy/commands/xhr.coffee @@ -228,7 +228,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> ## correctly Cypress.on("page:end", abort) - Cypress.on "test:run:start", -> + Cypress.on "test:start", -> ## reset the existing server reset() @@ -245,10 +245,10 @@ module.exports = (Commands, Cypress, cy, state, config) -> return null - Cypress.on "page:start", (contentWindow) -> + Cypress.on "page:start", ({ win }) -> if server ## dynamically bind the server to whatever is currently running - server.bindTo(contentWindow) + server.bindTo(win) else ## if we don't have a server such as the case when ## the last window was cross origin, try to bind diff --git a/packages/driver/src/cy/retries.coffee b/packages/driver/src/cy/retries.coffee index f7740911947f..41830edce260 100644 --- a/packages/driver/src/cy/retries.coffee +++ b/packages/driver/src/cy/retries.coffee @@ -87,7 +87,7 @@ create = (Cypress, state, timeout, clearTimeout, whenStable, finishAssertions) - .then -> return if ended() - Cypress.action("cy:command:retry", options) + Cypress.action("cy:internal:commandRetry", options) return if ended() diff --git a/packages/driver/src/cypress.coffee b/packages/driver/src/cypress.coffee index f804629ca960..e72287126b01 100644 --- a/packages/driver/src/cypress.coffee +++ b/packages/driver/src/cypress.coffee @@ -216,7 +216,7 @@ class $Cypress when "cypress:config" @emit("config", args[0]) - when "runner:start" + when "runner:mocha:start" ## mocha runner has begun running the tests @emit("run:start") @@ -225,7 +225,7 @@ class $Cypress if @config("isTextTerminal") @emit("mocha", "start", args[0]) - when "runner:end" + when "runner:mocha:end" ## mocha runner has finished running the tests ## end may have been caused by an uncaught error @@ -234,7 +234,7 @@ class $Cypress ## when this happens mocha aborts the entire run ## and does not do the usual cleanup so that means ## we have to fire the after:test:hooks and - ## test:run:end events ourselves + ## test:end events ourselves @emit("run:end") if @config("isTextTerminal") @@ -245,46 +245,46 @@ class $Cypress ## is about to be invoked @cy.setRunnable(args...) - when "runner:suite:start" + when "runner:mocha:suite:start" ## mocha runner started processing a suite if @config("isTextTerminal") @emit("mocha", "suite", args...) - when "runner:suite:end" + when "runner:mocha:suite:end" ## mocha runner finished processing a suite if @config("isTextTerminal") @emit("mocha", "suite end", args...) - when "runner:hook:start" + when "runner:mocha:hook:start" ## mocha runner started processing a hook if @config("isTextTerminal") @emit("mocha", "hook", args...) - when "runner:hook:end" + when "runner:mocha:hook:end" ## mocha runner finished processing a hook if @config("isTextTerminal") @emit("mocha", "hook end", args...) - when "runner:test:start" + when "runner:mocha:test:start" ## mocha runner started processing a hook if @config("isTextTerminal") @emit("mocha", "test", args...) - when "runner:test:end" + when "runner:mocha:test:end" if @config("isTextTerminal") @emit("mocha", "test end", args...) - when "runner:pass" + when "runner:mocha:pass" ## mocha runner calculated a pass if @config("isTextTerminal") @emit("mocha", "pass", args...) - when "runner:pending" + when "runner:mocha:pending" ## mocha runner calculated a pending test if @config("isTextTerminal") @emit("mocha", "pending", args...) - when "runner:fail" + when "runner:mocha:fail" ## mocha runner calculated a failure if @config("isTextTerminal") @emit("mocha", "fail", args...) @@ -292,32 +292,32 @@ class $Cypress when "mocha:runnable:run" @runner.onRunnableRun(args...) - when "runner:test:run:start" + when "runner:test:start" ## get back to a clean slate @cy.reset() - @emitToBackend("test:run:start", serializeTest(args[1])) - @emit("test:run:start", args...) + @emitToBackend("test:start", serializeTest(args[1])) + @emit("test:start", args...) - when "runner:test:run:start:async" + when "runner:test:start:async" ## TODO: handle timeouts here? or in the runner? - @emitThen("test:run:start:async", args...) + @emitThen("test:start:async", args...) when "runner:after:runnable:run:async" @emitThen("after:runnable:run:async", args...) - when "runner:test:run:end" + when "runner:test:end" @runner.cleanupQueue(@config("numTestsKeptInMemory")) ## this event is how the reporter knows how to display ## stats and runnable properties such as errors - @emitToBackend("test:run:end", serializeTest(args[1])) - @emit("test:run:end", args...) + @emitToBackend("test:end", serializeTest(args[1])) + @emit("test:end", args...) if @config("isTextTerminal") ## needed for calculating wallClockDuration ## and the timings of after + afterEach hooks - @emit("mocha", "test:run:end", args[0]) + @emit("mocha", "test:end", args[0]) when "cy:before:all:screenshots" @emit("before:all:screenshots", args...) @@ -325,8 +325,8 @@ class $Cypress when "cy:before:screenshot" @emit("before:screenshot", args...) - when "cy:after:screenshot" - @emit("after:screenshot", args...) + when "cy:screenshot" + @emit("screenshot", args...) when "cy:after:all:screenshots" @emit("after:all:screenshots", args...) @@ -357,24 +357,24 @@ class $Cypress when "cy:visit:failed" @emit("visit:failed", args[0]) - when "cy:viewport:changed" - @emit("viewport:changed", args...) + when "cy:viewport:change" + @emit("viewport:change", args...) - when "cy:command:start" - @emitToBackend("command:start", serializeCommand(args[0])) - @emit("command:start", args...) + when "cy:internal:commandStart" + @emitToBackend("internal:commandStart", serializeCommand(args[0])) + @emit("internal:commandStart", args...) - when "cy:command:end" - @emitToBackend("command:end", serializeCommand(args[0])) - @emit("command:end", args...) + when "cy:internal:commandEnd" + @emitToBackend("internal:commandEnd", serializeCommand(args[0])) + @emit("internal:commandEnd", args...) - when "cy:command:retry" - @emitToBackend("command:retry", serializeRetry(args[0])) - @emit("command:retry", args...) + when "cy:internal:commandRetry" + @emitToBackend("internal:commandRetry", serializeRetry(args[0])) + @emit("internal:commandRetry", args...) - when "cy:command:enqueued" - @emitToBackend("command:enqueued", serializeCommand(args[0])) - @emit("command:enqueued", args[0]) + when "cy:internal:commandEnqueue" + @emitToBackend("internal:commandEnqueue", serializeCommand(args[0])) + @emit("internal:commandEnqueue", args[0]) when "cy:before:command:queue:end" @emit("before:command:queue:end") diff --git a/packages/driver/src/cypress/cy.coffee b/packages/driver/src/cypress/cy.coffee index 76577b81a654..79c6b609bd00 100644 --- a/packages/driver/src/cypress/cy.coffee +++ b/packages/driver/src/cypress/cy.coffee @@ -124,8 +124,11 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> ## return undefined so our beforeunload handler ## doesnt trigger a confirmation dialog return undefined - onUnload: (e) -> - Cypress.action("app:page:end", e) + onUnload: -> + Cypress.action("app:page:end", { + win: contentWindow + url: state("url") + }) onNavigation: (args...) -> Cypress.action("app:navigation:changed", args...) onAlert: (str) -> @@ -189,7 +192,7 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> queue.splice(index, 0, obj) - Cypress.action("cy:command:enqueued", obj) + Cypress.action("cy:internal:commandEnqueue", obj) getCommandsUntilFirstParentOrValidSubject = (command, memo = []) -> return null if not command @@ -239,7 +242,7 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> ## since they return promises and queue more ## new commands if noArgsAreAFunction(args) - Cypress.once("command:enqueued", commandEnqueued) + Cypress.once("internal:commandEnqueue", commandEnqueued) ## run the command's fn with runnable's context try @@ -248,7 +251,7 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> throw err finally ## always remove this listener - Cypress.removeListener("command:enqueued", commandEnqueued) + Cypress.removeListener("internal:commandEnqueue", commandEnqueued) state("commandIntermediateValue", ret) @@ -371,7 +374,7 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> ## store the current runnable runnable = state("runnable") - Cypress.action("cy:command:start", command) + Cypress.action("cy:internal:commandStart", command) runCommand(command) .then -> @@ -390,7 +393,7 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> ## over at 0 state("index", index += 1) - Cypress.action("cy:command:end", command) + Cypress.action("cy:internal:commandEnd", command) if fn = state("onPaused") new Promise (resolve) -> @@ -693,7 +696,10 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> ## about:blank in a visit, we do need these contentWindowListeners(getContentWindow($autIframe)) - Cypress.action("app:page:ready", state("window")) + Cypress.action("app:page:ready", { + win: state("window") + url: state("url") + }) ## we are now stable again which is purposefully ## the last event we call here, to give our event @@ -892,19 +898,19 @@ create = (specWindow, Cypress, Cookies, state, config, log) -> ## prevent loop comprehension return null - onBeforeAppWindowLoad: (contentWindow) -> + onBeforeAppWindowLoad: ({ win }) -> ## we set window / document props before the window load event ## so that we properly handle events coming from the application ## from the time that happens BEFORE the load event occurs - setWindowDocumentProps(contentWindow, state) + setWindowDocumentProps(win, state) urlNavigationEvent("before:load") - contentWindowListeners(contentWindow) + contentWindowListeners(win) - wrapNativeMethods(contentWindow) + wrapNativeMethods(win) - timers.wrap(contentWindow) + timers.wrap(win) onSpecWindowUncaughtException: (args...) -> ## create the special uncaught exception err diff --git a/packages/driver/src/cypress/error_messages.coffee b/packages/driver/src/cypress/error_messages.coffee index 7098362252ad..669ab19f4e3f 100644 --- a/packages/driver/src/cypress/error_messages.coffee +++ b/packages/driver/src/cypress/error_messages.coffee @@ -224,6 +224,20 @@ module.exports = { {{object}}.{{method}}('{{newEvent}}', ) """ + renamed_event_win_to_details: """The '{{oldEvent}}' event has been renamed to '{{newEvent}}' and its argument signature has been changed. + + Please change: + + {{object}}.{{method}}('{{oldEvent}}', (win) => { + win // use of win argument + }) + + to: + + {{object}}.{{method}}('{{newEvent}}', (details) => { + details.win // win is now a property on the details argument + }) + """ exec: failed: """#{cmd('exec', '\'{{cmd}}\'')} failed with the following error: diff --git a/packages/driver/src/cypress/events.coffee b/packages/driver/src/cypress/events.coffee index f491844121c2..10f8f3d9a721 100644 --- a/packages/driver/src/cypress/events.coffee +++ b/packages/driver/src/cypress/events.coffee @@ -112,19 +112,27 @@ module.exports = { throwOnRenamedEvent: (eventEmitter, name) -> renamedEvents = { + "command:end": "internal:commandEnd" + "command:enqueued": "internal:commandEnqueued" "command:queue:before:end": "before:command:queue:end" + "command:retry": "internal:commandRetry" + "command:start": "internal:commandStart" "fail": "test:fail" "runnable:after:run:async": "after:runnable:run:async" "scrolled": "internal:scrolled" - "test:after:run": "test:run:end" - "test:before:run": "test:run:start" - "test:before:run:async": "test:run:start:async" + "test:after:run": "test:end" + "test:before:run": "test:start" + "test:before:run:async": "test:start:async" "url:changed": "page:url:changed" + "viewport:changed": "viewport:change" "window:alert": "page:alert" - "window:before:load": "page:start" "window:before:unload": "before:window:unload" "window:confirm": "page:confirm" - "window:unload": "page:end" + } + + renamedEventsWithWinChangedtoDetails = { + "window:before:load": "page:start" + "window:load": "page:ready" } methods = "addListener on once prependListener prependOnceListener".split(" ") @@ -141,6 +149,16 @@ module.exports = { } from: "cypress" }) + else if renamedEventsWithWinChangedtoDetails[eventName] + $utils.throwErrByPath("events.renamed_event_win_to_details", { + args: { + oldEvent: eventName + newEvent: renamedEventsWithWinChangedtoDetails[eventName] + object: name + method: method + } + from: "cypress" + }) else original.call(@, eventName, listener) } diff --git a/packages/driver/src/cypress/runner.coffee b/packages/driver/src/cypress/runner.coffee index aefaedb1d727..57ed70cb2e53 100644 --- a/packages/driver/src/cypress/runner.coffee +++ b/packages/driver/src/cypress/runner.coffee @@ -10,8 +10,8 @@ mochaCtxKeysRe = /^(_runnable|test)$/ betweenQuotesRe = /\"(.+?)\"/ HOOKS = "beforeAll beforeEach afterEach afterAll".split(" ") -TEST_RUN_START_EVENT = "runner:test:run:start" -TEST_RUN_END_EVENT = "runner:test:run:end" +TEST_RUN_START_EVENT = "runner:test:start" +TEST_RUN_END_EVENT = "runner:test:end" ERROR_PROPS = "message type name stack fileName lineNumber columnNumber host uncaught actual expected showDiff isPending".split(" ") RUNNABLE_LOGS = "routes agents commands".split(" ") @@ -77,8 +77,8 @@ fired = (event, runnable) -> testBeforeRunAsync = (test, Cypress) -> Promise.try -> - if not fired("runner:test:run:start:async", test) - fire("runner:test:run:start:async", test, Cypress) + if not fired("runner:test:start:async", test) + fire("runner:test:start:async", test, Cypress) runnableAfterRunAsync = (runnable, Cypress) -> Promise.try -> @@ -266,7 +266,7 @@ overrideRunnerHook = (Cypress, _runner, getTestById, getTest, setTest, getTests) return if not _runner.hook ## monkey patch the hook event so we can wrap - ## 'test:run:end' around all of + ## 'test:end' around all of ## the hooks surrounding a test runnable _runnerHook = _runner.hook @@ -442,7 +442,7 @@ afterEachFailed = (Cypress, test, err) -> test.state = "failed" test.err = wrapErr(err) - Cypress.action("runner:test:end", wrap(test)) + Cypress.action("runner:mocha:test:end", wrap(test)) hookFailed = (hook, err, hookName, getTestById, getTest) -> ## finds the test by returning the first test from @@ -460,16 +460,16 @@ hookFailed = (hook, err, hookName, getTestById, getTest) -> ## when would the hook not be emitted at this point? test.alreadyEmittedMocha = true else - Cypress.action("runner:test:end", wrap(test)) + Cypress.action("runner:mocha:test:end", wrap(test)) _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, getHookId) -> _runner.on "start", -> - Cypress.action("runner:start", { + Cypress.action("runner:mocha:start", { start: new Date() }) _runner.on "end", -> - Cypress.action("runner:end", { + Cypress.action("runner:mocha:end", { end: new Date() }) @@ -478,7 +478,7 @@ _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, _emissions.started[suite.id] = true - Cypress.action("runner:suite:start", wrap(suite)) + Cypress.action("runner:mocha:suite:start", wrap(suite)) _runner.on "suite end", (suite) -> ## cleanup our suite + its hooks @@ -489,7 +489,7 @@ _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, _emissions.ended[suite.id] = true - Cypress.action("runner:suite:end", wrap(suite)) + Cypress.action("runner:mocha:suite:end", wrap(suite)) _runner.on "hook", (hook) -> hook.hookId ?= getHookId() @@ -515,10 +515,10 @@ _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, ## will never fire if this failed in a before hook setTest(test) - Cypress.action("runner:hook:start", wrap(hook)) + Cypress.action("runner:mocha:hook:start", wrap(hook)) _runner.on "hook end", (hook) -> - Cypress.action("runner:hook:end", wrap(hook)) + Cypress.action("runner:mocha:hook:end", wrap(hook)) _runner.on "test", (test) -> setTest(test) @@ -527,17 +527,17 @@ _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, _emissions.started[test.id] = true - Cypress.action("runner:test:start", wrap(test)) + Cypress.action("runner:mocha:test:start", wrap(test)) _runner.on "test end", (test) -> return if _emissions.ended[test.id] _emissions.ended[test.id] = true - Cypress.action("runner:test:end", wrap(test)) + Cypress.action("runner:mocha:test:end", wrap(test)) _runner.on "pass", (test) -> - Cypress.action("runner:pass", wrap(test)) + Cypress.action("runner:mocha:pass", wrap(test)) ## if a test is pending mocha will only ## emit the pending event instead of the test @@ -555,12 +555,12 @@ _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, ## do not double emit this event test.alreadyEmittedMocha = true - Cypress.action("runner:pending", wrap(test)) + Cypress.action("runner:mocha:pending", wrap(test)) @emit("test", test) ## if this is not the last test amongst its siblings - ## then go ahead and fire its test:run:end event + ## then go ahead and fire its test:end event ## else this will not get called tests = getAllSiblingTests(test.parent, getTestById) @@ -592,7 +592,7 @@ _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, setTest, ## do not double emit this event runnable.alreadyEmittedMocha = true - Cypress.action("runner:fail", wrap(runnable), runnable.err) + Cypress.action("runner:mocha:fail", wrap(runnable), runnable.err) ## if we've already fired the test after run event ## it means that this runnable likely failed due to @@ -867,7 +867,7 @@ create = (specWindow, mocha, Cypress, cy) -> ## whenever any runnable is about to run ## we figure out what test its associated to ## if its a hook, and then we fire the - ## test:run:start:async action if its not + ## test:start:async action if its not ## been fired before for this test testBeforeRunAsync(test, Cypress) .catch (err) -> diff --git a/packages/driver/test/cypress/fixtures/page-events.html b/packages/driver/test/cypress/fixtures/page-events.html new file mode 100644 index 000000000000..d59373cb8c4e --- /dev/null +++ b/packages/driver/test/cypress/fixtures/page-events.html @@ -0,0 +1,12 @@ + + + + Page Events + + + Go to example.com + + + diff --git a/packages/driver/test/cypress/integration/commands/actions/check_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/check_spec.coffee index 8ac39427a3c2..453cd1c06244 100644 --- a/packages/driver/test/cypress/integration/commands/actions/check_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/check_spec.coffee @@ -126,7 +126,7 @@ describe "src/cy/commands/actions/check", -> }) .prependTo($("body")) - cy.on "command:retry", _.once (options) -> + cy.on "internal:commandRetry", _.once (options) -> expect(options.timeout).to.eq 1000 expect(options.interval).to.eq 60 done() @@ -142,7 +142,7 @@ describe "src/cy/commands/actions/check", -> chk.on "click", -> clicks += 1 - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> chk.prop("disabled", false) retried = true @@ -577,7 +577,7 @@ describe "src/cy/commands/actions/check", -> checkbox = $("").attr("id", "checkbox-covered-in-span").prop("checked", true).prependTo($("body")) span = $("span on checkbox").css(position: "absolute", left: checkbox.offset().left, top: checkbox.offset().top, padding: 5, display: "inline-block", backgroundColor: "yellow").prependTo($("body")) - cy.on "command:retry", (options) -> + cy.on "internal:commandRetry", (options) -> expect(options.timeout).to.eq 1000 expect(options.interval).to.eq 60 done() @@ -593,7 +593,7 @@ describe "src/cy/commands/actions/check", -> chk.on "click", -> clicks += 1 - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> chk.prop("disabled", false) retried = true diff --git a/packages/driver/test/cypress/integration/commands/actions/click_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/click_spec.coffee index 7ffcac0cda63..305f05e8f40e 100644 --- a/packages/driver/test/cypress/integration/commands/actions/click_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/click_spec.coffee @@ -547,7 +547,7 @@ describe "src/cy/commands/actions/click", -> cy.on "internal:scrolled", ($el, type) -> scrolled.push(type) - cy.on "command:retry", ($el, type) -> + cy.on "internal:commandRetry", ($el, type) -> retried = true $btn.on "click", -> @@ -578,7 +578,7 @@ describe "src/cy/commands/actions/click", -> cy.on "internal:scrolled", ($el, type) -> scrolled.push(type) - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $span.hide() retried = true @@ -711,7 +711,7 @@ describe "src/cy/commands/actions/click", -> retried = false - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $btn.show() retried = true @@ -727,7 +727,7 @@ describe "src/cy/commands/actions/click", -> $btn.on "click", -> clicks += 1 - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $btn.prop("disabled", false) retried = true @@ -738,7 +738,7 @@ describe "src/cy/commands/actions/click", -> it "waits until element stops animating", -> retries = 0 - cy.on "command:retry", (obj) -> + cy.on "internal:commandRetry", (obj) -> retries += 1 cy.stub(cy, "ensureElementIsNotAnimating") diff --git a/packages/driver/test/cypress/integration/commands/actions/scroll_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/scroll_spec.coffee index e5f5d3e2b9b9..f09bd9ca1f8e 100644 --- a/packages/driver/test/cypress/integration/commands/actions/scroll_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/scroll_spec.coffee @@ -268,7 +268,7 @@ describe "src/cy/commands/actions/scroll", -> retried = false - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> $container.css("overflow", "scroll") retried = true @@ -286,7 +286,7 @@ describe "src/cy/commands/actions/scroll", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> cy.$$("#scroll-into-view-horizontal").addClass("scrolled") cy @@ -303,7 +303,7 @@ describe "src/cy/commands/actions/scroll", -> cy.stub(cy, "ensureScrollability") .onFirstCall().throws(new Error) - cy.on "command:retry", -> + cy.on "internal:commandRetry", -> cy.ensureScrollability.returns() cy @@ -597,7 +597,7 @@ describe "src/cy/commands/actions/scroll", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> cy.$$("#scroll-into-view-win-vertical div").addClass("scrolled") cy diff --git a/packages/driver/test/cypress/integration/commands/actions/select_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/select_spec.coffee index ec41f2c91d0c..9cae54ac9b27 100644 --- a/packages/driver/test/cypress/integration/commands/actions/select_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/select_spec.coffee @@ -99,7 +99,7 @@ describe "src/cy/commands/actions/select", -> select = $(" is no longer disabled", -> select = cy.$$("select[name=disabled]") - cy.on "command:retry", _.once => + cy.on "internal:commandRetry", _.once => select.prop("disabled", false) cy.get("select[name=disabled]").select("foo") @@ -132,7 +132,7 @@ describe "src/cy/commands/actions/select", -> it "retries until are no longer disabled", -> select = cy.$$("select[name=opt-disabled]") - cy.on "command:retry", _.once => + cy.on "internal:commandRetry", _.once => select.find("option").prop("disabled", false) cy.get("select[name=opt-disabled]").select("bar") diff --git a/packages/driver/test/cypress/integration/commands/actions/trigger_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/trigger_spec.coffee index e6182aa9ff9b..f71894b64534 100644 --- a/packages/driver/test/cypress/integration/commands/actions/trigger_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/trigger_spec.coffee @@ -190,7 +190,7 @@ describe "src/cy/commands/actions/trigger", -> cy.on "internal:scrolled", ($el, type) -> scrolled.push(type) - cy.on "command:retry", ($el, type) -> + cy.on "internal:commandRetry", ($el, type) -> retried = true $btn.on "tap", -> @@ -221,7 +221,7 @@ describe "src/cy/commands/actions/trigger", -> cy.on "internal:scrolled", ($el, type) -> scrolled.push(type) - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $span.hide() retried = true @@ -374,7 +374,7 @@ describe "src/cy/commands/actions/trigger", -> retried = false - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $btn.show() retried = true @@ -390,7 +390,7 @@ describe "src/cy/commands/actions/trigger", -> $btn.on "mouseover", -> mouseovers += 1 - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $btn.prop("disabled", false) retried = true @@ -401,7 +401,7 @@ describe "src/cy/commands/actions/trigger", -> it "waits until element stops animating", -> retries = 0 - cy.on "command:retry", (obj) -> + cy.on "internal:commandRetry", (obj) -> retries += 1 cy.stub(cy, "ensureElementIsNotAnimating") @@ -469,7 +469,7 @@ describe "src/cy/commands/actions/trigger", -> it "eventually passes the assertion", -> $btn = cy.$$("button:first") - cy.on "command:retry", _.once -> + cy.on "internal:commandRetry", _.once -> $btn.addClass("moused-over") cy.get("button:first").trigger("mouseover").should("have.class", "moused-over").then -> diff --git a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee index 73fb8b33c07e..bd1bb98fcb53 100644 --- a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee @@ -157,7 +157,7 @@ describe "src/cy/commands/actions/type", -> retried = false - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $txt.show() retried = true @@ -173,7 +173,7 @@ describe "src/cy/commands/actions/type", -> $txt.on "click", -> clicks += 1 - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> $txt.prop("disabled", false) retried = true @@ -184,7 +184,7 @@ describe "src/cy/commands/actions/type", -> it "waits until element stops animating", -> retries = 0 - cy.on "command:retry", (obj) -> + cy.on "internal:commandRetry", (obj) -> retries += 1 cy.stub(cy, "ensureElementIsNotAnimating") @@ -1839,7 +1839,7 @@ describe "src/cy/commands/actions/type", -> } .prependTo cy.$$("body") - cy.on "command:retry", (options) -> + cy.on "internal:commandRetry", (options) -> expect(options.timeout).to.eq 1000 expect(options.interval).to.eq 60 done() @@ -2267,7 +2267,7 @@ describe "src/cy/commands/actions/type", -> it "triggers form submit synchronously before type logs or resolves", -> events = [] - cy.on "command:start", (cmd) -> + cy.on "internal:commandStart", (cmd) -> events.push "#{cmd.get('name')}:start" @$forms.find("#single-input").submit (e) -> @@ -2283,7 +2283,7 @@ describe "src/cy/commands/actions/type", -> events.push "#{log.get('name')}:log:#{state}" - cy.on "command:end", (cmd) -> + cy.on "internal:commandEnd", (cmd) -> events.push "#{cmd.get('name')}:end" cy.get("#single-input input").type("f{enter}").then -> @@ -2994,7 +2994,7 @@ describe "src/cy/commands/actions/type", -> textarea.on "click", -> clicks += 1 - cy.on "command:retry", _.after 3, -> + cy.on "internal:commandRetry", _.after 3, -> textarea.prop("disabled", false) retried = true @@ -3030,7 +3030,7 @@ describe "src/cy/commands/actions/type", -> input = $("").attr("id", "input-covered-in-span").prependTo(cy.$$("body")) span = $("span on input").css(position: "absolute", left: input.offset().left, top: input.offset().top, padding: 5, display: "inline-block", backgroundColor: "yellow").prependTo(cy.$$("body")) - cy.on "command:retry", (options) -> + cy.on "internal:commandRetry", (options) -> expect(options.timeout).to.eq 1000 expect(options.interval).to.eq 60 done() diff --git a/packages/driver/test/cypress/integration/commands/agents_spec.coffee b/packages/driver/test/cypress/integration/commands/agents_spec.coffee index 8fc8bdeb1566..bc7a852fc799 100644 --- a/packages/driver/test/cypress/integration/commands/agents_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/agents_spec.coffee @@ -238,7 +238,7 @@ describe "src/cy/commands/agents", -> expect(@myStub).to.eq(@stub) it "retries until assertions pass", -> - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => @myStub("foo") cy.get("@myStub").should("be.calledWith", "foo") @@ -301,7 +301,7 @@ describe "src/cy/commands/agents", -> it "resets unique name counter on restore", -> expect(@agentLogs[0].get("name")).to.eq("stub-1") - Cypress.emit("test:run:start", {}) + Cypress.emit("test:start", {}) cy.stub() diff --git a/packages/driver/test/cypress/integration/commands/aliasing_spec.coffee b/packages/driver/test/cypress/integration/commands/aliasing_spec.coffee index aa3ff4a02a08..9ea57b9e47d4 100644 --- a/packages/driver/test/cypress/integration/commands/aliasing_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/aliasing_spec.coffee @@ -44,7 +44,7 @@ describe "src/cy/commands/aliasing", -> it "retries primitives and assertions", -> obj = {} - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> obj.foo = "bar" cy.wrap(obj).as("obj") diff --git a/packages/driver/test/cypress/integration/commands/angular_spec.coffee b/packages/driver/test/cypress/integration/commands/angular_spec.coffee index c46ca2ec317e..76b20f57c7b7 100644 --- a/packages/driver/test/cypress/integration/commands/angular_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/angular_spec.coffee @@ -46,7 +46,7 @@ describe "src/cy/commands/angular", -> retry = _.after 2, => Cypress.stop() - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.on "test:fail", (err) -> done(err) @@ -85,7 +85,7 @@ describe "src/cy/commands/angular", -> ## wait until we're ALMOST about to time out before ## appending the missingInput - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => cy.$$("body").append(missingLi) cy.ng("repeater", "li in lis").then ($li) -> @@ -113,7 +113,7 @@ describe "src/cy/commands/angular", -> retry = _.after 2, => Cypress.stop() - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.on "test:fail", (err) -> done(err) @@ -181,7 +181,7 @@ describe "src/cy/commands/angular", -> ## wait until we're ALMOST about to time out before ## appending the missingInput - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> cy.$$("body").append(missingInput) cy.ng("model", "missing-input").then ($input) -> @@ -192,7 +192,7 @@ describe "src/cy/commands/angular", -> missingInput = $("", "data-ng-model": "missing-input") - cy.on "command:retry", _.after 6, _.once => + cy.on "internal:commandRetry", _.after 6, _.once => cy.$$("body").append(missingInput) ## we want to make sure that the ng promises do not continue @@ -226,7 +226,7 @@ describe "src/cy/commands/angular", -> retry = _.after 2, => Cypress.stop() - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.on "test:fail", (err) -> done(err) diff --git a/packages/driver/test/cypress/integration/commands/assertions_spec.coffee b/packages/driver/test/cypress/integration/commands/assertions_spec.coffee index 0ecffea0c253..f75f01734280 100644 --- a/packages/driver/test/cypress/integration/commands/assertions_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/assertions_spec.coffee @@ -49,19 +49,19 @@ describe "src/cy/commands/assertions", -> .should("have.property", "length", 1) it "skips over utility commands", -> - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => cy.$$("div:first").addClass("foo") - cy.on "command:retry", _.after 4, => + cy.on "internal:commandRetry", _.after 4, => cy.$$("div:first").attr("id", "bar") cy.get("div:first").should("have.class", "foo").debug().and("have.id", "bar") it "skips over aliasing", -> - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => cy.$$("div:first").addClass("foo") - cy.on "command:retry", _.after 4, => + cy.on "internal:commandRetry", _.after 4, => cy.$$("div:first").attr("id", "bar") cy.get("div:first").as("div").should("have.class", "foo").debug().and("have.id", "bar") @@ -107,7 +107,7 @@ describe "src/cy/commands/assertions", -> it "waits until function is true", -> button = cy.$$("button:first") - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => button.addClass("ready") cy.get("button:first").should ($button) -> @@ -116,7 +116,7 @@ describe "src/cy/commands/assertions", -> it "works with regular objects", -> obj = {} - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => obj.foo = "bar" cy.wrap(obj).should (o) -> @@ -188,7 +188,7 @@ describe "src/cy/commands/assertions", -> it "resolves eventually not exist", -> button = cy.$$("button:first") - cy.on "command:retry", _.after 2, _.once -> + cy.on "internal:commandRetry", _.after 2, _.once -> button.remove() cy.get("button:first").click().should("not.exist") @@ -266,7 +266,7 @@ describe "src/cy/commands/assertions", -> describe "have.class", -> it "snapshots and ends the assertion after retrying", -> - cy.on "command:retry", _.after 3, => + cy.on "internal:commandRetry", _.after 3, => cy.$$("#foo").addClass("active") cy.contains("foo").should("have.class", "active").then -> @@ -284,7 +284,7 @@ describe "src/cy/commands/assertions", -> retry = _.after 3, -> button.addClass("new-class") - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.get("button:first").should("have.class", "new-class") @@ -357,7 +357,7 @@ describe "src/cy/commands/assertions", -> button = cy.$$("button:first") - cy.on "command:retry", _.after 2, _.once -> + cy.on "internal:commandRetry", _.after 2, _.once -> button.addClass("foo").remove() cy.on "test:fail", (err) => @@ -837,7 +837,7 @@ describe "src/cy/commands/assertions", -> length = buttons.length - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => cy.$$("button:last").remove() cy.wrap(buttons).should("have.length", length - 1) diff --git a/packages/driver/test/cypress/integration/commands/clock_spec.coffee b/packages/driver/test/cypress/integration/commands/clock_spec.coffee index 5d0e5365e366..3c391e532102 100644 --- a/packages/driver/test/cypress/integration/commands/clock_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/clock_spec.coffee @@ -55,7 +55,7 @@ describe "src/cy/commands/clock", -> cy.clock().then (clock) -> r = cy.spy(clock, "restore") - Cypress.emit("test:run:start", {}) + Cypress.emit("test:start", {}) expect(r).to.be.called @@ -152,7 +152,7 @@ describe "src/cy/commands/clock", -> } } cy.clock(null, ["setTimeout"]).then (clock) => - Cypress.emit("page:start", newWindow) + Cypress.emit("page:start", { win: newWindow }) onSetTimeout = cy.spy() newWindow.setTimeout(onSetTimeout) clock.tick() @@ -195,7 +195,7 @@ describe "src/cy/commands/clock", -> it "does not log when auto-restored", (done) -> cy.clock().then => - Cypress.emit("test:run:start", {}) + Cypress.emit("test:start", {}) expect(@logs.length).to.equal(1) done() diff --git a/packages/driver/test/cypress/integration/commands/connectors_spec.coffee b/packages/driver/test/cypress/integration/commands/connectors_spec.coffee index 953f7829bde2..efb9cc06b68d 100644 --- a/packages/driver/test/cypress/integration/commands/connectors_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/connectors_spec.coffee @@ -204,18 +204,18 @@ describe "src/cy/commands/connectors", -> return "foo" - it "unbinds command:enqueued in the case of an error thrown", (done) -> + it "unbinds internal:commandEnqueue in the case of an error thrown", (done) -> listeners = [] cy.on "test:fail", (err) => - listeners.push(cy.listeners("command:enqueued").length) + listeners.push(cy.listeners("internal:commandEnqueue").length) expect(@logs.length).to.eq(1) expect(listeners).to.deep.eq([1, 0]) done() cy.then -> - listeners.push(cy.listeners("command:enqueued").length) + listeners.push(cy.listeners("internal:commandEnqueue").length) throw new Error("foo") @@ -260,7 +260,7 @@ describe "src/cy/commands/connectors", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => @remoteWindow.$.fn.foo = -> "foo" cy.get("div:first").invoke("foo").should("eq", "foo").then -> @@ -271,7 +271,7 @@ describe "src/cy/commands/connectors", -> expect(lastLog.get("ended")).to.be.true it "eventually fails the assertion", (done) -> - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => @remoteWindow.$.fn.foo = -> "foo" cy.on "test:fail", (err) => diff --git a/packages/driver/test/cypress/integration/commands/cookies_spec.coffee b/packages/driver/test/cypress/integration/commands/cookies_spec.coffee index 7d29dbfdf0c8..0d6e6cfec59e 100644 --- a/packages/driver/test/cypress/integration/commands/cookies_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/cookies_spec.coffee @@ -7,7 +7,7 @@ describe "src/cy/commands/cookies", -> cy.stub(Cypress, "automation").callThrough() - context "test:run:start:async", -> + context "test:start:async", -> it "clears cookies before each test run", -> Cypress.automation .withArgs("get:cookies", { domain: "localhost" }) @@ -15,7 +15,7 @@ describe "src/cy/commands/cookies", -> .withArgs("clear:cookies", [ { domain: "localhost", name: "foo" } ]) .resolves([]) - Cypress.emitThen("test:run:start:async", {}) + Cypress.emitThen("test:start:async", {}) .then -> expect(Cypress.automation).to.be.calledWith( "get:cookies", @@ -30,7 +30,7 @@ describe "src/cy/commands/cookies", -> it "does not call clear:cookies when get:cookies returns empty array", -> Cypress.automation.withArgs("get:cookies").resolves([]) - Cypress.emitThen("test:run:start:async", {}) + Cypress.emitThen("test:start:async", {}) .then -> expect(Cypress.automation).not.to.be.calledWith( "clear:cookies" @@ -45,7 +45,7 @@ describe "src/cy/commands/cookies", -> timeout = cy.spy(Promise.prototype, "timeout") - Cypress.emitThen("test:run:start:async", {}) + Cypress.emitThen("test:start:async", {}) .then -> expect(timeout).not.to.be.called diff --git a/packages/driver/test/cypress/integration/commands/files_spec.coffee b/packages/driver/test/cypress/integration/commands/files_spec.coffee index 9914df6320cd..b63dd5967491 100644 --- a/packages/driver/test/cypress/integration/commands/files_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/files_spec.coffee @@ -43,7 +43,7 @@ describe "src/cy/commands/files", -> retries = 0 - cy.on "command:retry", -> + cy.on "internal:commandRetry", -> retries += 1 Cypress.backend.withArgs("read:file") @@ -58,7 +58,7 @@ describe "src/cy/commands/files", -> it "retries assertions until they pass", -> retries = 0 - cy.on "command:retry", -> + cy.on "internal:commandRetry", -> retries += 1 Cypress.backend.withArgs("read:file") diff --git a/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee b/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee index 2b5f61982818..5adc315f3b1d 100644 --- a/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/local_storage_spec.coffee @@ -27,11 +27,11 @@ describe "src/cy/commands/local_storage", -> cy.clearLocalStorage().then (remote) -> expect(remote).to.eq ls - describe "test:run:start", -> + describe "test:start", -> it "clears localStorage before each test run", -> clear = cy.spy Cypress.LocalStorage, "clear" - Cypress.emit("test:run:start", {}) + Cypress.emit("test:start", {}) expect(clear).to.be.calledWith [] diff --git a/packages/driver/test/cypress/integration/commands/location_spec.coffee b/packages/driver/test/cypress/integration/commands/location_spec.coffee index 205a7878e0a1..a4e547a93b9c 100644 --- a/packages/driver/test/cypress/integration/commands/location_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/location_spec.coffee @@ -34,7 +34,7 @@ describe "src/cy/commands/location", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, _.once => + cy.on "internal:commandRetry", _.after 2, _.once => win = cy.state("window") win.location.href = "/foo/bar/baz.html" @@ -149,7 +149,7 @@ describe "src/cy/commands/location", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, => + cy.on "internal:commandRetry", _.after 2, => win = cy.state("window") win.location.hash = "users/1" @@ -268,7 +268,7 @@ describe "src/cy/commands/location", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, _.once => + cy.on "internal:commandRetry", _.after 2, _.once => win = cy.state("window") win.location.pathname = "users/1" diff --git a/packages/driver/test/cypress/integration/commands/misc_spec.coffee b/packages/driver/test/cypress/integration/commands/misc_spec.coffee index 179ff20fbf29..1eec5de8eedf 100644 --- a/packages/driver/test/cypress/integration/commands/misc_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/misc_spec.coffee @@ -77,7 +77,7 @@ describe "src/cy/commands/misc", -> $("
  • appended
  • ").appendTo cy.$$("#list") , 50 - cy.on "command:retry", _.after(2, _.once(append)) + cy.on "internal:commandRetry", _.after(2, _.once(append)) cy.get("#list").then ($ul) -> diff --git a/packages/driver/test/cypress/integration/commands/navigation_spec.coffee b/packages/driver/test/cypress/integration/commands/navigation_spec.coffee index ad73e5fadf81..d694736d1021 100644 --- a/packages/driver/test/cypress/integration/commands/navigation_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/navigation_spec.coffee @@ -569,7 +569,7 @@ describe "src/cy/commands/navigation", -> describe "when origins don't match", -> beforeEach -> - Cypress.emit("test:run:start", { id: 888 }) + Cypress.emit("test:start", { id: 888 }) cy.stub(Cypress, "getEmissions").returns([]) cy.stub(Cypress, "getTestsState").returns([]) @@ -1409,7 +1409,7 @@ describe "src/cy/commands/navigation", -> it "does not time out current commands until stability is reached", -> ## on the first retry cause a page load event synchronously - cy.on "command:retry", (options) -> + cy.on "internal:commandRetry", (options) -> switch options._retries when 1 win = cy.state("window") @@ -1495,7 +1495,7 @@ describe "src/cy/commands/navigation", -> log.get("name") is name cy.on "test:fail", (err) -> - cy.on "command:retry", -> + cy.on "internal:commandRetry", -> throw new Error("should not have retried twice") expect(err.message).to.include("Expected to find element") @@ -1513,7 +1513,7 @@ describe "src/cy/commands/navigation", -> start = null ## on the first retry cause a page load event synchronously - cy.on "command:retry", (options) -> + cy.on "internal:commandRetry", (options) -> switch options._retries when 1 ## hold a ref to this diff --git a/packages/driver/test/cypress/integration/commands/querying_spec.coffee b/packages/driver/test/cypress/integration/commands/querying_spec.coffee index 1fa091d37a76..56d2b5fd205a 100644 --- a/packages/driver/test/cypress/integration/commands/querying_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/querying_spec.coffee @@ -41,7 +41,7 @@ describe "src/cy/commands/querying", -> return null it "eventually passes the assertion", -> - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> cy.$$(":text:first").addClass("focused").focus() cy.focused().should("have.class", "focused").then -> @@ -55,7 +55,7 @@ describe "src/cy/commands/querying", -> it "retries on an elements value", -> $input = cy.$$("input:first") - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> $input.val("1234") $input.get(0).focus() @@ -250,13 +250,13 @@ describe "src/cy/commands/querying", -> cy.get("input:first").then ($input) -> expect($input.get(0)).to.eq input.get(0) - it "removes command:start listeners after within is over", -> + it "removes internal:commandStart listeners after within is over", -> cy.get("#button-text").within -> cy.get("button").within -> cy.get("span") cy.then -> - expect(cy._events).not.to.have.property "command:start" + expect(cy._events).not.to.have.property "internal:commandStart" it "clears withinSubject even if next is null", (done) -> span = cy.$$("#button-text button span") @@ -345,7 +345,7 @@ describe "src/cy/commands/querying", -> cy.get("body").within(value) it "throws when subject is not in the document", (done) -> - cy.on "command:end", => + cy.on "internal:commandEnd", => cy.$$("#list").remove() cy.on "test:fail", (err) -> @@ -447,7 +447,7 @@ describe "src/cy/commands/querying", -> ## wait until we're ALMOST about to time out before ## appending the missingEl - cy.on "command:retry", (options) => + cy.on "internal:commandRetry", (options) => if options.total + (options._interval * 4) > options._runnableTimeout cy.$$("body").append(missingEl) @@ -457,7 +457,7 @@ describe "src/cy/commands/querying", -> it "can increase the timeout", -> missingEl = $("
    ", id: "missing-el") - cy.on "command:retry", _.after 2, (options) -> + cy.on "internal:commandRetry", _.after 2, (options) -> ## make sure runnableTimeout is 10secs expect(options._runnableTimeout).to.eq 10000 @@ -469,7 +469,7 @@ describe "src/cy/commands/querying", -> it "does not factor in the total time the test has been running", -> missingEl = $("
    ", id: "missing-el") - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> cy.$$("body").append(missingEl) ## in this example our test has been running 200ms @@ -498,7 +498,7 @@ describe "src/cy/commands/querying", -> done() , 100 - cy.on "command:retry", -> + cy.on "internal:commandRetry", -> retrys += 1 stop() @@ -533,7 +533,7 @@ describe "src/cy/commands/querying", -> Cypress.config("defaultCommandTimeout", 1000) it "waits until button exists", -> - cy.on "command:retry", _.after 3, => + cy.on "internal:commandRetry", _.after 3, => cy.$$("body").append $("
    missing el
    ") cy.get("#missing-el").should("exist") @@ -542,7 +542,7 @@ describe "src/cy/commands/querying", -> it "waits until button does not exist", -> cy.timeout(500, true) - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> cy.$$("#button").remove() cy.get("#button").should("not.exist") @@ -558,7 +558,7 @@ describe "src/cy/commands/querying", -> retry = _.after 3, => cy.$$("#list li:last").remove() - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.get("#list li:last").should("not.exist").then ($el) -> expect($el).to.be.null @@ -589,7 +589,7 @@ describe "src/cy/commands/querying", -> retry = _.after 3, => button = cy.$$("#button").hide() - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.get("#button").should("not.be.visible").then ($button) -> expect($button.get(0)).to.eq button.get(0) @@ -610,7 +610,7 @@ describe "src/cy/commands/querying", -> retry = _.after 3, => button.show() - cy.on "command:retry", retry + cy.on "internal:commandRetry", retry cy.get("#button").should("be.visible").then ($button) -> expect($button.get(0)).to.eq button.get(0) @@ -630,7 +630,7 @@ describe "src/cy/commands/querying", -> length = buttons.length - 2 - cy.on "command:retry", _.after 2, -> + cy.on "internal:commandRetry", _.after 2, -> buttons.last().remove() buttons = cy.$$("button") @@ -647,7 +647,7 @@ describe "src/cy/commands/querying", -> length = buttons.length + 1 ## add another button after 2 retries, once - cy.on "command:retry", _.after 2, _.once => + cy.on "internal:commandRetry", _.after 2, _.once => $("