mochawesome-merge icon indicating copy to clipboard operation
mochawesome-merge copied to clipboard

Duration issue

Open joszo opened this issue 4 years ago • 2 comments

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.

joszo avatar Jan 21 '21 14:01 joszo

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

Antontelesh avatar Jan 21 '21 15:01 Antontelesh

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,
...
}

joszo avatar Jan 21 '21 17:01 joszo

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

basile-parent avatar Feb 01 '23 13:02 basile-parent

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

Antontelesh avatar Mar 13 '23 16:03 Antontelesh