Taranjit Kang
Taranjit Kang

Reputation: 2580

Karma Test running after executing tests screen goes blank

after running ng test my test runner begins executing all the tests but afterwards just goes blank. See image below.

enter image description here

My Karma Config:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'coverage-istanbul']
              : ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

my Package.json devDeps:

"devDependencies": {
"@angular/cli": "1.0.3",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"

}

Could it be a version issue? Maybe upgrade my Karma version? This was installed via cli, and I believe it was working earlier but somehow it has come to this.

Upvotes: 8

Views: 3116

Answers (4)

user31415
user31415

Reputation: 19

One more case where this issue happens is if you have listed browsers which are not installed on PC. Example: in your karma config file you have: browsers: ["Chrome", "Firefox", "IE"], but on your machine you do not have firefox, you would also get idle tests.

Upvotes: 0

Sahil Shikalgar
Sahil Shikalgar

Reputation: 821

It's because of npm version dependencies:-

 npm i --save-dev jasmine-core@latest
 npm i --save karma-jasmine@latest

Install these two dependencies this will resolve your issue.

Complete Package.json [FYR]

{
  "name": "karma-coverage-sample",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "karma start karma.conf.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "istanbul": "^0.4.5",
    "jasmine-core": "^3.5.0",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^2.0.1",
    "karma-jasmine-html-reporter": "^1.5.1"
  }
}

Upvotes: 1

mcgraphix
mcgraphix

Reputation: 2733

I was having this same issue. Setting the clearContext flag didn't make any difference.

For me though, it was only happening when using the --code-coverage argument. I was able to fix it by specifying the reporters manually:

karma start --code-coverage=true --reporters=progress,coverage-istanbul,kjhtml

Upvotes: 0

Philippe Plantier
Philippe Plantier

Reputation: 8073

The culprit is the client.clearContext option in the Karma configuration :

If true, Karma clears the context window upon the completion of running the tests. If false, Karma does not clear the context window upon the completion of running the tests. Setting this to false is useful when embedding a Jasmine Spec Runner Template.

To avoid blanking the screen, disable this option, like so (karma.conf.js):

module.exports = function (config) {
    config.set({
        /* ... */
        client: {
            clearContext: false
        }
        /* ... */
    })
}

Upvotes: 7

Related Questions