angular 伊斯坦布尔代码覆盖率报告中的导入未采用 if-else 路径
if-else path not taken in imports in angular istanbul code coverage report
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Com(I)ponent({
selector: 'app-fruit-cake',(E)
templateUrl: './fruit-cake.component.html',
styleUrls: ['./fruit-cake.component.scss'],
})
expo(E)rt class FruitCakeComponent {
constructor(private _title: Title) {
_title.setTitle('Cake');
}
}
我的代码覆盖率报告显示 (E):否则未采用路径。 (I):如果没有选择路径。
在 import 语句和装饰器的上下文中是什么意思?
因此,在我的任何测试中,我的代码覆盖率都没有达到 100%。
我该如何纠正?
我不得不删除:
--sourceMap=false
之前,我添加这个是为了帮助诊断其他问题。所以我在 package.json 中的 测试脚本 看起来像这样:
"test": "ng test --code-coverage --sourceMap=false"
我改成:
"test": "ng test --code-coverage"
然后,我所有的代码覆盖率开始正确报告。您可能还想在 package.json 中验证您的 devDependencies。我正在使用 Angular 6 所以它们看起来像这样:
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
对于 Angular 6,您似乎需要像这样 "sourceMap": true
到您的 test
:
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "test/test.ts",
"karmaConfig": "./karma.conf.js",
"sourceMap": true,
"polyfills": "src/polyfills.ts",
"tsConfig": "test/tsconfig.spec.json",
"scripts": [],
"styles": [],
"assets": [
"src/assets"
],
"codeCoverageExclude": []
}
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Com(I)ponent({
selector: 'app-fruit-cake',(E)
templateUrl: './fruit-cake.component.html',
styleUrls: ['./fruit-cake.component.scss'],
})
expo(E)rt class FruitCakeComponent {
constructor(private _title: Title) {
_title.setTitle('Cake');
}
}
我的代码覆盖率报告显示 (E):否则未采用路径。 (I):如果没有选择路径。 在 import 语句和装饰器的上下文中是什么意思? 因此,在我的任何测试中,我的代码覆盖率都没有达到 100%。 我该如何纠正?
我不得不删除:
--sourceMap=false
之前,我添加这个是为了帮助诊断其他问题。所以我在 package.json 中的 测试脚本 看起来像这样:
"test": "ng test --code-coverage --sourceMap=false"
我改成:
"test": "ng test --code-coverage"
然后,我所有的代码覆盖率开始正确报告。您可能还想在 package.json 中验证您的 devDependencies。我正在使用 Angular 6 所以它们看起来像这样:
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
对于 Angular 6,您似乎需要像这样 "sourceMap": true
到您的 test
:
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "test/test.ts",
"karmaConfig": "./karma.conf.js",
"sourceMap": true,
"polyfills": "src/polyfills.ts",
"tsConfig": "test/tsconfig.spec.json",
"scripts": [],
"styles": [],
"assets": [
"src/assets"
],
"codeCoverageExclude": []
}