adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js
https://gitter.im/mochawesome/general
MIT License
1.06k stars 160 forks source link

Allow control over the order of tests combined into one report #326

Open tamaker opened 4 years ago

tamaker commented 4 years ago

Is your feature request related to a problem? Please describe. An edge case / customization I'd say, not really a 'problem'... when I'm running my tests over the course of a day and opt to combine ALL into one report, the newly run tests are appended to the BOTTOM and oldest test run is at the top.

Describe the solution you'd like I'd like a means of letting me specify / control the order of report tests UL's LI elements.

Describe alternatives you've considered a flag that I can pass to specif an 'order' directive that lets me reverse sort the tests so the newest is always at the top. (i.e. --report-order: ascending | descending)

For now I'm going to try to write a JS based tweak (as a local js script include) that lets me call the .html report in my browser and set a query string parameter for sort order (chronological order vs revers chronological order).

Additional context Just for a little use case detail, I plan on having this displayed on one of a series of 50 inch displays in our development area, as a means for our team to have the ability to quickly glance at the current status of our tests -- with latest run always at the top of the HTML page... and if an issue or potential issue is noticed or brought to our attention, we can easily scroll / scrub down the UL to inspect the prior test results for the day.

adamgruber commented 4 years ago

I'm curious how you are combining tests into one report? Is this being done after multiple separate test runs?

aamakerlsa commented 4 years ago

@adamgruber - I'm using mochawesome-merge.

(from my package.json scripts object) "combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",

Update: I was able to implement this by adding script tags for a local custom js file and jQuery to the main-html.js file in /node_modules/mochawesome_report_generator/lib/main-html.js

and in that custom js file, I basically:

  1. loop through each '.suite--list---...' item and use jQuery to PREPEND it to the element with the ID 'details'
  2. check each item for the presence of the substring 'fail' and if found, perform a 'click' to expand the failures

While I've solved this question / issue, I now need to know if it's possible to always have autoOpen target the SAME browser tab (I'm running the test hourly and right now I always end up with a LOT of tabs)