@@ -28,7 +28,8 @@ cy.writeFile('menu.json')
2828A path to a file within the project root (the directory that contains the
2929default ` 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
3334The contents to be written to the file.
3435
@@ -57,11 +58,12 @@ first encoding it as a string.
5758
5859Pass 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
197199const 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