为什么我的 karma-config.js 会触发多次 karma 启动,只有第一个有效?

罗德里戈·西尔维拉

处理 Angular 7 应用程序的 CircleCI CI/CD 管道在测试步骤中失败,CircleCI 日志表明浏览器未注册,尽管它运行了一次并且可以工作!

我正在为 Angular 7 应用程序构建 CircleCI CI/CD 管道,其中包括一个以奇怪方式失败测试步骤。我尝试更改 karma.config.js 参数以使用 Puppeteer,但无济于事。

这是WUF开源项目的一部分,我在WUF-41-CI分支上工作。以下是详细信息:

CircleCI config.yml文件:

version: 2.0

# Acceptance Criteria
#
# Given a feature branch of WUF
# When it changes on GitHub
# Then its code is built and tested but not published
#
# Given origin/master of WUF
# When it changes on GitHub
# Then its code is built, tested, tagged and the packages pushed to NPM, and the project’s Git pages

jobs:
  build:
    docker:
      - image: wasvic/node_dev:1.0.0-FM-188-SNAPSHOT
        entrypoint: /bin/sh
    working_directory: ~/wuf
    environment:
      - DEPLOY_BRANCH: WUF-41-CI
      - TARGET_BRANCH: gh-pages
      - GH_EMAIL: [email protected]
      - GH_NAME: anvil-open-source-machine-user
      - CHROME_BIN: /usr/lib/chromium/chrome
    # branches:
    #   only:
    #     - master
    #     - WUF-41-CI
    steps:
      - run:
          name: Install OS tools
          # TODO: replace with install_os_pkgs.sh script
          command: |
            apk update && apk add git
            apk add openssh
            apk add tar
            apk add ca-certificates
            apk update && apk upgrade && \
            echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
            echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories
            apk add --no-cache \
               chromium@edge \
               nss@edge \
               freetype@edge \
               harfbuzz@edge \
               ttf-freefont@edge
            apk add --no-cache ttf-freefont

      #  chekout projectt
      - checkout
      - restore_cache:
          keys:
            # when lock file changes, use increasingly general patterns to restore cache
            - yarn-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
            - yarn-v1-{{ .Branch }}-
            - node-v1-
      - run:
          name: Install WUF
          command: |
            yarn bootstrap
      - save_cache:
          paths:
            - ./node_modules  # location depends on npm version
          key: yarn-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - run:
          name: Build WUF
          command: |
            ng build --aot --base-href /wuf/ --deploy-url /wuf/
      - run:
          name: Test WUF
          command: |
            # ng test --browsers CircleCI_ChromeHeadless --watch=false
            ng test --browsers CircleCI_ChromeHeadless
            # ng test
      - run:
          name: Deploy WUF
          # TODO: replace with a deploy.sh script
          command: |
            if [ $CIRCLE_BRANCH == $DEPLOY_BRANCH ]; then
              git config --global user.email $GH_EMAIL
              git config --global user.name $GH_NAME

              git clone $CIRCLE_REPOSITORY_URL out

              cd out
              git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
              git rm -rf .
              cd ..

              cp -a dist/. out/.

              mkdir -p out/.circleci && cp -a .circleci/. out/.circleci/.
              cd out

              git add -A
              git commit -m "Automated deployment to GitHub Pages: ${CIRCLE_SHA1}" --allow-empty

              git push origin $TARGET_BRANCH
            fi

karma.config.js文件:

/*
 * Copyright (c) 2018 Dematic, Corp.
 * Licensed under the MIT Open Source: https://opensource.org/licenses/MIT
 */

// 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'],
            fixWebpackSourcePaths: true
        },
        reporters: ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        browsers: ['Chrome', 'CircleCI_ChromeHeadless'],
        customLaunchers: {
          CircleCI_ChromeHeadless: {
            base: 'ChromeHeadless',
            flags: [
              '--headless',
              '--disable-gpu',
              '--disable-translate',
              '--disable-extensions',
              '--no-sandbox',  // Added to fix an issue where of Failed to connect to chrome browser
             '--remote-debugging-port=9222',
            ],
          }
        },
        singleRun: true
    });
};

圈-CI日志表明第一Chrome的推出工作:

...
1 05 2019 00:10:47.700:INFO [launcher]: Launching browsers CircleCI_ChromeHeadless with concurrency unlimited
 11% building 9/12 modules 3 active .../root/wuf/src/app/app.component.spec.ts 11% building 10/12 modules 2 active ...assets/dummydata/branding/branding.scss11 05 2019 00:10:47.732:INFO [launcher]: Starting browser ChromeHeadless
...

圈-CI日志表明在第一次执行的测试通过了:

...
HeadlessChrome 73.0.3683 (Linux 0.0.0): Executed 69 of 69 SUCCESS (0 secs / 12.127 secs)
HeadlessChrome 73.0.3683 (Linux 0.0.0): Executed 69 of 69 SUCCESS (12.186 secs / 12.127 secs)
TOTAL: 69 SUCCESS
TOTAL: 69 SUCCESS
...

圈-CI日志表明第二Chrome的启动失败

...
11 05 2019 00:11:29.320:INFO [launcher]: Launching browsers CircleCI_ChromeHeadless with concurrency unlimited
11 05 2019 00:11:29.320:ERROR [launcher]: Cannot load browser "CircleCI_ChromeHeadless": it is not registered! Perhaps you are missing some plugin?
11 05 2019 00:11:29.320:ERROR [karma-server]: Error: Found 1 load error
马塞尔·瓦格纳

这是否与Chrome 73 在后台计划任务中停止支持无头模式相同

如果是,它应该可以降级到 Chrome 72。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么 Karma 会跳过我的有效单元测试?

当我从 Visual Studio 运行 Jasmine 测试时,为什么 karma 找不到我的 karma.conf.js 文件?

Karma Jasmin- 为什么即使没有测试用例,我的测试用例也会随机失败?

只有第一个测试用例成功-Jasmine / Karma in Angular

为什么我会从Karma Web服务器收到404消息?

karma和phantomJS有什么区别

我如何在gulp配置中正确访问karma.config对象以查看文件,然后运行karma,如果karma通过,则最终进行构建?

Karma 启动和拆卸配置

只有我的第一个CSS媒体大小查询有效

为什么我的应用程序启动后,WorkManager会多次触发?

karma.conf.js自动文件排序?

Vue.js + Karma + Jasmine 错误

Karma.conf.js不存在

为什么只有第一个导入的模块有效而其余的不能运行

业力给了我一个__karma __。start适配器错误,没有任何其他错误

有没有办法在 IntelliJ 的 karma.conf.js 中指定 Angular 配置?

如何通过“npm test”找到我的 karma.conf.js 文件?

Karma按什么顺序运行测试?

具有Node.js,Angular,Karma,Jasmine和Maven的Java动态Web项目

karma-webpack没有运行测试

在WebStorm中安装Karma.js-bash:karma:找不到命令

基本的“ karma init”设置后,karma.js不返回任何结果

Karma Require.js-更改目录结构正在杀死一切

配置karma.js以与React和ES6一起使用

导入Node核心模块会破坏Karma测试(使用@ open-wc / testing-karma)

我的间谍正在被调用,但我的功能没有被 karma 覆盖

我如何让Karma WebDriver启动器使用我的硒服务器/网格

Karma + Webpack + Angularjs - 所有测试都通过,但 karma 错误,带有退出代码 1

为什么我的第一个snippit有效,而我的第二个却无效?