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

9.2.0 Release #4270

Merged
merged 13 commits into from
Dec 21, 2021
Merged
5 changes: 5 additions & 0 deletions content/_changelogs/9.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ _Released 11/10/2021_
could change the behavior of code within the `pluginsFile` when using the
bundled Node.js version of Cypress. Addressed in
[#18317](https://github.com/cypress-io/cypress/pull/18317).
- The default read behavior of a fixture provided as a static response in
`cy.intercept()` changed from being read as a Buffer to using `utf8` encoding.
This aligns the default read behavior of `cy.intercept()` to `cy.readFile()`
and `cy.fixture()`. Addresses
[#18534](https://github.com/cypress-io/cypress/issues/18534).

**Deprecations:**

Expand Down
75 changes: 75 additions & 0 deletions content/_changelogs/9.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## 9.2.0

_Released 12/20/2021_

**Features:**

- Cypress will throw an error when a user attempts to update a configuration
value at run-time using either the Test Configuration or using
`Cypress.config()` that is a
[readonly option](https://docs.cypress.io/guides/references/configuration#Test-Configuration).
Addresses [#6407](https://github.com/cypress-io/cypress/issues/6407) and
[#19001](https://github.com/cypress-io/cypress/issues/19001).
- A `timeout` option has been added to the `cy.writeFile()` command, with a
default value of `defaultCommandTimeout`. Addresses
[#3350](https://github.com/cypress-io/cypress/issues/3350).
- The default `maxHttpBufferSize` for the internal socket server has been
increased to
[Node's maximum Buffer size](https://nodejs.org/api/buffer.html#bufferconstantsmax_length)
(size varies by OS) to allow large file writes with `cy.writeFile()`.
Addresses [#19140](https://github.com/cypress-io/cypress/issues/19140).
- Add `CYPRESS_VERIFY_TIMEOUT` environment variable to override the timeout
duration of the `verify` command. Addresses
[#18290](https://github.com/cypress-io/cypress/issues/18290).

**Bugfixes:**

- Prevent unnecessary snapshotting when running default assertions that would
unnecessarily increase CPU use in `cypress open` mode which lead to out of
memory crashes on certain browsers. Fixes
[#18549](https://github.com/cypress-io/cypress/issues/18549).
- Removed automatic retries for failed HTTP requests through the proxy. This
fixes an issue where failed requests could be re-sent too many times in some
conditions. This change could increase the number of failed requests that your
app sees. Fixes [#19043](https://github.com/cypress-io/cypress/issues/19043).
- Reduced the occurrence of an issue where logs for `fetch` and `xhr` requests
could be associated with the wrong request. Fixes
[#19043](https://github.com/cypress-io/cypress/issues/19043).
- Tests that are skipped within `then` blocks will no longer throw errors
causing the test to fail. Tests that are skipped outside of `then` blocks will
no longer trigger the fail event. This will prevent screenshots from happening
from errors thrown by the fail event.Fixes
[#14867](https://github.com/cypress-io/cypress/issues/14867) and
[#17660](https://github.com/cypress-io/cypress/issues/17660).
- Fixed a regression in [9.0.0](/guides/references/changelog#9-0-0) where a
fixture provided in a static response to `cy.intercept()` did not support
passing `null` to encoding to read the fixture as a Buffer. This identified an
undocumented 9.0.0 Breaking Change where the default read behavior of a
fixture changed from a Buffer to being read with `utf8` encoding. Fixes
[#19344](https://github.com/cypress-io/cypress/issues/19344).
- Fixed a regression in [9.0.0](/guides/references/changelog#9-0-0) where
`cy.contains()` attempted to ignore `<script>` and `<style>` elements found
within `<body>`. by deleting them from the dom. This behavior was corrected to
ignore the elements without deleting them. Fixes
[#19377](https://github.com/cypress-io/cypress/issues/19377).
- Cypress will no longer crash when proxying an ill formed request. For example,
if the application under test has a resource of `"http: //localhost/asset.js"`
(notice the extraneous space), Cypress will now log a debug message and the
asset will fail to load. Fixes
[#9220](https://github.com/cypress-io/cypress/issues/9220).
- Correct `Cypress.Command.add()` and `Cypress.Command.override()` TypeScript
types. Fixes [#18879](https://github.com/cypress-io/cypress/issues/18879),
[#19095](https://github.com/cypress-io/cypress/issues/19095) and
[#18940](https://github.com/cypress-io/cypress/issues/18940).
- Custom command implementations typings take into account `prevSubject`
variants.
- Custom command implementations now allows to NOT return a value.
- Custom command overwrites typings take into account `originalFn` function.
- Add types for `Cypress.session.clearAllSavedSessions()`. Fixes
[#19363](https://github.com/cypress-io/cypress/issues/19363).

**Dependencies:**

- Upgraded `ssri` from `6.0.1` to `6.0.2` to mitigate
[ssri vulnerability](snyk.io/vuln/npm:ssri@6.0.1). Addressed in
[#19351](https://github.com/cypress-io/cypress/issues/19351).
74 changes: 33 additions & 41 deletions content/api/commands/intercept.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,14 @@ See [examples](#With-RouteMatcher) below.
#### <Icon name="angle-right"></Icon> staticResponse (<code>[StaticResponse][staticresponse]</code>)

By passing in a `StaticResponse` as the last argument, you can
[statically define (stub) a response](#Stubbing-a-response) for matched requests
including the body of the response, as well as the headers and HTTP status code:

| Option | Description |
| ---------- | ---------------------------------------------------------------- |
| statusCode | HTTP response status code |
| headers | HTTP response headers |
| body | Serve a static response body (`object`, `string`, `ArrayBuffer`) |
| fixture | Serve a fixture as the HTTP response body |

`StaticResponse` also provides options for simulating a degraded or broken
network connection:

| Option | Description |
| ----------------- | --------------------------------------------------------------------------- |
| forceNetworkError | Force an error by destroying the browser connection |
| delay | Minimum network latency or delay to add to the response time (milliseconds) |
| throttleKbps | Maximum data transfer rate of the response (kilobits/second) |

**Note:** All properties are optional.
[statically define (stub) a response](#Stubbing-a-response) for matched
requests. See [`StaticResponse` object](#StaticResponse-objects) for the list of
properties.

See
[Stubbing a response with a `StaticResponse` object](#With-a-StaticResponse-object)
for an example.

See also [`StaticResponse` objects](#StaticResponse-objects).

#### <Icon name="angle-right"></Icon> routeHandler (<code>Function</code>)

The `routeHandler` function is called whenever a request is matched, with the
Expand Down Expand Up @@ -457,7 +438,15 @@ cy.intercept('/not-found', {
})
```

See also [`StaticResponse` objects][staticresponse].
Stub response with a fixture that is read as a Buffer:

```js
cy.intercept('/not-found', {
fixture: 'media/gif.mp4,null',
})
```

See also [`StaticResponse` object][staticresponse].

### Using the **`routeHandler`** function

Expand Down Expand Up @@ -1326,30 +1315,33 @@ from propagating to the next matching response handler in line. See

## `StaticResponse` objects

A `StaticResponse` represents a stubbed response to an HTTP request. You can
supply a `StaticResponse` to Cypress in 3 ways:
A `StaticResponse` represents a
[statically defined response (stub)](#Stubbing-a-response).

The following properties are available on `StaticResponse`.

| Option | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| statusCode | HTTP response status code |
| headers | HTTP response headers |
| body | Serve a static response body (`object`, `string`, `ArrayBuffer`) (when `fixture` is omitted). |
| fixture | Serve a fixture as the HTTP response body (allowed when `body` is omitted). Read the contents with an encoding other than the [default for the file type](/api/commands/fixture#Encoding), pass the fixture like `path,encoding`. |
| forceNetworkError | Force an error by destroying the browser connection |
| delay | Minimum network latency or delay to add to the response time (milliseconds) |
| throttleKbps | Maximum data transfer rate of the response (kilobits/second) |

- Directly to `cy.intercept()` as
[`staticResponse`](#staticResponse-lt-code-gtStaticResponselt-code-gt), to
stub a response to a route: `cy.intercept('/url', staticResponse)`
**Note:** All properties are optional.

You can supply a `StaticResponse` to Cypress in 3 ways:

- To `cy.intercept()` as
[`an argument`](#staticResponse-lt-code-gtStaticResponselt-code-gt), to stub a
response to a route: `cy.intercept('/url', staticResponse)`
- To [`req.reply()`][req-reply], to stub a response from a request handler:
`req.reply(staticResponse)`
- To [`res.send()`][res-send], to stub a response from a response handler:
`res.send(staticResponse)`

The following properties are available on `StaticResponse`. All properties are
optional:

| Option | Description |
| ----------------- | --------------------------------------------------------------------------- |
| fixture | Serve a fixture as the HTTP response body |
| body | Serve a static response body (`object`, `string`, `ArrayBuffer`) |
| headers | HTTP response headers |
| statusCode | HTTP response status code |
| forceNetworkError | Force an error by destroying the browser connection |
| delay | Minimum network latency or delay to add to the response time (milliseconds) |
| throttleKbps | Maximum data transfer rate of the response (kilobits/second) |

See
["Stubbing a response with a `StaticResponse` object"](#With-a-StaticResponse-object)
for examples of stubbing with `cy.intercept()`.
Expand Down
28 changes: 18 additions & 10 deletions content/api/commands/readfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Pass in an options object to change the default behavior of `cy.readFile()`.

### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)

<List><li>`cy.readFile()` yields the contents of the file.</li></List>
- `cy.readFile()` yields the contents of the file.

## Examples

Expand Down Expand Up @@ -196,21 +196,21 @@ cy.readFile('some/nested/path/story.txt').should('eq', 'Once upon a time...')

### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)

<List><li>`cy.readFile()` requires being chained off of
`cy`.</li><li>`cy.readFile()` requires the file must
exist.</li><li>`cy.readFile()` requires the file be successfully read from
disk.</li></List>
- `cy.readFile()` requires being chained off of `cy`.
- `cy.readFile()` requires the file must exist.
- `cy.readFile()` requires the file be successfully read from disk.

### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)

<List><li>`cy.readFile()` will automatically
[retry](/guides/core-concepts/retry-ability) until all chained assertions have
passed</li></List>
- `cy.readFile()` will automatically
[retry](/guides/core-concepts/retry-ability) until all chained assertions have
passed.

### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)

<List><li>`cy.readFile()` can time out waiting for assertions you've added to
pass.</li></List>
- `cy.readFile()` can time out waiting for assertions you've added to pass.
- `cy.readFile()` can time out when the content being read takes a significant
amount of time to encode.

## Command Log

Expand All @@ -229,6 +229,14 @@ outputs the following:

<DocsImage src="/img/api/readfile/console-log-shows-content-from-file-formatted-as-javascript.png" alt="Console Log readFile" ></DocsImage>

## History

| Version | Changes |
| --------------------------------------------- | ----------------------------------------- |
| [9.0.0](/guides/references/changelog#9-0-0) | Changed `null` encoding to read as Buffer |
| [0.17.2](/guides/references/changelog#0-17-2) | Improved error messaging |
| [0.17.1](/guides/references/changelog#0-17-1) | `cy.readFile()` command added |

## See also

- [`cy.exec()`](/api/commands/exec)
Expand Down
27 changes: 10 additions & 17 deletions content/api/commands/writefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ first encoding it as a string.

Pass in an options object to change the default behavior of `cy.writeFile()`.

| Option | Default | Description |
| ---------- | ------- | --------------------------------------------------------------------------------------------------- |
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/test-runner#Command-Log) |
| `flag` | `w` | File system flag as used with [`fs.writeFile`](https://nodejs.org/api/fs.html#fs_file_system_flags) |
| `encoding` | `utf8` | The encoding to be used when writing to the file |
| Option | Default | Description |
| ---------- | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `log` | `true` | Displays the command in the [Command log](/guides/core-concepts/test-runner#Command-Log) |
| `flag` | `w` | File system flag as used with [`fs.writeFile`](https://nodejs.org/api/fs.html#fs_file_system_flags) |
| `encoding` | `utf8` | The encoding to be used when writing to the file |
| `timeout` | [`defaultCommandTimeout`](/guides/references/configuration#Timeouts) | Time to wait for `.writeFile()` to resolve before [timing out](#Timeouts) |

<Alert type="info">

Expand All @@ -74,8 +75,7 @@ parameter and include encoding there. This is the same behavior as

### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management)

<List><li>`cy.writeFile()` yields the value of the <code>contents</code>
argument.</li></List>
- `cy.writeFile()` yields `null`.

## Examples

Expand Down Expand Up @@ -209,7 +209,6 @@ cy.readFile(filename, null).then((obj) => {
### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)

- `cy.writeFile()` requires being chained off of `cy`.

- `cy.writeFile()` requires the file be successfully written to disk. Anything
preventing this such as OS permission issues will cause it to fail.

Expand All @@ -220,15 +219,8 @@ cy.readFile(filename, null).then((obj) => {

### Timeouts [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Timeouts)

- `cy.writeFile()` should never time out.

<Alert type="warning">

Because `cy.writeFile()` is asynchronous it is technically possible for there to
be a timeout while talking to the internal Cypress automation APIs. But for
practical purposes it should never happen.

</Alert>
- `cy.writeFile()` can time out when the content being written takes a
significant amount of time to encode.

## Command Log

Expand All @@ -251,6 +243,7 @@ outputs the following:

| Version | Changes |
| ------------------------------------------- | -------------------------------------------------------- |
| [9.2.0](/guides/references/changelog#9-2-0) | Added `timeout` option |
| [4.0.0](/guides/references/changelog#4-0-0) | `cy.writeFile()` now yields `null` instead of `contents` |
| [3.1.1](/guides/references/changelog#3-1-1) | Added `flag` option and appending with `a+` |
| [1.0.0](/guides/references/changelog#1.0.0) | `cy.writeFile()` command added |
Expand Down
8 changes: 4 additions & 4 deletions content/api/cypress-api/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ Cypress.config() // => {defaultCommandTimeout: 10000, viewportHeight: 900, ...}

### Not all config values can be changed at all times

Some configuration values are readonly and cannot be changed while running a
test. Anything that's not directly under Cypress's control - like timeouts,
`userAgent`, or environment variables - will be ignored at run-time. Be sure to
review the list of
Some configuration values are readonly and cannot be changed during running a
test. Anything that is not listed in the
[test configuration options](/guides/references/configuration#Test-Configuration)
cannot be updated at runtime. Be sure to review the list of
[test configuration options](/guides/references/configuration##Test-Configuration).

### Test Configuration vs `Cypress.config()`
Expand Down
Loading