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

Updates for events overhaul #967

Closed
wants to merge 86 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
8d4076c
plugins / events overhaul
chrisbreiding Sep 13, 2018
addaef6
fix tests
chrisbreiding Sep 13, 2018
97d0976
add migration guide
chrisbreiding Sep 17, 2018
0ed36cc
Merge branch 'develop' into issue-890-background-updates
chrisbreiding Sep 17, 2018
1f8188c
fix tests
chrisbreiding Sep 17, 2018
76587c0
update events docs per Rich’s excellent feedback
chrisbreiding Sep 17, 2018
e405bc8
Merge branch 'develop' into issue-890-background-updates
jennifer-shehane Sep 18, 2018
e1c8ed0
update api test to not use first link in sidebar
jennifer-shehane Sep 18, 2018
cf5a2fe
Minor updates for Background Process page
jennifer-shehane Sep 18, 2018
c62054f
package-lock
jennifer-shehane Sep 18, 2018
73d805d
more minor changes to pages
jennifer-shehane Sep 18, 2018
7510fc7
Normalize titles + 'environments' of each event page
jennifer-shehane Sep 18, 2018
f883941
Normalize arguments across event pages
jennifer-shehane Sep 18, 2018
b223e87
Normalize usage across all event docs
jennifer-shehane Sep 18, 2018
62856f7
Add 'See also' links to every event page
jennifer-shehane Sep 18, 2018
2d96f81
revert changelog changes / convert obselete urls to plain text
chrisbreiding Sep 18, 2018
8fba26e
missed an obsolete changelog url
chrisbreiding Sep 18, 2018
3e4007e
fix urls
chrisbreiding Sep 18, 2018
d780c3d
note default location of background and file and configurabiliity
chrisbreiding Sep 18, 2018
1753661
fixes for grammar / consistency
chrisbreiding Sep 18, 2018
556352f
fix tests
chrisbreiding Sep 18, 2018
241bc48
remove links in event files to own doc
jennifer-shehane Sep 19, 2018
51de0fa
Fix padding of th to match td, add style for grey icon if we want it
jennifer-shehane Sep 19, 2018
fc7d90e
fix link
chrisbreiding Sep 19, 2018
556cb51
set up aliases for moved pages
chrisbreiding Sep 19, 2018
e480cbe
Merge branch 'develop' into issue-890-background-updates
jennifer-shehane Sep 24, 2018
caacdc7
package-lock
jennifer-shehane Sep 24, 2018
a22faf1
remove conflict
jennifer-shehane Sep 24, 2018
87081da
Add more context to 'environment' section of events
jennifer-shehane Sep 24, 2018
de8b33b
package-lock changes
chrisbreiding Nov 2, 2018
033d3a0
add error message for mocha overspecified error
chrisbreiding Nov 2, 2018
171386b
Merge branch 'develop' into issue-890-background-updates
chrisbreiding Nov 6, 2018
d2866df
ensure api sidebar doesn’t expand all
chrisbreiding Nov 13, 2018
5f68a77
fix typo
chrisbreiding Nov 13, 2018
28d8305
change Catalog of Events to All Events
chrisbreiding Nov 15, 2018
189ca2c
fix references to old events
chrisbreiding Nov 15, 2018
253cad5
split up events table into two tables
chrisbreiding Nov 15, 2018
0cb9aa7
fix event environment table layout
chrisbreiding Nov 15, 2018
e199d1c
update ‘remote page’ to ‘page’
chrisbreiding Nov 16, 2018
967ad6b
Add Chai changes to migration guide
lilaconlee Nov 30, 2018
7ecc59e
Merge branch 'develop' into issue-890-background-updates
jennifer-shehane Dec 3, 2018
f1cb1e1
Merge branch 'develop' into issue-890-background-updates
lilaconlee Dec 3, 2018
37ca0be
Add sinon upgrade notes to migration guide
lilaconlee Dec 3, 2018
939dd55
Merge branch 'issue-890-background-updates' of github.com:cypress-io/…
chrisbreiding Jan 23, 2019
44868ce
Merge branch 'develop' into issue-890-background-updates
chrisbreiding Jan 23, 2019
aafab54
package-lock changes
chrisbreiding Jan 23, 2019
e60a482
window:alert -> page:alert
chrisbreiding Jan 23, 2019
0540642
window:confirm -> page:confirm
chrisbreiding Jan 23, 2019
3202028
before:window:load -> page:start
chrisbreiding Jan 23, 2019
36f02b0
add changed events to migration guide
chrisbreiding Jan 23, 2019
caf248c
window:load -> page:ready
chrisbreiding Jan 23, 2019
56b60e1
window:unload -> page:end
chrisbreiding Jan 23, 2019
f9532c7
update page events with updated arguments
chrisbreiding Jan 23, 2019
f99ff43
url:changed -> page:urlChange
chrisbreiding Jan 23, 2019
dd34701
file:preprocessor -> browser:filePreprocessor
chrisbreiding Jan 23, 2019
a9aa125
before:browser:launch -> browser:launch
chrisbreiding Jan 23, 2019
e9eb6d9
command:end -> internal:commandEnd
chrisbreiding Jan 25, 2019
645955b
command:enqueued -> internal:commandEnqueue
chrisbreiding Jan 25, 2019
b337703
command:retry -> internal:commandRetry
chrisbreiding Jan 25, 2019
295b44d
command:start -> internal:commandStart
chrisbreiding Jan 25, 2019
7590994
before:test:run -> test:start
chrisbreiding Jan 25, 2019
4de2f7a
after:test:run -> test:end
chrisbreiding Jan 25, 2019
342669f
before:run -> run:start
chrisbreiding Jan 25, 2019
58f22d6
after:run -> run:end
chrisbreiding Jan 25, 2019
a291c2a
after:screenshot -> screenshot
chrisbreiding Jan 25, 2019
e1ff757
before:spec -> spec:start
chrisbreiding Jan 25, 2019
9a9c507
after:spec -> spec:end
chrisbreiding Jan 25, 2019
7a25654
before:test:run -> test:start
chrisbreiding Jan 25, 2019
a5c1452
fail -> test:fail
chrisbreiding Jan 25, 2019
468ac1f
viewport:changed -> viewport:change
chrisbreiding Jan 25, 2019
0a35710
format table
chrisbreiding Jan 25, 2019
75f2934
update migration guide with details about background process
chrisbreiding Jan 25, 2019
b2f918b
fix api spec
chrisbreiding Jan 25, 2019
4797ab9
fix event names / re-alphabetize
chrisbreiding Jan 25, 2019
f2c64a3
fix file name
chrisbreiding Jan 25, 2019
f8836d7
fix file names
chrisbreiding Jan 25, 2019
7777a20
Merge branch 'develop' into issue-890-background-updates
chrisbreiding Jan 25, 2019
60f1fdc
log:added -> internal:log
chrisbreiding Feb 6, 2019
d7a0dea
log:changed -> internal:logChange
chrisbreiding Feb 6, 2019
161dcff
alphabetize
chrisbreiding Feb 6, 2019
97ac201
Merge pull request #1404 from cypress-io/issue-1387-log-event-changes
chrisbreiding Feb 6, 2019
4f6edc2
Merge branch 'develop' into issue-890-background-updates
chrisbreiding Feb 7, 2019
2b1c475
Merge branch 'issue-890-background-updates' into issue-1077-mocha-ove…
chrisbreiding Feb 7, 2019
56dbe84
move mocha promise/done callback section to migration guide
chrisbreiding Feb 7, 2019
38c1ee9
Merge pull request #1105 from cypress-io/issue-1077-mocha-overspecifi…
chrisbreiding Feb 7, 2019
79ca22c
Merge branch 'develop' into issue-890-background-updates
chrisbreiding Mar 22, 2019
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
2 changes: 1 addition & 1 deletion cypress/integration/api_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ API_PATH = "/api/introduction/api"
API_HTML = API_PATH + '.html'

