Karma: singleRun not closing any browser

Created on 7 Sep 2016  路  5Comments  路  Source: karma-runner/karma

Expected behaviour

With singleRun:true set,
after tests done, closing all browsers which where fetched for tests

Actual behaviour

Doing nothing. Browser instances used for testing stay open after tests done.

Environment Details

  • Win7
  • Node v6.2.2
  • Karma version 1.2.0:
  • PhantomJS 2.1.21
  • Firefox 48.0.2

frameworks: ['jasmine-jquery', 'jasmine'],
browsers: ['PhantomJS', 'Firefox'],
reporters: ['coverage', 'junit'],
singleRun: true,
logLevel: config.LOG_DEBUG,

feedback-from-author

Most helpful comment

I just installed the CLI, and specifying --single-run on the command line works properly. Only the property in the config file is being ignored.

I guess for now a workaround is to tweak the npm test command to supply the --single-run param.

All 5 comments

@HerrDerb do you run karma from console?
If yes then which exit status return karma start ... command

Thanks

I am getting the same behavior. This is affecting my integration builds on Travis CI.

karma.conf.js:

module.exports = function (config) {
  let configuration = {
    basePath: '',
    frameworks: ['jasmine', 'angular-cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-remap-istanbul'),
      require('angular-cli/plugins/karma')
    ],
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['angular-cli']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    remapIstanbulReporter: {
      reports: {
        html: 'coverage',
        lcovonly: './coverage/coverage.lcov'
      }
    },
    angularCli: {
      config: './angular-cli.json',
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'karma-remap-istanbul']
              : ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    customLaunchers: {
      ChromeTravisCI: {
        base: 'Chrome',
        flags: ['--no-sandbox'],
        displayName: 'Chrome (Travis CI)'
      }
    }
  };

  if (process.env.TRAVIS) {
    configuration.browsers = ['ChromeTravisCI'];
    configuration.singleRun = true;
  }

  config.set(configuration);
};

I can simulate the behavior by setting the TRAVIS environment variable locally.

(master)*$ TRAVIS=true npm test

> [email protected] test /home/emcintyre/Development/src/macdaddy/desk-calendar
> ng test

01 02 2017 00:06:06.370:WARN [karma]: No captured browser, open http://localhost:9876/   
01 02 2017 00:06:06.378:INFO [karma]: Karma v1.4.1 server started at http://0.0.0.0:9876/
01 02 2017 00:06:06.378:INFO [launcher]: Launching browser ChromeTravisCI with unlimited concurrency
01 02 2017 00:06:06.429:INFO [launcher]: Starting browser Chrome (Travis CI)
01 02 2017 00:06:07.278:INFO [Chrome (Travis CI)]: Connected on socket dyUOKZZcSRp18syGAAAA with id 60222982
Chrome (Travis CI): Executed 27 of 27 SUCCESS (0.814 secs / 0.79 secs)
^C

Karma is definitely using my Travis browser config (note the "Chrome (Travis CI)" in the log). But when the tests are complete, the runner and browser just sit there. I have to Ctrl-C to stop them. I see the same behavior in Karma 1.2.0 and 1.4.1.

I just installed the CLI, and specifying --single-run on the command line works properly. Only the property in the config file is being ignored.

I guess for now a workaround is to tweak the npm test command to supply the --single-run param.

I'm seeing both --single-run argument and the config file parameter being ignored when karma is launched from another process. Both work as expected when the same command line is executed in a shell.

Win10
node v7.4
[email protected]
[email protected]
[email protected]

I can upload a test case if you need it.

EDIT: resolved - this case was caused by reading from the stdout on completion but the amount of output fills up an internal system buffer stalling the karma process. Stdout has to be read asynchronously to let it complete properly.

singleRun: true is now being respected properly.
This issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macjohnny picture macjohnny  路  5Comments

sneakyfildy picture sneakyfildy  路  3Comments

TKTheTechie picture TKTheTechie  路  4Comments

mboughaba picture mboughaba  路  3Comments

danielsiwiec picture danielsiwiec  路  5Comments