1
votes

We are using karma as the test runner for jasmine unit tests, testing an Angular application. We have over 6000 tests. Karma is so slow to run tests, and never gets past about 2700 tests (11 mins).

Is there a limit to the number of tests Karma can run, or is it normal for the performance of the test runner to degrade so much as the number of tests increase?

// Karma Config file
module.exports = function(config) {
  config.set({
    basePath: '../',
    frameworks: ['jasmine'],
    files: [
       ...list of files
    ],
    proxies: {
        '/images/': '/base/src/client/images/',
    },
    exclude: [
      'src/client/app/window/window.js'
    ],
    preprocessors: {
      '**/*.partial.html': ['ng-html2js']
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['Chrome'],
    singleRun: true,
    concurrency: Infinity,
    browserNoActivityTimeout: 100000,
    plugins: [
      'karma-jasmine',
      'karma-chrome-launcher',
      'karma-phantomjs-launcher',
      'karma-firefox-launcher',
      'karma-ie-launcher',
      'karma-ng-html2js-preprocessor'
    ],
    ngHtml2JsPreprocessor: {
      moduleName: 'templates',
      stripPrefix: 'src/client'
      }
  })
}
1
First of all, congratulations for being so dedicated about unit testing. 6K is a big number. Now, about slowness, there is a known issue about test execution being slow specially on chrome when karma tab is not in focus. If you are running manually, make sure that your chrome karma tab is in focus.TypeScripter
We do run the tests with Chrome tab focused, and they still run slow. We have also tried using Phantomjs, but they are equally as slow. Is there a Karma reporter to monitor test execution?Paddy

1 Answers

0
votes

To help slow test execution I have found using ng-bullet (https://www.npmjs.com/package/ng-bullet) has been quite helpful in speeding up my tests. With 6k tests, it would probably be quite an undertaking to get your components moved over but you should be able to do it one spec file at a time starting with the lengthier specs to see how much it helps execution time.

Another thing I've used to help with tests is by breaking the tests up into suites so that you can multiple suites in parallel or in smaller chunks if testing a specific part of the application. This article talks about that concept as well as using ng-bullet: https://www.forbes.com/sites/forbesdigitalgroup/2019/05/14/improve-your-angular-jasmine-unit-test-speeds-by-500/#45ee76a14163