Skip to content

Angular 6 Unit Test Coverage - reporting not accurate #26020

Closed

Description

@ChrisBadalucco

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

Unit test coverage reporting is no longer accurate (shows missed branches outside of logic e.g. in imports)

Expected behavior

Unit test coverage accurately reports coverage.

Minimal reproduction of the problem with instructions

  1. Create a new angular 6 project: ng new angular6-coverage-issue
  2. Execute tests with code coverage ng test --code-coverage
  3. View HTML report
    screen shot 2018-09-19 at 11 47 14 am

screen shot 2018-09-19 at 11 13 31 am

What is the motivation / use case for changing the behavior?

The motivation is to fix coverage reports so they can be used as an accurate measure.

Environment



For Tooling issues:
- Node version: 8.11.3
- Platform:  Mac

Others:
      _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.2.2
Node: 8.11.3
OS: darwin x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.5
@angular-devkit/build-angular     0.7.5
@angular-devkit/build-optimizer   0.7.5
@angular-devkit/build-webpack     0.7.5
@angular-devkit/core              0.8.2
@angular-devkit/schematics        0.8.2
@angular/cli                      6.2.2
@ngtools/webpack                  6.1.5
@schematics/angular               0.8.2
@schematics/update                0.8.2
rxjs                              6.3.2
typescript                        2.7.2
webpack                           4.9.2

