karma-runner / karma-chrome-launcher

A Karma plugin. Launcher for Chrome and Chrome Canary.
MIT License
467 stars 120 forks source link

Tests are often not rerunning when files change #221

Open jdcai opened 4 years ago

jdcai commented 4 years ago

I'm using karma with an angular project. When I do ng test --browsers=Chrome it will run the test the first time. If I make a change to a file it will compile and then the tests won't get rerun. If I keep on trying to change a file it will randomly rerun test sometimes but most of the time it won't run them. When it doesn't rerun tests it shows this in the debug messages and just stays there.

23 04 2020 14:46:30.985:DEBUG [karma-server]: List of files has changed, trying to execute
23 04 2020 14:46:30.986:DEBUG [karma]: All browsers are ready, executing
23 04 2020 14:46:30.986:DEBUG [karma]: Captured 1 browsers

It also happens with ChromeHeadless. It doesn't seem to happen with Firefox though.

karma.conf.js

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-firefox-launcher'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: true, 
      jasmine: {
        failSpecWithNoExpectations: true
      }
    },
    mime: {
      'text/x-typescript': ['ts', 'tsx']
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true,
      thresholds: {
        emitWarning: false, 
        // thresholds for all files
        global: {
          statements: 80, 
          branches: 60, 
          functions: 75, 
          lines: 80, 
        },
        // thresholds per file
        each: {
          statements: 60, 
          lines: 60, 
          branches: 25, 
          functions: 35, 
        }
      },
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['ChromeHeadless', 'FirefoxHeadless'],
    captureTimeout: 120000,
    customLaunchers: {
      HeadlessChrome: {
        base: 'ChromeHeadless',
        flags: [
          '--headless',
          '--no-sandbox'
        ]
      },
      HeadlessFirefox: {
        base: 'FirefoxHeadless',
        flags: [
          '-headless',
        ],
      }
    },
    singleRun: false,
    restartOnFileChange: true
  });
};

Version karma-chrome-launcher: 3.1.0 karma: 5.0.2

tr1stan commented 11 months ago

I noticed this problem after upgrading an Angular app from 12 -> 14. it looks like updating to the latest version karma-chrome-launcher@3.2.0 has fixed the issue for me.