Karma - 如何指向 typescript 覆盖的源地图
Karma - How to point to a source map for typescript coverage
我喜欢用 karma-coverage 为我的 typescript 源文件生成覆盖率报告。我的单元测试是用 javascript 编写的,我使用的是 Jasmine 测试框架。
我的文件夹结构如下所示:
node_modules/
app/
app.js
app.js.map
app.ts
components/
controllers/
SampleController.ts
directives/
filters/
services/
unittests/
karma.conf.js
components/
controllers/
SampleControllerTest.js
directives/
filters/
services/
我的karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-coverage',
'karma-phantomjs-launcher',
'karma-sourcemap-loader'
],
preprocessors: {
'../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ],
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'../app/app.js' : ['sourcemap', 'coverage' ],
},
reporters: ['progress', 'coverage'],
// web server port
port: 9876,
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
// and some other stuff
});
};
目前我的覆盖率报告提供了足够的指标,但与单个打字稿文件无关,而是 app.js。
我想我要么搞砸了预处理器配置,要么我需要指定源映射。
有什么提示吗?
使用 karma-istanbul-remap 对我有用。
karma.conf.js:
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-coverage',
'karma-phantomjs-launcher',
'karma-remap-istanbul'
],
preprocessors: {
'../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ],
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'../app/app.js' : ['coverage' ],
},
reporters: ['progress', 'coverage', 'karma-remap-istanbul'],
// web server port
port: 9876,
coverageReporter: {
type : 'json',
subdir : '.',
dir : 'coverage/',
file : 'coverage.json'
},
remapIstanbulReporter: {
src: 'coverage/coverage.json',
reports: {
lcovonly: 'coverage/lcov.info',
html: 'coverage/html/report'
},
timeoutNotCreated: 5000, // default value
timeoutNoMoreFiles: 1000 // default value
},
// and some other stuff
});
};
我喜欢用 karma-coverage 为我的 typescript 源文件生成覆盖率报告。我的单元测试是用 javascript 编写的,我使用的是 Jasmine 测试框架。
我的文件夹结构如下所示:
node_modules/
app/
app.js
app.js.map
app.ts
components/
controllers/
SampleController.ts
directives/
filters/
services/
unittests/
karma.conf.js
components/
controllers/
SampleControllerTest.js
directives/
filters/
services/
我的karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-coverage',
'karma-phantomjs-launcher',
'karma-sourcemap-loader'
],
preprocessors: {
'../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ],
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'../app/app.js' : ['sourcemap', 'coverage' ],
},
reporters: ['progress', 'coverage'],
// web server port
port: 9876,
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
// and some other stuff
});
};
目前我的覆盖率报告提供了足够的指标,但与单个打字稿文件无关,而是 app.js。
我想我要么搞砸了预处理器配置,要么我需要指定源映射。
有什么提示吗?
使用 karma-istanbul-remap 对我有用。
karma.conf.js:
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-coverage',
'karma-phantomjs-launcher',
'karma-remap-istanbul'
],
preprocessors: {
'../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ],
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'../app/app.js' : ['coverage' ],
},
reporters: ['progress', 'coverage', 'karma-remap-istanbul'],
// web server port
port: 9876,
coverageReporter: {
type : 'json',
subdir : '.',
dir : 'coverage/',
file : 'coverage.json'
},
remapIstanbulReporter: {
src: 'coverage/coverage.json',
reports: {
lcovonly: 'coverage/lcov.info',
html: 'coverage/html/report'
},
timeoutNotCreated: 5000, // default value
timeoutNoMoreFiles: 1000 // default value
},
// and some other stuff
});
};