diff --git a/packages/server/lib/stdout.coffee b/packages/server/lib/stdout.coffee index bef4e0309626..76b59e2ef2f9 100644 --- a/packages/server/lib/stdout.coffee +++ b/packages/server/lib/stdout.coffee @@ -1,4 +1,5 @@ _write = process.stdout.write +_log = process.log module.exports = { capture: -> @@ -7,6 +8,16 @@ module.exports = { ## lazily backup write to enable ## injection write = process.stdout.write + log = process.log + + ## electron adds a new process.log + ## method for windows instead of process.stdout.write + ## https://github.com/cypress-io/cypress/issues/977 + if log + process.log = (str) -> + logs.push(str) + + log.apply(@, arguments) process.stdout.write = (str) -> logs.push(str) @@ -20,6 +31,7 @@ module.exports = { } restore: -> - ## restore to the original write + ## restore to the originals process.stdout.write = _write + process.log = _log } diff --git a/packages/server/test/unit/stdout_spec.coffee b/packages/server/test/unit/stdout_spec.coffee index 20fa5c6d9b7b..6ea2c9613a14 100644 --- a/packages/server/test/unit/stdout_spec.coffee +++ b/packages/server/test/unit/stdout_spec.coffee @@ -3,27 +3,53 @@ require("../spec_helper") stdout = require("#{root}lib/stdout") describe "lib/stdout", -> - beforeEach -> - @write = @sandbox.spy(process.stdout, "write") - @captured = stdout.capture() - afterEach -> stdout.restore() - it "slurps up stdout", -> - console.log("foo") - console.log("bar") - process.stdout.write("baz") + context "process.stdout.write", -> + beforeEach -> + @write = @sandbox.spy(process.stdout, "write") + @captured = stdout.capture() + + it "slurps up stdout", -> + console.log("foo") + console.log("bar") + process.stdout.write("baz") + + expect(@captured.data).to.deep.eq([ + "foo\n" + "bar\n" + "baz" + ]) + + expect(@captured.toString()).to.eq("foo\nbar\nbaz") + + ## should still call through to write + expect(@write).to.be.calledWith("foo\n") + expect(@write).to.be.calledWith("bar\n") + expect(@write).to.be.calledWith("baz") + + context "process.log", -> + beforeEach -> + @log = process.log + @logStub = process.log = @sandbox.stub() + + @captured = stdout.capture() + + afterEach -> + process.log = @log + + it "slurps up logs", -> + process.log("foo\n") + process.log("bar\n") - expect(@captured.data).to.deep.eq([ - "foo\n" - "bar\n" - "baz" - ]) + expect(@captured.data).to.deep.eq([ + "foo\n" + "bar\n" + ]) - expect(@captured.toString()).to.eq("foo\nbar\nbaz") + expect(@captured.toString()).to.eq("foo\nbar\n") - ## should still call through to write - expect(@write).to.be.calledWith("foo\n") - expect(@write).to.be.calledWith("bar\n") - expect(@write).to.be.calledWith("baz") + ## should still call through to write + expect(@logStub).to.be.calledWith("foo\n") + expect(@logStub).to.be.calledWith("bar\n")