# Setting Up Test Coverage Profiling for JavaScript/TypeScript

To take advantage of the Test Gap analysis, you have to upload test coverage information to Teamscale.

Currently, only coverage information in the Istanbul (opens new window) profiler's JSON format is supported. Tools to produce coverage information can be found in our List of Test Coverage Tools.

Along with the coverage information, also a mapping from the exercised code to the original code is needed. The source code that is executed by the end-user is typically produced by a sequence of transformation steps, each augmenting (minifying, transpiling, enriching) the source code of the previous step, starting from the developers' original source code. For example, TypeScript is always transpiled to JavaScript before deployment. The coverage information resulting from running the tests refers to the transformed code instead of the original source code. Teamscale needs source-map files to map coverage information to the original source code. Teamscale allows for uploading source maps ahead of time, for example, when they are created during the build process.

The source code version must be provided for both the coverage information and the source mapping. Whenever you build your application, new mapping files are generated and Teamscale needs to know which mapping files to use when you upload coverage. Thus, during the upload of the mapping files, you must provide a version string (any unique string will do, e.g., a revision number). You must provide the exact same version string again when uploading coverage files that belong to those mapping files.

Test Gap analysis for JavaScript/TypeScript data flow


Please note that errors in the source maps can lead to subtle misalignment of the covered lines and thus to wrong coverage results. Please make absolutely sure that source maps are configured correctly for your entire build pipeline and that they correctly map back to your source files. Some minification/bundling tools are known to e.g., produce off-by-one source maps.

# Uploading Source Maps

The following is an example of how to upload source map files using curl:

curl --request POST \
--user bob:e434mikm35d \
--form "file=@./source.map" \

The branch:timestamp must be the branch name and commit timestamp in milliseconds of the commit which was processed by the build to generate the mapping file.

# Uploading Coverage files

The following is an example of how to upload Istanbul coverage files using curl:

curl --request POST \
--user bob:e434mikm35d \
--form "report=@./coverage.json" \