Geo*_*o j 2 tdd karma-jasmine angular
我正在将我的 angular 从 4 升级到版本 7。我有 karma-parallel 来运行 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
});
};
Run Code Online (Sandbox Code Playgroud)
用于运行测试用例的命令如下,
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng test --watch=false --code-coverage --source-map=false
Run Code Online (Sandbox Code Playgroud)
请指教。
小智 5
当您运行时ng test,它将运行所有项目的测试。
例如,如果您的 中有这两个项目angular.json:
hello-world (有 10 个测试)utilities (100 次测试)那么当你运行ng test它会运行两个测试hello-world和utilities。
但是,如果您使用带有监视文件或启用自动监视功能的 Karma,它将在第一个项目处停止,因此您只会看到运行 10 个测试(或 100 个测试,具体取决于项目的顺序)。然后当你 Ctrl+C 并退出 Karma 进程时,它将继续下一个项目,编译它并运行测试。因此,您将进行两次测试运行。
ng test <app>您正在部署的项目名称。ng test <app> && ng test <library>ng test忘记更改 Karma 以运行单个测试运行,而不是自动监视更改的文件!karma.conf.js每个项目以确保它具有正确的设置(无需观看、单次运行、使用正确的浏览器)| 归档时间: |
|
| 查看次数: |
2260 次 |
| 最近记录: |