在Azure DevOps管道中运行Angular测试时出现问题

时间:2019-06-14 02:30:17

标签: azure-devops karma-jasmine karma-runner angular7

我有一个角度为7.2的项目,在该项目中,我创建了3个角度库,并用jasmin-karma配置了单元测试。我没有一个人进行所有测试。在我的本地环境中,一切运行正常,但是当我尝试在天蓝色的devops管道测试中运行时,则无法正常工作。它显示了这样的错误“ Chrome 75.0.3770(Windows 10.0.0)错误   在2000ms超时(ping超时)之前,Disconnectedreconnect失败“。有人知道这是怎么回事吗?。还是谢谢您。

这是每个库的我的业力配置文件

// 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,
  });
};

1 个答案:

答案 0 :(得分:0)

我建议您切换到HeadlessChrome 。 PhantomJS的创建者于2018年3月8日宣布该项目将被存档。

https://semaphoreci.com/blog/2018/03/27/phantomjs-is-dead-use-chrome-headless-in-continuous-integration.html

我有同样的问题。 PhantomJS也花费了大约60秒来完成。 HeadlessChrome只需约6秒钟即可运行测试=)