azure-devops - 在 Azure DevOps Pipeline 中运行 Angular 测试时出现问题
问题描述
我有一个 Angular 7.2 的项目,在该项目中我创建了 3 个 Angular 库并使用 jasmin-karma 配置我的单元测试。我一个一个地运行所有测试。在我的本地环境中,一切都执行得很好,但是当我尝试在 azure devops 管道中运行时,测试不起作用。它向我显示了这样的错误“ Chrome 75.0.3770 (Windows 10.0.0) ERROR Disconnectedreconnect failed before timeout of 2000ms (ping timeout) ”。有谁知道这是怎么回事?总之谢谢大家。
这是我每个库的业力配置文件
// 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-phantomjs-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-junit-reporter'),
],
files:["../../node_modules/jquery/dist/jquery.min.js",
"../../node_modules/jquery-migrate/dist/jquery-migrate.min.js",
"../../node_modules/lodash/lodash.min.js",
"../../node_modules/moment/min/moment.min.js",
"../../node_modules/app-resources/bits/Framework/scripts/app.js",],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in
browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage'),
reports: ['html', 'lcov', 'cobertura'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml', 'junit'/* 'sonarqube' */],
sonarqubeReporter: {
basePath: 'src/lib', // test files folder
filePattern: '**/*spec.ts', // test files glob pattern
encoding: 'utf-8', // test files encoding
outputFolder: 'reports', // report destination
legacyMode: false, // report for Sonarqube < 6.2 (disabled)
reportName: (metadata) => { // report name callback
/**
* Report metadata array:
* - metadata[0] = browser name
* - metadata[1] = browser version
* - metadata[2] = plataform name
* - metadata[3] = plataform version
*/
metadata[4] = 'lib';
return metadata.concat('xml').join('.');
}
},
junitReporter: {
outputDir: '../../reports', // results will be saved as
$outputDir/$browserName.xml
outputFile: undefined, // if included, results will be saved as
$outputDir/$browserName/$outputFile
suite: '', // suite will become the package name attribute in xml
testsuite element
useBrowserName: true, // add browser name to report and classes names
nameFormatter: undefined, // function (browser, result) to customize the
name attribute in xml testcase element
classNameFormatter: undefined, // function (browser, result) to customize
the classname attribute in xml testcase element
properties: {} // key value pair of properties to add to the <properties>
section of the report
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', ],
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 60000,
flags: [
'--disable-web-security',
'--disable-gpu',
'--no-sandbox'
],
singleRun: true,
});
};
解决方案
我建议您切换到 HeadlessChrome。2018 年 3 月 8 日,PhantomJS 的创建者宣布该项目将被归档。
我有同样的问题。PhantomJS 也需要大约 60 秒才能完成。HeadlessChrome 运行测试只需要大约 6 秒 =)
推荐阅读
- html - 如何使反应阻止浏览器缓存外部加载的html?
- javascript - 如何从wordpress url中提取令牌并给它一个变量/值?
- javascript - 如何撤消 addEventListener?
- android - Epoxy 要求每个模型属性实现 equals 和 hashCode 错误
- java - 为什么在 HashMap 节点中维护键的哈希?
- laravel - vue.js 未在浏览器中显示
- react-native - Text.js 的这种变化是否会影响任何事情,是否有必要?
- php - 特定位置的 nginx 重写规则
- css - laravel 中的 Boostrap 粘性页脚
- python - 使用 df.to_excel (openpyxl) 从数据框写入时如何在 Excel 中增加行