2

我只得到任何 {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。

我在我的 tsconfig.json 文件中使用“system”作为模块格式而不是“commonjs”,使用 Electron 浏览器而不是 Chrome(通过 karma-electron NPM 包),以及一行 Electron require shim 在 karma- karma .loaded 行上方的 test-shim 文件- 所有这些一起使节点模块(如 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.

    })
}
4

0 回答 0