我只得到任何{included:true}文件的测试覆盖率结果,在我的例子中只有karma-test-shim.js . 我无法生成我的测试文件{included:true},因为SystemJs应该在karma-test-shim中加载它们 . 试图使我的测试文件{included:true}导致“不允许匿名系统寄存器调用”错误 . 我的测试运行良好{included:false} . 使用SystemJS在karma-test-shim中加载测试文件,并生成测试文件{included:false},是Angular 2 github repos遵循的标准格式,包括angular2-quickstart repo .

我使用"system"作为我的tsconfig.json文件中的模块格式而不是"commonjs",而电子浏览器代替Chrome(通过karma-electron NPM软件包),以及一行电子需要垫片在karma-test-shim文件中在 karma .loaded行之上 - 所有这些共同使得"requires"节点模块(如fs,path或已安装的节点模块)能够在没有预先捆绑的情况下在测试中工作 . 我的应用程序是使用Electron和Angular 2的桌面应用程序 .

除了这些差异,我有完全相同的测试设置(karma.conf.js和karma-test-shim.js)为https://github.com/juliemr/ng2-test-seed .

这是我的基本karma.conf.js文件:

module.exports = function(config) {
    config.set({

        basePath: 'src/', // all the files in the files config  parameter, are searched for relative to this path

        frameworks: ['jasmine'],

        files: files, // the files parameter exported from another file

        preprocessors: {'*.js': ['coverage']},

        reporters: ['spec', 'coverage'], //report to console

        port: 9876,

        colors: true,

        browsers: ['Electron'],

        singleRun: false // true is necessary for CI. Set to false so  the browser is on long enough to debug.

    })
}