Karma test framework

Gathering coverage and test information using the SeaLights Node.js Test Listener is done in a few steps and commands, detailed below in a table comparing the relevancy of each, depending on the type of tests you’re running

Step
Command
Unit Tests
Functional Tests

1

Starting the Test Stage

2

Executing your application instrumented by Sealights

3

Run your Karma tests

4.a

Upload Coverage Report

4.b

Upload JUnit Report

5

End the Test Stage

See 'Generating an Agent token' for instructions on how to generate a token

Starting the Test Stage

First, the SeaLights server needs to be notified that a test stage is starting.

npx slnodejs start --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --teststage "Unit Tests"ests"

See Starting a test stage for full parameter details

Running your tests

Functional Tests

Before running your functional tests, you need to set up your backend or frontend applications to send the coverage to Sealights (test footprints):

Once set up, you now run your tests normally while generating one or more JUnit XML result files to be reported to the SeaLights server.

Unit Tests

To report the test and coverage information to SeaLights, you need to run the karma tests while producing coverage information and a JUnit results file.

  • For the JUnit results XML file, you can use the karma-junit-reporter reporter.

  • For the coverage, you need to use the karma-coverage configured to generate a coverage-final.json file by using the coverageReporter type json.

To generate these report files, update your karma.conf.js and add or update the reporters, coverageReporter, and junitReporter sections:

Uploading Test Metadata

Upload coverage report files from Unit Tests

Once done running the Unit Tests, you upload the coverage report files to the SeaLights server using the nycReport option

Upload test results report files

Once done running the tests, you upload the test results file to the SeaLights server using the uploadReports option

Ending the Test Stage

Finally, the server needs to be notified that a test stage has ended.

Sample - Capturing Unit Tests with Karma

Below, a sample script running the Unit Tests while instrumenting for client-side (front-end) coverage

Last updated

Was this helpful?