Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Infinite loop #197

Open
FunnyGhost opened this issue May 12, 2017 · 4 comments
Open

Infinite loop #197

FunnyGhost opened this issue May 12, 2017 · 4 comments

Comments

@FunnyGhost
Copy link

FunnyGhost commented May 12, 2017

Hello,

I am working on a project with angular cli. Up until a few days ago I was using karma out of the box and chrome and everything works. However, I want a headless browser for my CI and I am trying to use karma-phantomjs-launcher.
The problem is that it never stops executing tests. Even with single run it executes them over and over again.
Here is the debug level info:

....
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 24 of 27 SUCCESS (0 secs / 8.736 secs)
12 05 2017 09:51:38.817:DEBUG [middleware:karma]: custom files null null
12 05 2017 09:51:38.818:DEBUG [middleware:karma]: Serving static request /context.html
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 26 of 27 SUCCESS (0 secs / 9.132 secs)
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 50 of 27 SUCCESS (0 secs / 18.412 secs)
12 05 2017 09:51:48.947:DEBUG [middleware:karma]: custom files null null
12 05 2017 09:51:48.949:DEBUG [middleware:karma]: Serving static request /context.html
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 51 of 27 SUCCESS (0 secs / 18.615 secs)
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 76 of 27 SUCCESS (0 secs / 27.636 secs)
12 05 2017 09:51:58.667:DEBUG [middleware:karma]: custom files null null
12 05 2017 09:51:58.668:DEBUG [middleware:karma]: Serving static request /context.html
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 77 of 27 SUCCESS (0 secs / 27.839 secs)
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 102 of 27 SUCCESS (0 secs / 36.78 secs)
12 05 2017 09:52:08.327:DEBUG [middleware:karma]: custom files null null
12 05 2017 09:52:08.328:DEBUG [middleware:karma]: Serving static request /context.html
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 103 of 27 SUCCESS (0 secs / 36.977 secs)
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 112 of 27 SUCCESS (0 secs / 39.392 secs)

And it just goes on and on like this.
The last test that I added is this:

    it('should break', () => {
        expect(true).toBe(false);
    });

So, it should fail, but apparently is not even executed.
Here is my karma.conf.js file:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-phantomjs-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: ['PhantomJS'],
    customLaunchers: {
      'PhantomJS_custom': {
        base: 'PhantomJS', 
        flags: ['--load-images=false'],
        debug: false
      }
    },
    phantomjsLauncher: {
      // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom) 
      exitOnResourceError: true
    },
    singleRun: false
  });
};

The command I am running is:
ng test -sr --log-level=debug --browsers PhantomJS_custom

@yuvicode
Copy link

try :
ng test --single-run

@andremarcondesteixeira
Copy link

I have this issue also

@ChadBH
Copy link

ChadBH commented Dec 7, 2018

I ran into this because I had junitReporter putting an output file in src/app, which caused it to be watched, so it would trigger a relaunch, update the output file, relaunch, update the output, etc.

So if your tests generate output files, don't put them where they'll be watched.

@crh225
Copy link

crh225 commented Mar 6, 2019

In karma.config.js file set singleRun to true. Mine was set to false.
I tried command line for singleRun and it didnt work.
singleRun: true ==========> I had this set to false, setting this to true helped

// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function ( config ) {
  config.set( {
    basePath: '',
    frameworks: [ 'jasmine', '@angular-devkit/build-angular' ],
    plugins: [
      require( 'karma-jasmine' ),
      require( 'karma-chrome-launcher' ),
      require( 'karma-jasmine-html-reporter' ),
      require( 'karma-coverage-istanbul-reporter' ),
      require( '@angular-devkit/build-angular/plugins/karma' )
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require( 'path' ).join( __dirname, 'coverage' ),
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    reporters: [ 'progress', 'kjhtml' ],
    port: 9876,
    browsers: [ 'Chrome' ],
    logLevel: config.LOG_INFO,
    singleRun: true ==========> I had this set to false, setting this to true helped
  } );
};

All is well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants