Skip to content

Commit

Permalink
Yield null from cy.writeFile (#2731)
Browse files Browse the repository at this point in the history
- Fixes #2466 
- [Docs PR](cypress-io/cypress-documentation#1117)

Should be part of 4.0.0
  • Loading branch information
lilaconlee authored and chrisbreiding committed May 21, 2019
1 parent 59ab85b commit ce8f0ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
5 changes: 1 addition & 4 deletions packages/driver/src/cy/commands/files.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ module.exports = (Commands, Cypress, cy, state, config) ->
})

if _.isObject(contents)
objContents = contents
contents = JSON.stringify(contents, null, 2)

Cypress.backend("write:file", fileName, contents, _.pick(options, ["encoding", "flag"]))
.then ({ contents, filePath }) ->
consoleProps["File Path"] = filePath
consoleProps["Contents"] = contents
if objContents?
return objContents
return contents
return null
.catch Promise.TimeoutError, (err) ->
$utils.throwErrByPath "files.timed_out", {
onFail: options._log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,11 @@ describe "src/cy/commands/files", ->
}
)

it "sets the contents as the subject", ->
it "yields null", ->
Cypress.backend.resolves(okResponse)

cy.writeFile("foo.txt", "contents").then (subject) ->
expect(subject).to.equal("contents")

it "sets a JSON as the subject", ->
Cypress.backend.resolves(okResponse)

cy.writeFile("foo.json", { name: "Test" }).then (subject) ->
expect(subject.name).to.equal("Test")
expect(subject).to.not.exist

it "can write a string", ->
Cypress.backend.resolves(okResponse)
Expand Down

0 comments on commit ce8f0ee

Please sign in to comment.