Skip to content

HTML cannot be rendered if a 'text/json' attachment is present #1787

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

Open
mitchgrout opened this issue May 20, 2025 · 3 comments
Open

HTML cannot be rendered if a 'text/json' attachment is present #1787

mitchgrout opened this issue May 20, 2025 · 3 comments

Comments

@mitchgrout
Copy link

👓 What did you see?

Given an object which represents some JSON object, attach(object, "text/json") will correctly add an attachment envelope to the output message stream, and will be included in the HTML body. However, attempting to open this report (at least in Chrome) results in only a white screen being rendered.

If for example, object = { "foo": 42 }, then within the message stream we have (prettified):

{
  "attachment": {
    "body": {"foo":42},
    "contentEncoding": "IDENTITY",
    "mediaType": "text/json",
    "testCaseStartedId": "a92d9794-86d9-4c14-a913-1f8ddb736289",
    "testStepId": "5996f98b-fe36-48e3-94be-b3b2433344c2"
  }
}

✅ What did you expect to see?

The page should continue to be loadable, and either display the attached text/json in a plaintext form or in any other way.

📦 Which tool/library version are you using?

cucumber-html-formatter v19.2.0

🔬 How could we reproduce it?

  1. Create features/test.feature with:
# features/test.feature
Feature: Reproduction of problem
  Scenario: Example scenario
    When nothing happens
  1. Create features/step_definitions/all.rb with:
When('nothing happens') { }
  1. Create features/support/env.rb with:
After do |test|
  context = {
    "foo" => 42,
  }

  attach(context, "text/json")
end
  1. Run cucumber -f html -o cucumber.html
  2. Load the cucumber.html into a browser of choice, and check that:
    1. only a white screen is displayed, and
    2. the attachment message is present in the message list, and
    3. if the attachment message is removed, the page is rendered correctly

📚 Any additional context?

No response

@mpkorstanje mpkorstanje transferred this issue from cucumber/html-formatter May 20, 2025
@mpkorstanje
Copy link
Contributor

@luke-hill It looks like body is a hash rather than a string. That would suggest cucumber-ruby is writing the message wrong.

@mitchgrout as a workaround can you turn the hash into a string when calling attach?

@mitchgrout
Copy link
Author

@luke-hill It looks like body is a hash rather than a string. That would suggest cucumber-ruby is writing the message wrong.

@mitchgrout as a workaround can you turn the hash into a string when calling attach?

It does appear that an explicit #to_json does the trick, as it results in the "body" being set to a string rather than an object:

{
  "attachment": {
    "body": "{\"foo\":42}",
    "contentEncoding": "IDENTITY",
    "mediaType": "text/json",
    "testCaseStartedId": "d175d079-76cf-43ba-b6b6-77064365b781",
    "testStepId": "0b071290-cd83-4db0-b7c1-b24fd9a8bf98"
  }
}

@luke-hill
Copy link
Contributor

It's likely there is an issue.

The html-formatter has another issue whereby errors aren't being rendered correctly.

@mitchgrout so you know my rough priority / timelines.

  1. Get cucumber ruby v10 out (I'm hoping this is soon, a week or so)
  2. Then refactor a bunch of stuff regarding versions (Want to make sure we're using late/latest versions of most things)
  3. Look at the html-formatter, fix a bunch of issues

I appreciate this is a long timeline, just lots of stuff for me to tackle.

If you have capacity and want to look into the html formatter feel free. There are issues there with errors (I think it's using the wrong property)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants