Antontelesh / mochawesome-merge

Merge several Mochawesome JSON reports
MIT License
85 stars 16 forks source link

Duration issue #61

Closed joszo closed 1 year ago

joszo commented 3 years ago

Hello,

I'm not sure is it a bug or feature.

But in test you are maping duration only for tests but not for before and after hooks.

duration: tests.map(test => test.duration).reduce((a, b) => a + b, 0),

So if a generate 2 files using mochawsome with duration duration: 6821 duration: 39938 Thier html reporter generates 6.xx and 39.xx second. After merging my duration is equal 26.617seconds But when we will merge those two jsons you don't summing up those time correctly.

In my opinion we should sum up whole duration of the tests in that case.

Antontelesh commented 3 years ago

Hey @joszo. I don’t think we do this intentionally, so may be a bug. If you know how to fix it and need a fix, I will review your PR with a pleasure

joszo commented 3 years ago

I'm not sure is it the prettiest solution but as quick implemenation:

added in index.js

const collectStatsDuration = (report) => {
  return report.map(element => element.stats.duration).reduce((a, b)=> a + b, 0);
};
`exports.merge = async function merge(options) {

...

  const statsDuration = collectStatsDuration(reports);

  return {
    stats: {
      ...generateStats(suites, statsDuration),
 ...
};`

and then passing:

function generateStats(suites, statsDuration) {

...
    duration: statsDuration,
...
}
basile-parent commented 1 year ago

Hello, I created this pull request to solve the problem: https://github.com/Antontelesh/mochawesome-merge/pull/95 I calculated the total time of execution (including the time loss between each test run).

I hope it will help you

Antontelesh commented 1 year ago

95 is released in version 4.3.0, so I'm closing this issue