我正在将我的angular从4升级到版本7。我已经进行了业力并行运行tdd,并且它在Angular 4中可以按预期工作。现在,在升级到7之后,相同的测试运行两次,然后停止执行。我的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
});
};
用于运行测试用例的命令如下,
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng test --watch=false --code-coverage --source-map=false
请咨询。
所以我找到了问题。在angular.json文件中,我有2个项目都配置了测试块,这导致它运行两次。删除最后一个项目测试块即可解决。