Activity

  1. jhage-accesso commented on Sep 19, 2018

    @jhage-accesso
  2. benlesh commented on Sep 19, 2018

    @benlesh
    Contributor

    This was closed by: angular/angular-cli#12291

  3. thorstenherbst commented on Jul 15, 2019

    @thorstenherbst

    Hi @ALL,
    i have the same problem. Itryed already source-maps:true and the problem stays the same. Reporting is not accurate.

    Heres my configuration:

    ##angular-cli

    
    
         _                      _                 ____ _     ___
        / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
       / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
      / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
     /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                    |___/
        
    
    Angular CLI: 7.3.6
    Node: 10.15.2
    OS: darwin x64
    Angular: 
    ... 
    
    Package                      Version
    ------------------------------------------------------
    @angular-devkit/architect    0.13.6
    @angular-devkit/core         7.3.6
    @angular-devkit/schematics   7.3.6
    @schematics/angular          7.3.6
    @schematics/update           0.13.6
    rxjs                         6.3.3
    typescript                   3.2.4```
    

    package.json

    {
      "name": "web",
      "version": "0.0.0",
      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "grunt && ng build --prod",
        "build-dev": "grunt && ng build --extract-css --watch --aot --output-hashing=bundles",
        "build-debug": "grunt && ng build --source-map --extract-css --output-hashing=bundles",
        "build-svg": "grunt",
        "test": "ng test",
        "test-ci": "ng test --watch=false --browsers=ChromeHeadlessIuE --code-coverage",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "livereload": "livereload ./dist -e html -u true -w 250"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "^8.0.3",
        "@angular/common": "^8.0.3",
        "@angular/compiler": "^8.0.3",
        "@angular/core": "^8.0.3",
        "@angular/elements": "^8.0.3",
        "@angular/forms": "^8.0.3",
        "@angular/platform-browser": "^8.0.3",
        "@angular/platform-browser-dynamic": "^8.0.3",
        "@angular/router": "^8.0.3",
        "@ngrx/store": "^8.0.1",
        "@types/leaflet-fullscreen": "^1.0.4",
        "@types/leaflet.markercluster": "^1.4.0",
        "classlist.js": "^1.1.20150312",
        "core-js": "^2.6.9",
        "deep-equal": "^1.0.1",
        "leaflet": "^1.4.0",
        "leaflet.markercluster": "^1.4.1",
        "ngx-cookie-service": "^2.1.0",
        "rxjs": "^6.4.0",
        "s": "^0.1.1",
        "swiper": "^4.5.0",
        "tslib": "^1.10.0",
        "video.js": "^7.5.5",
        "zone.js": "~0.9.1"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "~0.800.6",
        "@angular/cli": "^8.0.6",
        "@angular/compiler-cli": "^8.0.3",
        "@angular/language-service": "^8.0.3",
        "@types/jasmine": "^3.3.13",
        "@types/jasminewd2": "^2.0.6",
        "@types/leaflet": "^1.4.3",
        "@types/node": "^10.14.10",
        "@types/swiper": "^4.4.3",
        "@types/video.js": "^7.2.10",
        "codelyzer": "^5.0.1",
        "grunt": "^1.0.3",
        "grunt-cli": "^1.3.2",
        "grunt-replace": "^1.0.1",
        "grunt-sass": "^3.0.2",
        "grunt-svgstore": "^2.0.0",
        "jasmine-core": "^3.3.0",
        "jasmine-spec-reporter": "^4.2.1",
        "karma": "^4.0.1",
        "karma-chrome-launcher": "^2.2.0",
        "karma-coverage-istanbul-reporter": "^2.0.5",
        "karma-jasmine": "^2.0.1",
        "karma-jasmine-html-reporter": "^1.4.0",
        "karma-junit-reporter": "^1.2.0",
        "livereload": "^0.8.0",
        "node-sass": "^4.11.0",
        "npm-check-updates": "^3.1.12",
        "protractor": "^5.4.2",
        "sass-loader": "^7.1.0",
        "ts-node": "^8.3.0",
        "tslint": "^5.18.0",
        "typescript": "~3.4.5",
        "webpack": "^4.35.0"
      }
    }
    

    ts-config

    {
    	"extends": "../tsconfig.json",
    	"compilerOptions": {
    		"outDir": "../out-tsc/app",
    		"types": []
    	},
    	"exclude": [
    		"src/test.ts",
    		"**/*.spec.ts"
    	]
    }
    

    angular.json

    {
    	"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    	"version": 1,
    	"newProjectRoot": "projects",
    	"projects": {
    		"web": {
    			"root": "",
    			"sourceRoot": "src",
    			"projectType": "application",
    			"prefix": "db",
    			"schematics": {
    				"@schematics/angular:component": {
    					"styleext": "scss"
    				}
    			},
    			"architect": {
    				"build": {
    					"builder": "@angular-devkit/build-angular:browser",
    					"options": {
    						"outputPath": "dist",
    						"index": "src/iue.html",
    						"main": "src/main.ts",
    						"polyfills": "src/polyfills.ts",
    						"tsConfig": "src/tsconfig.app.json",
    						"assets": [
    							"src/favicon.ico",
    							"src/assets/fonts",
    							{
    								"glob": "assets/{**/,}*.svg",
    								"input": "tmp",
    								"output": ""
    							},
    							{
    								"glob": "static/{**/,}*",
    								"input": "tmp",
    								"output": ""
    							},
    							"src/assets/images",
    							"src/assets/sounds",
    							"src/static",
    							"src/sw.js"
    						],
    						"styles": [
    							"node_modules/leaflet/dist/leaflet.css",
    							"node_modules/leaflet.markercluster/dist/MarkerCluster.css",
    							"node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css",
    							"node_modules/swiper/dist/css/swiper.min.css",
    							"node_modules/video.js/dist/video-js.min.css",
    							"src/styles.scss"
    						],
    						"scripts": [
    							"src/app/villains/helpers/livereload/livereload.dev.ts",
    							"node_modules/swiper/dist/js/swiper.min.js",
    							"node_modules/video.js/dist/video.min.js",
    							"node_modules/video.js/dist/lang/de.js",
    							"src/libs/custom-elements-es5/custom-elements-es5-adapter.js",
    							"src/libs/tracking/framework/AppMeasurement.min.js",
    							"tmp/libs/tracking/t4media-tracking.dev.js",
    							"src/libs/tracking/customCode.dev.min.js"
    						]
    					},
    					"configurations": {
    						"production": {
    							"fileReplacements": [
    								{
    									"replace": "src/environments/environment.ts",
    									"with": "src/environments/environment.prod.ts"
    								},
    								{
    									"replace": "src/app/villains/helpers/livereload/livereload.dev.ts",
    									"with": "src/app/villains/helpers/livereload/livereload.prod.ts"
    								},
    								{
    									"replace": "tmp/libs/tracking/t4media-tracking.dev.min.js",
    									"with": "tmp/libs/tracking/t4media-tracking.prod.min.js"
    								},
    								{
    									"replace": "src/libs/tracking/customCode.dev.min.js",
    									"with": "src/libs/tracking/customCode.prod.min.js"
    								}
    							],
    							"optimization": true,
    							"outputHashing": "all",
    							"sourceMap": false,
    							"extractCss": true,
    							"namedChunks": false,
    							"aot": true,
    							"extractLicenses": true,
    							"vendorChunk": false,
    							"buildOptimizer": true
    						}
    					}
    				},
    				"serve": {
    					"builder": "@angular-devkit/build-angular:dev-server",
    					"options": {
    						"browserTarget": "web:build"
    					},
    					"configurations": {
    						"production": {
    							"browserTarget": "web:build:production"
    						}
    					}
    				},
    				"extract-i18n": {
    					"builder": "@angular-devkit/build-angular:extract-i18n",
    					"options": {
    						"browserTarget": "web:build"
    					}
    				},
    				"test": {
    					"builder": "@angular-devkit/build-angular:karma",
    					"options": {
    						"progress": false,
    						"main": "src/test.ts",
    						"polyfills": "src/polyfills.ts",
    						"tsConfig": "src/tsconfig.spec.json",
    						"karmaConfig": "src/karma.conf.js",
    						"styles": [
    							"src/styles.scss"
    						],
    						"scripts": [],
    						"assets": [
    							"src/favicon.ico",
    							"src/assets"
    						]
    					}
    				},
    				"lint": {
    					"builder": "@angular-devkit/build-angular:tslint",
    					"options": {
    						"tsConfig": [
    							"src/tsconfig.app.json",
    							"src/tsconfig.spec.json"
    						],
    						"exclude": [
    							"**/node_modules/**"
    						]
    					}
    				}
    			}
    		},
    		"web-e2e": {
    			"root": "e2e/",
    			"projectType": "application",
    			"architect": {
    				"e2e": {
    					"builder": "@angular-devkit/build-angular:protractor",
    					"options": {
    						"protractorConfig": "e2e/protractor.conf.js",
    						"devServerTarget": "web:serve"
    					},
    					"configurations": {
    						"production": {
    							"devServerTarget": "web:serve:production"
    						}
    					}
    				},
    				"lint": {
    					"builder": "@angular-devkit/build-angular:tslint",
    					"options": {
    						"tsConfig": "e2e/tsconfig.e2e.json",
    						"exclude": [
    							"**/node_modules/**"
    						]
    					}
    				}
    			}
    		}
    	},
    	"defaultProject": "web"
    }
    

    Help is very appreciated.

    Thanks in advance.

  4. angular-automatic-lock-bot commented on Sep 15, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions