Skip to content

add partial to warn people that code in plugin file runs in Node #3686

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

Merged
merged 5 commits into from
Mar 15, 2021
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
3 changes: 3 additions & 0 deletions source/_partial/code_runs_in_node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% note warning %}
⚠️ This code is part of the [plugin file](/guides/core-concepts/writing-and-organizing-tests.html#Plugin-files) and thus executes in the Node environment. You cannot call `Cypress` or `cy` commands in this file, but you do have the direct access to the file system and the rest of the operating system.
{% endnote %}
2 changes: 2 additions & 0 deletions source/api/plugins/after-run-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The event will fire each time `cypress run` executes. As a result, if running yo

# Syntax

{% partial code_runs_in_node %}

```js
on('after:run', (results) => { /* ... */ })
```
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/after-screenshot-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This allows you to record those details, manipulate the image as needed, and ret

# Syntax

{% partial code_runs_in_node %}

```js
on('after:screenshot', (details) => { /* ... */ })
```
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/after-spec-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The `after:spec` event fires after a spec file is run. The event only fires when

# Syntax

{% partial code_runs_in_node %}

```js
on('after:spec', (spec, results) => { /* ... */ })
```
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/before-run-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The event will fire each time `cypress run` executes. As a result, if running yo

# Syntax

{% partial code_runs_in_node %}

```js
on('before:run', (details) => { /* ... */ })
```
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/before-spec-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The `before:spec` event fires before a spec file is run. The event only fires wh

# Syntax

{% partial code_runs_in_node %}

```js
on('before:spec', (spec) => { /* ... */ })
```
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/browser-launch-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Before Cypress launches a browser, it gives you the opportunity to modify the br

# Syntax

{% partial code_runs_in_node %}

```js
on('before:browser:launch', (browser = {}, launchOptions) => { /* ... */ })
```
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/configuration-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Cypress enables you to dynamically modify configuration values and environment v

# Usage

{% partial code_runs_in_node %}

To modify configuration, you return an object from your plugins file exported function.

```javascript
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/preprocessors-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ If you don't use webpack in your project or would like to keep the majority of t

# Usage

{% partial code_runs_in_node %}

To use a preprocessor, you should bind to the `file:preprocessor` event in your {% url "`pluginsFile`" configuration#Folders-Files %}:

```javascript
Expand Down
2 changes: 2 additions & 0 deletions source/api/plugins/writing-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = (on, config) => {
}
```

{% partial code_runs_in_node %}

The exported function is called whenever a project is opened either with {% url "`cypress open`" command-line#cypress-open %} or {% url "`cypress run`" command-line#cypress-run %}.

Your function will receive 2 arguments: `on` and `config`.
Expand Down
6 changes: 3 additions & 3 deletions source/guides/core-concepts/writing-and-organizing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ To learn more about videos and settings available, see {% url "Screenshots and V

## Plugin files

By default Cypress will automatically include the plugins file `cypress/plugins/index.js` **before** every single spec file it runs. We do this purely as a convenience mechanism so you don't have to import this file in every single one of your spec files.
The plugin file is a special file that executes in Node before the project is loaded, before the browser launches, and during your test execution. While the Cypress tests execute in the browser, the plugin file runs in the background Node process, giving your tests the ability to access the file system and the rest of the operating system by calling the {% url "cy.task()" task %} command.

The initial imported plugins file can be {% url 'configured to another file' configuration#Folders-Files %}.
The plugin file is a good place to define how you want to bundle the spec files via the {% url "preprocessors" preprocessors-api %}, how to find and launch the browsers via the {% url "browser launch API" browser-launch-api %}, and other cool things. Read our {% url "plugins guide" plugins-guide %} for more details and examples.

{% url "Read more about using plugins to extend Cypress behavior." plugins-guide %}
The initial imported plugins file can be {% url 'configured to another file' configuration#Folders-Files %}.

## Support file

Expand Down
2 changes: 2 additions & 0 deletions source/guides/tooling/plugins-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ You can use the `task` event to do things like:

The {% url "Real World App (RWA)" https://github.com/cypress-io/cypress-realworld-app %} uses {% url tasks task %} to re-seed its database, and to filter/find test data for various testing scenarios.

{% partial code_runs_in_node %}

```ts
// cypress/plugins/index.ts

Expand Down