Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

angular - 业力并行执行测试用例两次(karma parallel executing test cases twice)

I am upgrading my angular from 4 to version 7. I had karma-parallel to run the tdd and it was working as expected with Angular 4. Now after upgrading to 7 the same tests are running twice before stop executing.

(我正在将我的angular从4升级到版本7。我已经运行了karma-parallel来运行tdd,并且可以按预期与Angular 4一起工作。现在升级到7后,相同的测试运行了两次,然后停止执行。)

My karma.conf.js is as below,

(我的karma.conf.js如下所示,)

const path = require('path');
module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: [ 'parallel', 'jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-parallel'),
      require('karma-jasmine'),
      require('karma-spec-reporter'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    parallelOptions: {
      executors: 3, // For Jenkins enterprise, stick to 6 executors. For local laptop, change to 3-5
      shardStrategy: 'round-robin'
    },
    client: {
      jasmine: {
        random: false
      },
      clearContext: false
    },
    coverageIstanbulReporter: {
      reports: ['html', 'json', 'text-summary'],
      dir: path.join(__dirname, 'coverage'),
      fixWebpackSourcePaths: true
    },    
    reporters: ['spec', 'kjhtml'],
    specReporter: {
         maxLogLines: 5,
         suppressErrorSummary: true,
         suppressFailed: false,
         suppressPassed: false,
         suppressSkipped: true,
         showSpecTiming: true,
         failFast: false
      },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadlessNoSandbox'],
    customLaunchers: {
        ChromeHeadlessNoSandbox: {
            base: 'ChromeHeadless',
            flags: [
                '--no-sandbox', // required to run without privileges in docker
                '--user-data-dir=/tmp/chrome-test-profile',
                '--disable-web-security',
                '--no-proxy=http://0.0.0.0:9876/'
            ]
        }
    },
    singleRun: true,
    concurrency: Infinity,
    captureTimeout: 180000,
    browserDisconnectTimeout: 90000,
    browserNoActivityTimeout: 180000
  });
};

The command used to run the test cases is as below,

(用于运行测试用例的命令如下,)

node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng test --watch=false --code-coverage --source-map=false

Please advice.

(请指教。)

  ask by Geo j translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So I have found the issue.

(所以我找到了问题。)

In angular.json file i have 2 projects both have the test block configured and that was causing it to run twice.

(在angular.json文件中,我有2个项目都配置了测试块,这导致它运行两次。)

Removing the last project test block resolved it.

(删除最后一个项目测试块即可解决。)

Not sure how Angular 4 was running the TDD only once while with the same configuration Angular 7 run it twice.

(不确定Angular 4如何仅运行一次TDD,而在相同配置下Angular 7却运行两次。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...