(Note: This blog applies to the Jasmine variant of the Lightning Testing Service)
Some or all of the following functions are required to handle the various events that occur as test are executed - basically things commencing and completing:
- jasmineStarted/jasmineDone - called before any specs (tests) execute/once all tests have completed
- suiteStarted/suiteDone - called before a specific suite (group of tests) execute/once they have completed
- specStarted/specDone - called before a specific test executes/once it has completed
Once you have your object with the desired functions, it must be registered before any tests are queued:
and that’s all there is to it.
Below is an example lightning component that creates a simple reporter to capture the success/failure of each suite/spec and log information to the console. Note that this relies on the Jasmine artefacts installed by the latest version of the Lightning Testing Service unmanaged package. The component is named KABJasmineReporter:
A couple of tweaks to the jasmineTests app to include my reporter (and to limit to a couple of tests, otherwise there’s a lot of information in the console log):
Executing the app produces the following console output:
While this has been a simple example, there’s a lot more that can be done with custom reporters, such as posting notifications with the tests results, which I plan to explore in later posts.