Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 833
Taranjit Kang Avatar asked Aug 04 '17 14:08

Taranjit Kang


2 Answers

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
        }
        /* ... */
    })
}
like image 78
Philippe Plantier Avatar answered Nov 14 '22 08:11

Philippe Plantier


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"
  }
}
like image 22
Sahil Shikalgar Avatar answered Nov 14 '22 08:11

Sahil Shikalgar