0

I'm trying to put up angular2 scaffolding using karma, jasmine, webpack by following various sources from online to get a deeper understanding.

I'm using istanbul-instrumenter-loader for karma coverage reporting.

When I run npm test I get following output:

ksharifbd:provat Admin$ npm test

> provat@0.0.1 test /Users/Admin/Downloads/kamal/development/self/provat
> karma start ./testconfig/karma/karma.conf.js --browsers Chrome

root directory: /Users/Admin/Downloads/kamal/development/self/provat
source directory: /Users/Admin/Downloads/kamal/development/self/provat/src

webpack: bundle is now VALID.
webpack: bundle is now INVALID.
ts-loader: Using typescript@2.0.3 and /Users/Admin/Downloads/kamal/development/self/provat/tsconfig.json
22 10 2016 18:48:15.719:WARN [karma]: No captured browser, open http://localhost:9876/

webpack: bundle is now VALID.
22 10 2016 18:48:15.741:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
22 10 2016 18:48:15.742:INFO [launcher]: Launching browser Chrome with unlimited concurrency
22 10 2016 18:48:15.859:INFO [launcher]: Starting browser Chrome
22 10 2016 18:48:17.420:INFO [Chrome 54.0.2840 (Mac OS X 10.10.4)]: Connected on socket /#m-tmeGM-JMz_OSU4AAAA with id 80103692
Chrome 54.0.2840 (Mac OS X 10.10.4): Executed 1 of 1 SUCCESS (0.129 secs / 0.104 secs)
Error: Could not find source map for: "/Users/Admin/Downloads/kamal/development/self/provat/src/modules/greetings/component/greetings.component.ts"
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/remap-istanbul/lib/remap.js:257:11
at Array.forEach (native)
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/remap-istanbul/lib/remap.js:214:22
at Array.forEach (native)
at remap (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/remap-istanbul/lib/remap.js:213:12)
at RemapCoverageReporter.onCoverageComplete (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-remap-coverage/remap-coverage.js:23:23)
at Server.<anonymous> (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma/lib/events.js:13:22)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at InMemoryReport.writeReport (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/in-memory-report.js:14:22)
at writeReport (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/reporter.js:68:16)
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/reporter.js:290:11
at Array.forEach (native)
at Collection.forEach (/Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma/lib/browser_collection.js:93:21)
at /Users/Admin/Downloads/kamal/development/self/provat/node_modules/karma-coverage/lib/reporter.js:247:16
at Array.forEach (native)

=============================== Coverage  summary===============================
Statements   : 82.35% ( 14/17 )
Branches     : 48.28% ( 14/29 )
Functions    : 100% ( 4/4 )
Lines        : 91.67% ( 11/12 )
================================================================================

Rather than posting outputs from multiple files, I have put all the codes in Github with README.

Your help will be highly appreciated.

ksharifbd
  • 5,102
  • 2
  • 18
  • 23

2 Answers2

4

I was facing same problem, There is an issue with "istanbul-instrumenter-loader", downgrading to version "^0.2.0" works.

Change your package.json and reinstall the package

npm un  istanbul-instrumenter-loader --save-dev

and

npm i istanbul-instrumenter-loader@^0.2.0 --save-dev

Here is coverage for one of the file

enter image description here

Ajay Bhosale
  • 1,872
  • 24
  • 35
  • @Ajay Bhosle, I am facing the same issue, but downgrading karma-instrumenter-loader isn't working for me. Here is link to question i have posted http://stackoverflow.com/questions/40546022/error-could-not-find-source-map-for-in-angular2-karma-webpack-and-istanbul. Can you help me out? – gschambial Nov 11 '16 at 11:03
  • Have you found a solution ? – Jerzy Gruszka Nov 18 '16 at 11:24
  • Please refer https://github.com/bhosale-ajay/minimalistic-angular-starter-kit, for complete example – Ajay Bhosale Nov 19 '16 at 08:01
0

I'm not sure whether downgrading istanbul-instrumenter-loader will work or not. But downgrading it to the lowest is not a good practice and fit always. The problem here is test load could not find source map for the particular files. And it's not necessary in testing phase. So we can fix by adding "sourceMap": false to the test configuration in angular.json file as below.

    "test": {
      "builder": "ngx-build-plus:karma",
      "options": {
        "main": "src/test.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.spec.json",
        "karmaConfig": "karma.conf.js",
        "sourceMap": false,  // <---
        "styles": [
          "src/styles.scss"
        ],
        "scripts": [],
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ]
      }
    },
Anand Raja
  • 2,676
  • 1
  • 30
  • 35