【问题标题】:How to run Karma with Chrome on TravisCI (Ubuntu 16.04/Xenial)?如何在 TravisCI (Ubuntu 16.04/Xenial) 上使用 Chrome 运行 Karma?
【发布时间】:2019-09-11 18:37:04
【问题描述】:

我最近在 TravisCI 上的测试开始失败,因为 Google 显然放弃了对最新版本 Chrome 的 Ubuntu 14.04 (Trusty) 的支持。我已升级到 Ubuntu 16.04 (Xenial),但现在无法让 Karma 连接到 Chrome:

11 09 2019 18:15:05.421:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/
11 09 2019 18:15:05.425:INFO [launcher]: Launching browsers Chrome_travis_ci with concurrency unlimited
11 09 2019 18:15:05.429:INFO [launcher]: Starting browser Chrome
11 09 2019 18:16:05.435:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
11 09 2019 18:16:07.439:WARN [launcher]: Chrome was not killed in 2000 ms, sending SIGKILL.
11 09 2019 18:16:09.439:WARN [launcher]: Chrome was not killed by SIGKILL in 2000 ms, continuing.

我不清楚问题出在我的 Travis 配置、我的 Karma 配置还是其他问题上。

尝试过的解决方案:

travis.yml:

sudo: required
dist: xenial
services:
  - xvfb
addons:
  apt:
    sources:
      - google-chrome
    packages:
      - google-chrome-stable

language: node_js
node_js:
  - "10"
  - "8"
cache:
  directories: node_modules

before_install:
  - export CHROME_BIN=chromium-browser

before_script:
  - npm rebuild node-sass

script:
  - npm run lint
  - npm run test:ci # Runs: xvfb-run -a karma start
  - npm run build

karma.conf.js:

module.exports = (config) => {
  config.set({
    browsers: [process.env.TRAVIS ? 'Chrome_travis_ci' : 'Chrome'],
    client: {
      captureConsole: false,
    },
    customLaunchers: {
      Chrome_travis_ci: {
        base: 'Chrome',
        flags: ['--no-sandbox', '--disable-setuid-sandbox'],
      },
    },
    files: ['test/index.js'],
    frameworks: ['mocha', 'chai'],
    preprocessors: {
      'test/index.js': ['webpack', 'sourcemap'],
    },
    reporters: ['dots'],
    singleRun: true,
    webpack: Object.assign(webpackConfigBase, {
      devtool: 'inline-source-map',
      mode: 'development',
    }),
    webpackServer: {
      noInfo: true,
    },
  });
};

任何帮助或建议表示赞赏。谢谢!

【问题讨论】:

    标签: karma-runner travis-ci karma-chrome-launcher


    【解决方案1】:

    解决方案:从我的travis.yml 中完全删除before_install 配置。

    经过更多搜索,我终于被this comment 告知了一个可能的解决方案:

    起初我使用的是 Chromium,但由于量角器测试,我决定切换到 google-chrome 最新版本。我... [发现] 我的业力正在使用(我不知道如何)一个铬 bin 环境变量,即使我确实使用 dockerfile 正确设置了它!

    唯一的解决方法是在我的詹金斯工作中重新设置这个环境变量:

    # Set CHROME_BIN because it is incorrect even from Dockerfile
    export CHROME_BIN=/usr/bin/google-chrome
    

    更新我的 travis.yml 文件来自

    before_install:
      - export CHROME_BIN=chromium-browser
    

    before_install:
      - export CHROME_BIN=/usr/bin/google-chrome
    

    为我解决了这个问题。然后我更进一步,完全删除了该命令,一切仍然有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 2018-12-04
      • 1970-01-01
      • 2017-02-10
      • 2017-12-20
      相关资源
      最近更新 更多