FIRST_PAGE = "api.html"
NEXT_PAGE = "catalog-of-events.html"
NEXT_PAGE = "and.html"

describe "API", ->
context "Catalog of events", ->
Expand Down
41 changes: 32 additions & 9 deletions source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ guides:
web-security: web-security.html
tooling:
intelligent-code-completion: intelligent-code-completion.html
plugins-guide: plugins-guide.html
background-process: background-process.html
reporters: reporters.html
typescript-support: typescript-support.html

Expand All @@ -51,14 +51,13 @@ guides:
trade-offs: trade-offs.html
# contributing: contributing.html
changelog: changelog.html
migration-guide: migration-guide.html
roadmap: roadmap.html
# all-videos: all-videos.html

api:
introduction:
api: api.html
events:
catalog-of-events: catalog-of-events.html
assertions:
all-assertions: assertions.html
commands:
Expand Down Expand Up @@ -149,6 +148,36 @@ api:
minimatch: minimatch.html
moment: moment.html
promise: promise.html
events:
catalog-of-events: catalog-of-events.html
after-screenshot-event: after-screenshot-event.html
after-run-event: after-run-event.html
after-spec-event: after-spec-event.html
after-test-run-event: after-test-run-event.html
before-browser-launch-event: before-browser-launch-event.html
before-run-event: before-run-event.html
before-spec-event: before-spec-event.html
before-test-run-event: before-test-run-event.html
before-window-load-event: before-window-load-event.html
before-window-unload-event: before-window-unload-event.html
command-end-event: command-end-event.html
command-enqueued-event: command-enqueued-event.html
command-retry-event: command-retry-event.html
command-start-event: command-start-event.html
configuration-event: configuration-event.html
fail-event: fail-event.html
file-preprocessor-event: file-preprocessor-event.html
log-added-event: log-added-event.html
log-changed-event: log-changed-event.html
scrolled-event: scrolled-event.html
task-event: task-event.html
uncaught-exception-event: uncaught-exception-event.html
url-changed-event: url-changed-event.html
viewport-changed-event: viewport-changed-event.html
window-alert-event: window-alert-event.html
window-confirm-event: window-confirm-event.html
window-load-event: window-load-event.html
window-unload-event: window-unload-event.html
cypress-api:
custom-commands: custom-commands.html
cookies: cookies.html
Expand All @@ -164,12 +193,6 @@ api:
platform: platform.html
spec: spec.html
version: version.html
plugins:
writing-a-plugin: writing-a-plugin.html
configuration-api: configuration-api.html
preprocessors-api: preprocessors-api.html
browser-launch-api: browser-launch-api.html
after-screenshot-api: after-screenshot-api.html

