简体   繁体   English

Karma 在所有测试运行之前断开连接

[英]Karma disconnects before all tests run

We are using karma as the test runner for jasmine unit tests, testing an Angular application.我们使用 karma 作为 jasmine 单元测试的测试运行器,测试一个 Angular 应用程序。 We have over 6000 tests.我们有超过 6000 次测试。 Karma is so slow to run tests, and never gets past about 2700 tests (11 mins). Karma 运行测试的速度非常慢,并且从未超过大约 2700 次测试(11 分钟)。

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 可以运行的测试数量是否有限制,或者测试运行器的性能随着测试数量的增加而下降这么多是否正常?

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

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.为了帮助减缓测试执行,我发现使用 ng-bullet ( https://www.npmjs.com/package/ng-bullet ) 对加快我的测试很有帮助。 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.使用 6k 测试,让您的组件移动可能是一项艰巨的任务,但您应该能够一次完成一个规范文件,从较长的规范开始,看看它对执行时间有多大帮助。

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本文讨论了该概念以及使用 ng-bullet: https : //www.forbes.com/sites/forbesdigitalgroup/2019/05/14/improve-your-angular-jasmine-unit-test-speeds-by- 500/#45ee76a14163

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM