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

docs: document mode argument to plugins #3693

Merged
merged 9 commits into from
Mar 29, 2021
1 change: 1 addition & 0 deletions content/_data/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
"configuration-api": "Configuration",
"version": "version",
"arch": "arch",
"testing-type": "testingType",
"browser": "browser",
"platform": "platform",
"selector-playground-api": "SelectorPlayground",
Expand Down
1 change: 1 addition & 0 deletions content/_data/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"cypress-log": "cypress-log.html",
"platform": "platform.html",
"spec": "spec.html",
"testing-type": "testing-type.html",
"version": "version.html"
},
"plugins": {
Expand Down
39 changes: 39 additions & 0 deletions content/api/cypress-api/testing-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Cypress.testingType
---

`Cypress.testingType` returns the current testing type, determined by the Test Runner chosen to run. The `Cypress.testingType` returns `e2e` for Cypress Test Runner `integration` tests, or `component` for experimental [Component Testing](guides/component-testing/introduction).

## Syntax

```javascript
Cypress.testingType // returns 'e2e' or 'component'
```

## Examples

### Testing Type

```javascript
it('is running experimental component testing mode', () => {
expect(Cypress.testingType).to.equal('component')
})
```

### Conditionals

```javascript
it('does something differently', () => {
if (Cypress.testingType === 'e2e') {
cy.exec('something')
} else {
cy.exec('something else')
}
})
```

## History

| Version | Changes |
| ------------------------------------- | --------------------------- |
| [7.0.0](/guides/references/changelog) | Added `Cypress.testingType` |
26 changes: 25 additions & 1 deletion content/api/plugins/configuration-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To modify configuration, you return an object from your plugins file exported fu
```javascript
// cypress/plugins/index.js
module.exports = (on, config) => {
console.log(config) // see what all is in here!
console.log(config) // see everything in here!

// modify config values
config.defaultCommandTimeout = 10000
Expand Down Expand Up @@ -210,3 +210,27 @@ This would enable you to do things like this:
This is a less complicated example. Remember - you have the full power of Node at your disposal.

How you choose to edit the configuration is up to you. You don't have to read off of the file system - you could store them all in memory inside of your `pluginsFile` if you wanted.

### Runner Specific Plugins

You can access the type of tests running via the `config.testingType` property. The testing type is either `e2e` or `component` depending on if the E2E or [Component Testing](/guides/component-testing/introduction/) runner was launched. This allows you to configure runner specific plugins.

#### Use Cypress React Plugin Conditionally

Conditionally apply the Cypress React Plugin if launching via Component Testing:

```js
module.exports = (on, config) => {
if (config.testingType === 'component') {
require('@cypress/react/plugins/react-scripts')(on, config)
}

return config
}
```

## History

| Version | Changes |
| ------------------------------------- | ----------------------------------------- |
| [7.0.0](/guides/references/changelog) | Added `testingType` property to `config`. |
1 change: 1 addition & 0 deletions content/guides/continuous-integration/aws-codebuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ phases:
In the AWS CodeBuild configuration we have defined in the previous section, we are leveraging three useful features of the [Cypress Dashboard](https://on.cypress.io/dashboard):

1. [Recording test results with the `--record` flag](https://on.cypress.io/how-do-i-record-runs) to the [Cypress Dashboard](https://on.cypress.io/dashboard):

- In-depth and shareable [test reports](/guides/dashboard/runs).
- Visibility into test failures via quick access to error messages, stack traces, screenshots, videos, and contextual details.
- [Integrating testing with the pull-request (PR) process](/guides/dashboard/github-integration) via [commit status check guards](/guides/dashboard/github-integration#Status-checks) and convenient [test report comments](/guides/dashboard/github-integration#Pull-request-comments).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ The above configuration using the `--parallel` and `--record` flags to [cypress
In the Bitbucket Pipelines configuration we have defined in the previous section, we are leveraging three useful features of the [Cypress Dashboard](https://on.cypress.io/dashboard):

1. [Recording test results with the `--record` flag](https://on.cypress.io/how-do-i-record-runs) to the [Cypress Dashboard](https://on.cypress.io/dashboard):

- In-depth and shareable [test reports](/guides/dashboard/runs).
- Visibility into test failures via quick access to error messages, stack traces, screenshots, videos, and contextual details.
- [Integrating testing with the pull-request process](/guides/dashboard/bitbucket-integration) via [commit status check guards](/guides/dashboard/bitbucket-integration#Status-checks) and convenient [pull request comments](/guides/dashboard/bitbucket-integration#Pull-Request-comments).
Expand Down
31 changes: 31 additions & 0 deletions content/guides/references/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@ For more complex configuration objects, you may want to consider passing a [JSON
cypress open --config '{"watchForFileChanges":false,"testFiles":["**/*.js","**/*.ts"]}'
```

### Runner Specific Overrides

You can override configuration for either the E2E or [Component Testing](/guides/component-testing/introduction/) runner using the `e2e` and `component` options.

#### Examples

Component Testing specific viewports in configuration file (`cypress.json` by default):

```json
{
"viewportHeight": 600,
"viewportWidth": 1000,
"component": {
"viewportHeight": 500,
"viewportWidth": 500
}
}
```

E2E specific timeouts in configuration file (`cypress.json` by default):

```json
{
"defaultCommandTimeout": 5000,
"e2e": {
"defaultCommandTimeout": 10000
}
}
```

### Plugins

You can programmatically modify configuration values using Node within the `pluginsFile`. This enables you to do things like:
Expand Down Expand Up @@ -519,6 +549,7 @@ DEBUG=cypress:cli,cypress:server:specs

| Version | Changes |
| -------------------------------------------- | ------------------------------------------------------- |
| [7.0.0](/guides/references/changelog#7-0-0) | Added `e2e` and `component` options. |
| [7.0.0](/guides/references/changelog#7-0-0) | Added `redirectionLimit` option. |
| [6.1.0](/guides/references/changelog#6-1-0) | Added `scrollBehavior` option. |
| [5.2.0](/guides/references/changelog#5-2-0) | Added `includeShadowDom` option. |
Expand Down
1 change: 1 addition & 0 deletions cypress/integration/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('APIs', () => {
'cypress-log': 'Cypress.log',
platform: 'Cypress.platform',
spec: 'Cypress.spec',
'testing-type': 'Cypress.testingType',
version: 'Cypress.version',
'configuration-api': 'Configuration API',
'preprocessors-api': 'Preprocessors API',
Expand Down