业力配置可禁用无头Chrome,仅使用终端

时间:2019-04-20 15:08:24

标签: angular unit-testing karma-runner google-chrome-headless

我正在尝试运行Angular单元测试。我想将karma.config文件配置为不打开无头Chrome。我只是想仅在终端中查看输出。

我通过在 karma.config ....... p

reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false

reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false

运行测试不应打开无头镀铬

2 个答案:

答案 0 :(得分:1)

  

完整的karma.conf.js文件,仅能在终端中运行   使用ChromeHeadless

// 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')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadless'],
    singleRun: false,
    customLaunchers:{
      HeadlessChrome:{
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox'
        ]
      }
    }
  });
};

答案 1 :(得分:0)

您当前未使用无头铬。由于您的设置具有[Chrome]

,因此它已启动

您需要更改browser数组值。

  

browsers: ['Chrome']更改为browsers: ['ChromeHeadless']