【发布时间】:2020-08-22 16:35:39
【问题描述】:
在本地,我的测试用例在 Chrome 上运行良好,没有问题。我想在我的构建服务器 (Microsoft Azure) 上运行我的测试用例。
在我的服务器构建中,测试用例运行了两次。我只想运行一次。
我将配置作为 HeadlessChrome 传递。这些是我的配置。
在 package.json 文件中,
"test": "ng test --code-coverage --watch=false --browsers ChromeHeadless",
我的 karma.conf.js 文件,
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
// customLaunchers: {
// 'ChromeHeadless_Sandbox': {
// base: 'ChromeHeadless',
// flags: [
// '--no-sandbox',
// ],
// debug: true
// },
// },
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
browsers: ['ChromeHeadless'],
autoWatch: false,
concurrency: Infinity,
singleRun: true, // Karma captures browsers, runs the tests and exits
});
};
错误:
共有 131 个测试用例。 8个被跳过并且剩余的通行证正确。它运行第二次,它不工作。服务器将所有测试用例显示为失败。
我一直在 StackOverflow 和 Github 上探索所有类似问题的答案,但测试用例仍然运行了两次。两次它都在为 HeadlessChrome 运行,这很好,但它应该运行一次并退出。
PS - 还有一些我正在测试和尝试不同方式的注释代码。
请帮忙。我哪里做错了?如何让测试用例只运行一次?
【问题讨论】:
-
您找到解决方案了吗?
标签: angular unit-testing karma-jasmine google-chrome-headless