0

I am currently using jest to run my tests and redirect the output to the file using the below command: “jest --runInBand tests/*tests.ts --json --verbose --outputFile=testout.json"

In the output.json file, the time taken for each of the suite is present. I will have to determine the time taken for each tests under the suite, which is not present in .json file. Could anyone please help me with this.

1 Answers1

0

I also tried to find this functionality in the default jest reporters but I do not think this is possible by default (I searched extensively, but someone else could prove me wrong, and I'd be grateful for it).

What you CAN do is write your own reporter that is able to take the duration of each test and print it in another json file, along with other informations that could be useful for crossing results with your "testout.json" file. In order to do this, check out jest reporter section. Another resource that was useful for me is this guide on reporters that was so useful especially with the object structure from which gathering informations.

In our specific case, that is retrieving information about the duration of a single test, I'll suggest to check out testResults.testResults[i].duration property, which contains the time took by i-th test to run.

In my case, I forked this git repo for a custom reporter specific for bamboo, and adjusted to my needs. In particular, I edited this file and changed.

duration: testSuite.perfStats.end - testSuite.perfStats.start,

to

duration: test.duration,

But again, you do not need to fork this, write the one that best suits your needs.

ouflak
  • 2,458
  • 10
  • 44
  • 49
cecia234
  • 46
  • 1
  • 6