Skip to content

Commit b392543

Browse files
authored
Adding readFile/writeFile doc around new timeout features (#4244)
1 parent 1976a4f commit b392543

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

content/_changelogs/9.1.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ _Released 11/22/2021_
2323
- The warning message for retrying connection to a browser has been improved to
2424
indicate when it is still waiting. Fixes
2525
[#18644](https://github.com/cypress-io/cypress/issues/18644).
26-
- Cypress commands that rely on `this` context now have access to `this` when
27-
overridden. Fixes [#18899](https://github.com/cypress-io/cypress/pull/18899).
26+
- Cypress commands that rely on `this` context now have access to `this` when
27+
overridden. Fixes [#18899](https://github.com/cypress-io/cypress/pull/18899).

content/api/commands/readfile.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ supported:
4646
- `'utf-16le'`
4747
- `null`
4848

49-
Using `null` explicitly will return the file as a `Buffer`, regardless of file extension.
49+
Using `null` explicitly will return the file as a `Buffer`, regardless of file
50+
extension.
5051

5152
**<Icon name="angle-right"></Icon> options** **_(Object)_**
5253

@@ -59,7 +60,7 @@ Pass in an options object to change the default behavior of `cy.readFile()`.
5960

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

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

6465
## Examples
6566

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

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

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

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

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

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

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

214215
## Command Log
215216

@@ -228,6 +229,14 @@ outputs the following:
228229

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

232+
## History
233+
234+
| Version | Changes |
235+
| --------------------------------------------- | ----------------------------------------- |
236+
| [9.0.0](/guides/references/changelog#9-0-0) | Changed `null` encoding to read as Buffer |
237+
| [0.17.2](/guides/references/changelog#0-17-2) | Improved error messaging |
238+
| [0.17.1](/guides/references/changelog#0-17-1) | `cy.readFile()` command added |
239+
231240
## See also
232241

233242
- [`cy.exec()`](/api/commands/exec)

content/api/commands/writefile.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ cy.writeFile('menu.json')
2828
A path to a file within the project root (the directory that contains the
2929
default `cypress.json`).
3030

31-
**<Icon name="angle-right"></Icon> contents** **_(String, Array, Object or Buffer)_**
31+
**<Icon name="angle-right"></Icon> contents** **_(String, Array, Object or
32+
Buffer)_**
3233

3334
The contents to be written to the file.
3435

@@ -57,11 +58,12 @@ first encoding it as a string.
5758

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

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

6668
<Alert type="info">
6769

@@ -73,8 +75,7 @@ parameter and include encoding there. This is the same behavior as
7375

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

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

7980
## Examples
8081

@@ -193,6 +194,7 @@ cy.readFile(filename).then((list) => {
193194
### Buffer
194195

195196
#### Write a buffer directly without encoding as a string
197+
196198
```javascript
197199
const filename = '/path/to/file.png'
198200

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

209211
- `cy.writeFile()` requires being chained off of `cy`.
210-
211212
- `cy.writeFile()` requires the file be successfully written to disk. Anything
212213
preventing this such as OS permission issues will cause it to fail.
213214

@@ -218,15 +219,8 @@ cy.readFile(filename, null).then((obj) => {
218219

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

221-
- `cy.writeFile()` should never time out.
222-
223-
<Alert type="warning">
224-
225-
Because `cy.writeFile()` is asynchronous it is technically possible for there to
226-
be a timeout while talking to the internal Cypress automation APIs. But for
227-
practical purposes it should never happen.
228-
229-
</Alert>
222+
- `cy.writeFile()` can time out when the content being written takes a
223+
significant amount of time to encode.
230224

231225
## Command Log
232226

@@ -249,6 +243,7 @@ outputs the following:
249243

250244
| Version | Changes |
251245
| ------------------------------------------- | -------------------------------------------------------- |
246+
| [9.2.0](/guides/references/changelog#9-2-0) | Added `timeout` option |
252247
| [4.0.0](/guides/references/changelog#4-0-0) | `cy.writeFile()` now yields `null` instead of `contents` |
253248
| [3.1.1](/guides/references/changelog#3-1-1) | Added `flag` option and appending with `a+` |
254249
| [1.0.0](/guides/references/changelog#1.0.0) | `cy.writeFile()` command added |

0 commit comments

Comments
 (0)