我整个早上都在阅读有关此问题的文章,试图正确设置我的环境。但由于某种原因我不明白。我的设置-
/app
... source (mixed js and ts)
/scripts
... copied source (js)
typescripts.js // transpiled typescript with inline mapping
测试运行良好,并且通过 chrome 调试器中的映射调试可以正确映射。但伊斯坦布尔看到typescripts.js
文件作为一个文件而不是数十个其他文件的串联。
生成我正在使用的打字稿源gulp-typescript
。源代码(不包括测试)被转换为上述内容typescripts.js
,并且测试被单独转译并复制到/scripts
.
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
module.exports = function (gulp, config) {
'use strict';
// Runs dot ts files found in `www` through the typescript compiler and copies them as js
// files to the scripts directory
gulp.task('typescript', ['typescript:tests'], function () {
return gulp.src(config.paths.typescript) // [ './www/app/**/*.ts', '!./www/app/**/*.test.ts', '!./www/app/**/*.mock.ts' ]
.pipe(sourcemaps.init())
.pipe(ts(ts.createProject(config.paths.tsConfig))) // './tsconfig.json'
.js
.pipe(concat(config.sourcemaps.dest)) // typescripts.js
.pipe(sourcemaps.write(config.sourcemaps)) // { includeContent: false, sourceRoot: '/app' } - i've also tried absolute local path
.pipe(gulp.dest(config.paths.tmpScripts)); // ./www/scripts
});
gulp.task('typescript:tests', [], function() {
return gulp.src(config.paths.typescriptTests) // [ './www/app/**/*.test.ts', './www/app/**/*.mock.ts' ]
.pipe(ts(ts.createProject(config.paths.tsConfig))) // './tsconfig.json'
.pipe(gulp.dest(config.paths.tmpScripts)); // ./www/scripts
});
};
所结果的typescripts.js
有内联源映射。使用源映射,十多个 ts 文件的大小为 106kb。
所以从这里开始测试和调试工作正常。
现在,为了让伊斯坦布尔代码覆盖率正常工作,我已经安装了karma-sourcemap-loader
并将其添加到预处理器中。
preprocessors: {
'www/scripts/typescripts.js': ['sourcemap'],
'www/scripts/**/*.js': ['coverage']
},
我想这就是我需要做的。但它不显示源文件的代码覆盖率。我尝试了绝对路径C:/
但这也不起作用。我也尝试了不同的选项gulp-sourcemaps
就像添加源代码(将文件推到 160kb),但也不像。
有人让它发挥作用吗?有什么想法我可能做错了什么吗?