Applicable when
- You need to generate code coverage reports in the form of HTML, Cobertura, Text summary, etc for Lambda functions written in TypeScript.
Implementation
When you have a collection of Lambda functions and associated unit tests written in TypeScript you will probably be interested to generate code coverage reports at some point in time. You might be tempted to use Karma to achieve this goal. However, it requires an unnecessarily high amount of configuration and plugin setup in order to launch your tests in a browser correctly for code originally intended to run on NodeJs. In addition, you may need to further configure your remote CI CD server to guarantee the browser runs correctly in Karma.
As an alternative, we can install nyc instead to achieve the same goal with minimal configuration.
Let's assume you are using jasmine-ts to run your TS unit tests (keep in mind nyc also has support for other JS testing frameworks such as Mocha) and the command you use to generate your tests is: jasmine-ts \"path/to/specs/**/*.spec.ts\". At this point, all you need to do is call your usual test command with nyc and provide some optional configuration parameters. For example:
...
// Cd to coverage report folder before the actual stage
stage('Publish coverage report') {
steps {
cobertura(
coberturaReportFile: '*.xml',
)
}
}
...
Comments
0 comments
Please sign in to leave a comment.