plugins:
plugins: index.html
Expand Down
6 changes: 3 additions & 3 deletions source/api/commands/screenshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ describe('my tests', function () {
})
```

## `after:screenshot` plugin event
## `after:screenshot` background event

You can get details about any given screenshot and manipulate it after it has been written to disk with the {% url '`after:screenshot` plugin event' after-screenshot-api %}.
You can get details about any given screenshot and manipulate it after it has been written to disk with the {% url '`after:screenshot` background event' after-screenshot-event %}.

## Test Failures

Expand Down Expand Up @@ -247,7 +247,7 @@ When clicking on `screenshot` within the command log, the console outputs the fo
# See also

- {% url `Cypress.Screenshot` screenshot-api %}
- {% url 'After Screenshot API' after-screenshot-api %}
- {% url '`after:screenshot` event' after-screenshot-event %}
- {% url `cy.debug()` debug %}
- {% url 'Dashboard Service' dashboard-service %}
- {% url 'Screenshots and Videos' screenshots-and-videos %}
Expand Down
48 changes: 19 additions & 29 deletions source/api/commands/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
title: task
---

Execute code in {% url "Node.js" https://nodejs.org %} via the `task` plugin event.
Execute code in {% url "Node.js" https://nodejs.org %} via the {% url "`task` background event" task-event %}.

{% note warning 'Anti-Pattern' %}
We do not recommend starting a web server using `cy.task()`. Read about {% url 'best practices' best-practices#Web-Servers %} here.
We do not recommend starting a web server using `cy.task()`. Read more about {% url "the `task` background event" task-event#Notes %} and about {% url 'best practices' best-practices#Web-Servers %}.
{% endnote %}

# Syntax
Expand All @@ -24,8 +24,9 @@ cy.task(event, arg, options)
// in test
cy.task('log', 'This will be output to the terminal')
```

