Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native base64 encoding, fix for binary attachments #589

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/cucumber/listener/json_formatter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* jshint -W106 */
function JsonFormatter(options) {
var Cucumber = require('../../cucumber');
var base64 = require('base-64');

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

Expand Down Expand Up @@ -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(),
};
});
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions spec/cucumber/listener/json_formatter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
Expand All @@ -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'
}
]);
});
});
Expand Down