Paddy
Paddy

Reputation: 41

Karma disconnects before all tests run

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'
      }
  })
}

Upvotes: 2

Views: 2280

Answers (1)

Nortain
Nortain

Reputation: 143

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

Upvotes: 0

Related Questions