```javascript
// in plugins file
// in background file
on('task', {
log (message) {
console.log(message)
Expand All @@ -38,7 +39,7 @@ on('task', {

**{% fa fa-angle-right %} event** ***(String)***

An event name to be handled via the `task` event in the {% url "`pluginsFile`" configuration#Folders-Files %}.
An event name to be handled via the {% url "`task` event" task-event %} in the {% url "`backgroundFile`" configuration#Folders-Files %}.

**{% fa fa-angle-right %} arg** ***(Object)***

Expand All @@ -55,7 +56,7 @@ Option | Default | Description

## Yields {% helper_icon yields %}

`cy.task()` yields the value returned or resolved by the `task` event in the {% url "`pluginsFile`" configuration#Folders-Files %}.
`cy.task()` yields the value returned or resolved by the `task` event in the {% url "`backgroundFile`" configuration#Folders-Files %}.

# Examples

Expand All @@ -68,9 +69,9 @@ Option | Default | Description
- Performing parallel tasks, like making multiple http requests outside of Cypress.
- Running an external process.

In the `task` plugin event, the command will fail if `undefined` is returned. This helps catch typos or cases where the task event is not handled.
In the {% url "`task` background event" task-event %}, the command will fail if `undefined` is returned. It will also fail if you return a promise that resolves `undefined`. This helps catch typos or cases where the task event is not handled.

If you do not need to return a value, explicitly return `null` to signal that the given event has been handled.
If you do not need to return a value, explicitly return or resolve `null` to signal that the given event has been handled.

### Read a JSON file's contents

Expand All @@ -88,11 +89,13 @@ cy.task('readJson', 'cypress.json').then((data) => {
```

