我正在尝试使用Karma,Jasmine和Webpack测试(使用覆盖率)我的TypeScript应用程序.通过以下内容,我能够成功运行测试,但无法正确生成覆盖.我正在使用karma-remap-coverage
(https://github.com/sshev/karma-remap-coverage),看起来很简单.
它看起来好像一些有趣的事情正在发生的事情(和我得到某种覆盖报告),但在这里和那里了一些调整,这些数字彻底改变,我永远不能真正加载sourcemaps.
这是基本设置:
我有一个src
包含10个.ts
文件的目录.目前只有一个.spec
文件具有相应的文件.
该spec
文件非常简单,足以证明我可以运行测试:
import ComponentToTest from './componentToTest';
describe('ComponentToTest', () => {
it('should run a test', () => {
expect(1+1).toBe(2);
});
it('should be able to invoke the a method', () => {
spyOn(ComponentToTest, 'foo').and.callThrough();
ComponentToTest.foo('testing foo');
expect(ComponentToTest.foo).toHaveBeenCalled();
});
});
Run Code Online (Sandbox Code Playgroud)
当与我的tsconfig.json
文件配对时,这就像一个魅力:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true,
"lib": ["es6", "dom"],
"experimentalDecorators": true
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
和 …
在尝试创建伊斯坦布尔报告(angular2-cli应用程序)时,出现以下错误
[Error: Could not find source map for:"/Users/dylan/IdeaProjects/IssueTracker2-UI/code/dist/vendor/es6-shim/es6-shim.js"]
[Error: Could not find source map for: "/Users/dylan/IdeaProjects/IssueTracker2-UI/code/dist/vendor/zone.js/dist/zone.js"]
Error: Could not find file: "/Users/dylan/IdeaProjects/IssueTracker2-UI/code/dist/vendor/systemjs/dist/system-polyfills.js.map"
Run Code Online (Sandbox Code Playgroud)
这是我跑步的时候npm run posttest
.这在我的package.json中有说明如下.
"posttest": "node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage -t html",
"coverage": "http-server -c-1 -o -p 9875 ./coverage"
Run Code Online (Sandbox Code Playgroud)
在下面我将显示我的karma.conf.js
文件
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '..',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-coverage')
],
customLaunchers: {
// chrome setup for travis CI …
Run Code Online (Sandbox Code Playgroud) 我想istanbul
将从客户端获取的 JSON 格式的覆盖率报告文件转换为 html 格式。目前我正在使用remap-istanbul
这个,但实际上那个特定的工具旨在为最初用不同语言(如打字稿)编写的代码重新映射覆盖率数据。
所以我想是否有更方便的方法来做同样的事情