Product
Solutions
Resources
Company
Download Trial Book a Demo

Code Coverage for JavaScript Applications

Generate code coverage for a JavaScript or TypeScript application with RKTracer in three simple steps. Install the rkserver app, instrument the selected folder with rktracer, run your tests, and produce an HTML report.

This guide shows you how to generate code coverage for a JavaScript based application in the command line interface using the RKTracer tool with 3 simple steps. The same workflow applies to JavaScript and TypeScript applications.

Setup RKTracer tool server to capture code coverage

You need to install the NodeJS rkserver app to receive code coverage from the instrumented application at runtime, and it is a one-time job per system. Install rkserver globally with the -g flag, then install the rk4js runtime package.

On Windows:

Windows install
npm install C:\rktracer\share\rktracer\rkserver-2.0.0.tgz -g
npm install C:\rktracer\share\rktracer\rk4js-2.0.11.tgz

On Linux:

Linux install
npm install /home/rk/rktracer/share/rktracer/rkserver-2.0.0.tgz -g
npm install /home/rk/rktracer/share/rktracer/rk4js-2.0.11.tgz

NodeJS setup on Linux

You can download the NodeJS from the official website and unzip it in your home folder, create a symlink to node, and then you need to set the path in the .bashrc file in home.

node symlink
which node
ln -s node-v14.17.5-linux-x64 node

Code Coverage for JavaScript/TypeScript applications example

Identify the project folder that needs to be instrumented and generate coverage data. Please make sure the project is configured and you are able to test it.

Enable the RKTracer tool

Instrument the selected folder with the rktracer tool. There might be multiple folders in the project, and based on the requirement, you can do selected instrumentation. Use rktracer -on to enable instrumentation for the chosen file type, and rktracer -off to disable it.

instrument folders
rktracer -on foldername1 .js -v
rktracer -on foldername1 .ts -v
rktracer -off foldername .js -v
rktracer -off foldername .ts -v

Start RKTracer server to capture code coverage at runtime

Before you start testing your application you need to execute the command rkserver in the project build folder to capture coverage data at runtime.

start the server
rkserver

Run Tests on instrumented application

Testing can be unit-testing or functional or integration testing of the application.

Generate Code Coverage reports

Once you have the rk-coverage.txt file, you need to run the rkresults command to generate the HTML reports.

generate the report
rkresults

Enable coverage for selected files

Edit rktracer.config in the RKTracer installation folder, go to the end of the file, and add the following information.

Coverage for selected folders

rktracer.config
ignore *.js
ignore *.ts
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*
  • ignore *.js and ignore *.ts ignore all JavaScript and TypeScript source files from instrumentation.
  • instrument instruments source files from the given folders.
  • never ignores the selected folders.

Coverage for selected functions

rktracer.config
ignore *.js
ignore *.ts
instrument *source-file-X.js *source-file-Y.js *source-file-Z.js
instrument *source-file-X.ts *source-file-Y.ts *source-file-Z.ts
function-ignore *
function-instrument fun_X() fun_Y() fun_Z()
  • ignore *.js and ignore *.ts ignore all JavaScript and TypeScript source files.
  • instrument instruments only the listed source files.
  • function-ignore * then ignores all functions in the above files.
  • function-instrument fun_X() fun_Y() fun_Z() targets these specific functions for instrumentation.

Stuck on your build?

Open a support ticket and an engineer who knows your toolchain will help. You get a tracked ticket ID by email.