I have been working on a simple Angular/Typescript project that includes 12 basic unit tests which all pass successfully. However, I am now looking to measure the code coverage of these tests. Despite trying different methods, I have not been able to achieve this and have decided to start fresh with karma-coverage and seek assistance here.
When running karma, I encounter an error message for each source file similar to:
Failed to parse file: C:/Users/FRBA/Documents/MyProject/src/app/nav/new-panel/new-panel.component.ts
07 07 2017 07:54:35.832:ERROR [preprocessor.coverage]: Line 1: Unexpected token
at C:/Users/FRBA/Documents/MyProject/src/app/nav/new-panel/new-panel.component.ts
The configuration in my karma.conf.js file is as follows:
var path = require('path');
module.exports = function (config) {
config.set({
files: [
'src/app/**/*.ts',
'test/app/**/*.ts'
],
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-ie-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular/cli/plugins/karma')
],
client: {
clearContext: false
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml', 'coverage'],
preprocessors: {
'src/app/**/*.ts': ['coverage']
},
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', 'IE'],
singleRun: false
});
};
I have attempted several solutions - including karma-coverage, karma-coverage-istanbul-reporter, and karma-typescript - but encountered issues like empty reports and stalled execution. It seems there may be a fundamental error in my approach. Any guidance or tutorials tailored to beginners in karma (and Typescript) would be greatly appreciated. Thank you!