karma配置禁用无头铬并仅使用终端

问题描述 投票:0回答:2

我正在尝试运行Angular单元测试。我想配置karma.config文件不打开无头chrome。我只想在终端看到输出。

我尝试在karma.config中注释下面的代码行....

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

跑步测试不应该打开无头铬

angular unit-testing karma-runner google-chrome-headless
2个回答
0
投票

您目前没有使用无头镀铬。它已经启动,因为你的设置有[Chrome]

您需要更改browser数组值。

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


2
投票

完整的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'
        ]
      }
    }
  });
};
© www.soinside.com 2019 - 2024. All rights reserved.