diff --git a/lib/cucumber/listener/json_formatter.js b/lib/cucumber/listener/json_formatter.js index 8a6fc1078..bc30bbd3e 100644 --- a/lib/cucumber/listener/json_formatter.js +++ b/lib/cucumber/listener/json_formatter.js @@ -1,7 +1,6 @@ /* jshint -W106 */ function JsonFormatter(options) { var Cucumber = require('../../cucumber'); - var base64 = require('base-64'); var self = Cucumber.Listener.Formatter(options); @@ -91,8 +90,12 @@ function JsonFormatter(options) { if (stepResult.hasAttachments()) { currentStep.embeddings = stepResult.getAttachments().map(function (attachment) { + var data = attachment.getData(); + if (!(data instanceof Buffer)) { + data = new Buffer(data); + } return { - data: base64.encode(attachment.getData()), + data: data.toString('base64'), mime_type: attachment.getMimeType(), }; }); diff --git a/package.json b/package.json index f2258b03c..b5da80333 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "node": ">=0.10" }, "dependencies": { - "base-64": "^0.1.0", "callsite": "^1.0.0", "camel-case": "^1.2.0", "cli-table": "^0.3.1", diff --git a/spec/cucumber/listener/json_formatter_spec.js b/spec/cucumber/listener/json_formatter_spec.js index e045070e0..265e8c255 100644 --- a/spec/cucumber/listener/json_formatter_spec.js +++ b/spec/cucumber/listener/json_formatter_spec.js @@ -3,6 +3,7 @@ require('../../support/spec_helper'); describe("Cucumber.Listener.JsonFormatter", function () { var Cucumber = requireLib('cucumber'); + var fs = require('fs'); var jsonFormatter, options; beforeEach(function () { @@ -281,7 +282,13 @@ describe("Cucumber.Listener.JsonFormatter", function () { beforeEach(function (){ var attachment1 = createSpyWithStubs("first attachment", {getMimeType: "first mime type", getData: "first data"}); var attachment2 = createSpyWithStubs("second attachment", {getMimeType: "second mime type", getData: "second data"}); - var attachments = [attachment1, attachment2]; + var favicon = fs.readFileSync('example/images/favicon.png'); + var attachment3 = createSpyWithStubs("third attachment", { + getMimeType: "image/png", + getData: favicon + }); + this.faviconBase64 = favicon.toString('base64'); + var attachments = [attachment1, attachment2, attachment3]; stepResult.hasAttachments.and.returnValue(true); stepResult.getAttachments.and.returnValue(attachments); jsonFormatter.handleStepResultEvent(event, callback); @@ -298,7 +305,11 @@ describe("Cucumber.Listener.JsonFormatter", function () { var features = JSON.parse(json); expect(features[0].elements[0].steps[0].embeddings).toEqual([ {data: 'Zmlyc3QgZGF0YQ==', mime_type: 'first mime type'}, - {data: 'c2Vjb25kIGRhdGE=', mime_type: 'second mime type'} + {data: 'c2Vjb25kIGRhdGE=', mime_type: 'second mime type'}, + { + data: this.faviconBase64, + mime_type: 'image/png' + } ]); }); });