Skip to content

Commit

Permalink
fix: writeFile returns string instead JSON (#2373)
Browse files Browse the repository at this point in the history
* Returning obj instead of text

If input of writeFile is an object, it should return an object after successful write instead of a string.

* Testing returned JSON of writeFile
  • Loading branch information
rezaxdi authored and brian-mann committed Oct 31, 2018
1 parent 0228762 commit 6087111
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/driver/src/cy/commands/files.coffee
Expand Up @@ -94,13 +94,15 @@ 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
.catch Promise.TimeoutError, (err) ->
$utils.throwErrByPath "files.timed_out", {
Expand Down
Expand Up @@ -291,6 +291,12 @@ describe "src/cy/commands/files", ->

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")

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

0 comments on commit 6087111

Please sign in to comment.