```javascript
// in plugins/index.js file
// in background/index.js file
const fs = require('fs-extra')

on('task', {
readJson: (filename) => {
// reads the file relative to current working directory
return fsExtra.readJson(path.join(process.cwd(), filename)
return fs.readJson(path.join(process.cwd(), filename)
}
})
```
Expand All @@ -103,7 +106,7 @@ on('task', {
// in test
describe('e2e', () => {
beforeEach(() => {
cy.task('defaults:db')
cy.task('seed:database')
cy.visit('/')
})

Expand All @@ -115,15 +118,15 @@ describe('e2e', () => {
```

```javascript
// in plugins/index.js file
// in background/index.js file
// we require some code in our app that
// is responsible for seeding our database
const db = require('../../server/src/db')
const database = require('../../app/database')

module.exports = (on, config) => {
on('task', {
'defaults:db': () => {
return db.seed('defaults')
'seed:database': () => {
return database.seed()
}
})
}
Expand All @@ -142,20 +145,6 @@ Cypress will *not* continue running any other commands until `cy.task()` has fin
cy.task('seedDatabase', null, { timeout: 20000 });
```

# Notes

## Tasks must end

### Tasks that do not end are not supported

`cy.task()` does not support tasks that do not end, such as:

- Starting a server.
- A task that watches for file changes.
- Any process that needs to be manually interrupted to stop.

A task must end within the `taskTimeout` or Cypress will fail the current test.

# Rules

## Requirements {% helper_icon requirements %}
Expand Down Expand Up @@ -184,10 +173,11 @@ The command above will display in the command log as:

When clicking on the `task` command within the command log, the console outputs the following:

![console.log task](/img/api/task/console-shows-task-result.png)
![console.log task](/img/api/task/console-shresult.png)
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved

# See also

- {% url "`task` event" task-event %}
- {% url `cy.exec()` exec %}
- {% url `cy.fixture()` fixture %}
- {% url `cy.readFile()` readfile %}
Expand Down
6 changes: 3 additions & 3 deletions source/api/commands/trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: trigger

---

Trigger an event on a DOM element.
Trigger an event on a DOM element.

# Syntax

Expand Down Expand Up @@ -88,9 +88,9 @@ cy.get('.target').trigger('mousedown')
cy.wait(1000)
cy.get('.target').trigger('mouseleave')
```
### jQuery UI Sortable
### jQuery UI Sortable

To simulate drag and drop using jQuery UI sortable requires `pageX` and `pageY` properties along with `which:1`.
To simulate drag and drop using jQuery UI sortable requires `pageX` and `pageY` properties along with `which:1`.

```javascript
cy.get('[data-cy=draggable]')
Expand Down
48 changes: 48 additions & 0 deletions source/api/events/after-run-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: after:run Event
---

The `after:run` event fires after the run finishes.

# Environment

Occurs only in the {% url "background process" background-process %}.

# Arguments

* run results **(Object)**

# Usage

```javascript
// cypress/background/index.js

module.exports = (on, config) => {
on('after:run', (results) => {
// results will look something like this:
// {
// totalDuration: 81,
// totalSuites: 0,
// totalTests: 1,
// totalFailed: 0,
// totalPassed: 1,
// totalPending: 0,
// totalSkipped: 0,
// browserName: 'electron',
// browserVersion: '59.0.3071.115',
// osName: 'darwin',
// osVersion: '16.7.0',
// cypressVersion: '3.1.0',
// config: {
// projectId: '1qv3w7',
// baseUrl: 'http://example.com',
// viewportWidth: 1000,
// viewportHeight: 660,
// // more properties...
// }
// // ... more properties...
// }
// }
})
}
```
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
---
title: After Screenshot API
title: after:screenshot event
---

After a screenshot is taken, you can get details about the screenshot via the `after:screenshot` plugin event. This event is called whether a screenshot is taken with {% url `cy.screenshot()` screenshot %} or as a result of a test failure. The event is called after the screenshot image is written to disk.
After a screenshot is taken, you can get details about the screenshot via the `after:screenshot` background event. This event is called whether a screenshot is taken with {% url `cy.screenshot()` screenshot %} or as a result of a test failure. The event is called after the screenshot image is written to disk.

This allows you to record those details or manipulate the image as needed. You can also return updated details about the image.

# Environment

Occurs only in the {% url "background process" background-process %}.

# Arguments

* screenshot details **(Object)**

# Usage

Using your {% url "`pluginsFile`" plugins-guide %} you can tap into the `after:screenshot` event.
Using your {% url "`backgroundFile`" background-process %} you can tap into the `after:screenshot` event.

```js
// cypress/plugins/index.js
// cypress/background/index.js

const fs = require('fs')

Expand Down
57 changes: 57 additions & 0 deletions source/api/events/after-spec-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: after:spec Event
---

The `after:spec` event fires after a spec file and its tests run.

# Environment

Occurs only in the {% url "background process" background-process %}.

# Arguments

* spec **(Object)**
* spec results **(Object)**

# Usage

```javascript
// cypress/background/index.js

module.exports = (on, config) => {
on('after:spec', (spec, results) => {
// spec will look something like this:
// {
// name: 'login_spec.js',
// relative: 'cypress/integration/login_spec.js',
// absolute: '/Users/janelane/app/cypress/integration/login_spec.js',
// }

// results will look something like this:
// {
// stats: {
// suites: 0,
// tests: 1,
// passes: 1,
// pending: 0,
// skipped: 0,
// failures: 0,
// // ...more properties
// }
// reporter: 'spec',
// tests: [
// {
// title: ['login', 'logs user in'],
// state: 'passed',
// body: 'function () {}',
// // ...more properties...
// }
// ],
// error: null,
// video: '/Users/janelane/app/cypress/videos/passing_spec.js.mp4',
// screenshots: [],
// // ...more properties...
// }
})
}
```
Loading