Skip to content

Commit 966f131

Browse files
committed
Merge branch 'html-formatter-embedded-text' of github.com:tomdcc/cucumber-jvm
2 parents 03a106a + 31f75a9 commit 966f131

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

core/src/main/java/cucumber/runtime/formatter/HTMLFormatter.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,17 @@ public void match(Match match) {
135135

136136
@Override
137137
public void embedding(String mimeType, byte[] data) {
138-
// Creating a file instead of using data urls to not clutter the js file
139-
String extension = MIME_TYPES_EXTENSIONS.get(mimeType);
140-
if (extension != null) {
141-
StringBuilder fileName = new StringBuilder("embedded").append(embeddedIndex++).append(".").append(extension);
142-
writeBytesAndClose(data, reportFileOutputStream(fileName.toString()));
143-
jsFunctionCall("embedding", mimeType, fileName);
138+
if(mimeType.startsWith("text/")) {
139+
// just pass straight to the formatter to output in the html
140+
jsFunctionCall("embedding", mimeType, new String(data));
141+
} else {
142+
// Creating a file instead of using data urls to not clutter the js file
143+
String extension = MIME_TYPES_EXTENSIONS.get(mimeType);
144+
if (extension != null) {
145+
StringBuilder fileName = new StringBuilder("embedded").append(embeddedIndex++).append(".").append(extension);
146+
writeBytesAndClose(data, reportFileOutputStream(fileName.toString()));
147+
jsFunctionCall("embedding", mimeType, fileName);
148+
}
144149
}
145150
}
146151

core/src/test/java/cucumber/runtime/formatter/HTMLFormatterTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void includes_uri() throws IOException {
6565
public void included_embedding() throws IOException {
6666
String reportJs = FixJava.readReader(new InputStreamReader(new URL(outputDir, "report.js").openStream(), "UTF-8"));
6767
assertContains("formatter.embedding(\"image/png\", \"embedded0.png\");", reportJs);
68+
assertContains("formatter.embedding(\"text/plain\", \"dodgy stack trace here\");", reportJs);
6869
}
6970

7071
private void assertContains(String substring, String string) {
@@ -78,6 +79,7 @@ private void runFeaturesWithFormatter(URL outputDir) throws IOException {
7879
f.uri("some\\windows\\path\\some.feature");
7980
f.scenario(new Scenario(Collections.<Comment>emptyList(), Collections.<Tag>emptyList(), "Scenario", "some cukes", "", 10, "id"));
8081
f.embedding("image/png", "fakedata".getBytes("US-ASCII"));
82+
f.embedding("text/plain", "dodgy stack trace here".getBytes("US-ASCII"));
8183
f.done();
8284
f.close();
8385
}

0 commit comments

Comments
 (0)