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

Output embedded text in HTML report #501

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 11 additions & 6 deletions core/src/main/java/cucumber/runtime/formatter/HTMLFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ public void match(Match match) {

@Override
public void embedding(String mimeType, byte[] data) {
// Creating a file instead of using data urls to not clutter the js file
String extension = MIME_TYPES_EXTENSIONS.get(mimeType);
if (extension != null) {
StringBuilder fileName = new StringBuilder("embedded").append(embeddedIndex++).append(".").append(extension);
writeBytesAndClose(data, reportFileOutputStream(fileName.toString()));
jsFunctionCall("embedding", mimeType, fileName);
if(mimeType.startsWith("text/")) {
// just pass straight to the formatter to output in the html
jsFunctionCall("embedding", mimeType, new String(data));
} else {
// Creating a file instead of using data urls to not clutter the js file
String extension = MIME_TYPES_EXTENSIONS.get(mimeType);
if (extension != null) {
StringBuilder fileName = new StringBuilder("embedded").append(embeddedIndex++).append(".").append(extension);
writeBytesAndClose(data, reportFileOutputStream(fileName.toString()));
jsFunctionCall("embedding", mimeType, fileName);
}
}
}

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

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