Skip to content

Commit 3a2861d

Browse files
benjaminecharlierudolph
authored andcommitted
native base64 encoding, fix for binary attachments (#589)
1 parent f6089be commit 3a2861d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

lib/cucumber/listener/json_formatter.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* jshint -W106 */
22
function JsonFormatter(options) {
33
var Cucumber = require('../../cucumber');
4-
var base64 = require('base-64');
54

65
var self = Cucumber.Listener.Formatter(options);
76

@@ -86,8 +85,12 @@ function JsonFormatter(options) {
8685

8786
if (stepResult.hasAttachments()) {
8887
currentStep.embeddings = stepResult.getAttachments().map(function (attachment) {
88+
var data = attachment.getData();
89+
if (!(data instanceof Buffer)) {
90+
data = new Buffer(data);
91+
}
8992
return {
90-
data: base64.encode(attachment.getData()),
93+
data: data.toString('base64'),
9194
mime_type: attachment.getMimeType(),
9295
};
9396
});

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
"node": ">=0.10"
104104
},
105105
"dependencies": {
106-
"base-64": "^0.1.0",
107106
"callsite": "^1.0.0",
108107
"camel-case": "^3.0.0",
109108
"cli-table": "^0.3.1",

spec/cucumber/listener/json_formatter_spec.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require('../../support/spec_helper');
33

44
describe("Cucumber.Listener.JsonFormatter", function () {
55
var Cucumber = requireLib('cucumber');
6+
var fs = require('fs');
67
var jsonFormatter, options;
78

89
beforeEach(function () {
@@ -244,7 +245,13 @@ describe("Cucumber.Listener.JsonFormatter", function () {
244245
beforeEach(function (){
245246
var attachment1 = createSpyWithStubs("first attachment", {getMimeType: "first mime type", getData: "first data"});
246247
var attachment2 = createSpyWithStubs("second attachment", {getMimeType: "second mime type", getData: "second data"});
247-
var attachments = [attachment1, attachment2];
248+
var favicon = fs.readFileSync('example/images/favicon.png');
249+
var attachment3 = createSpyWithStubs("third attachment", {
250+
getMimeType: "image/png",
251+
getData: favicon
252+
});
253+
this.faviconBase64 = favicon.toString('base64');
254+
var attachments = [attachment1, attachment2, attachment3];
248255
stepResult.hasAttachments.and.returnValue(true);
249256
stepResult.getAttachments.and.returnValue(attachments);
250257
jsonFormatter.handleStepResultEvent(stepResult);
@@ -257,7 +264,11 @@ describe("Cucumber.Listener.JsonFormatter", function () {
257264
var features = JSON.parse(json);
258265
expect(features[0].elements[0].steps[0].embeddings).toEqual([
259266
{data: 'Zmlyc3QgZGF0YQ==', mime_type: 'first mime type'},
260-
{data: 'c2Vjb25kIGRhdGE=', mime_type: 'second mime type'}
267+
{data: 'c2Vjb25kIGRhdGE=', mime_type: 'second mime type'},
268+
{
269+
data: this.faviconBase64,
270+
mime_type: 'image/png'
271+
}
261272
]);
262273
});
263274
});

0 commit comments

Comments
 (0)