'write results of a test to external file using json

I have a spec 'CreateDepartment.ts' and have a few tests inside this file. And, I want to store the current test title, state, and error (if any) in an external JSON file after each test executed from 'CreateDepartment.ts'.

this.currentTest?.title
this.currentTest?.state

Also, if a test is failed then I want to capture the error message also and store in the file?

this.currentTest?.error

Could someone please help on this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source