【问题标题】:Angular + Karma + CI/CD gitlab : Chrome and test running correctly in local but not in CI/CD jobAngular + Karma + CI/CD gitlab:Chrome 和测试在本地正确运行但在 CI/CD 作业中不正确
【发布时间】:2023-01-19 12:15:33
【问题描述】:

实际上,我在 gitlab 上绑定到 kubernetes 的 CI/CD 管道的测试业力工作遇到了一个问题,我的 gitlab runner 是在其中设置的。

这是我的问题: 当我在我的本地机器上使用 ChromeHeadless 运行“ng test”时,所有测试都被正确触发并且我的控制台上有所有输出但是当我尝试使用 CI/CD 作业触发我的测试时没有任何反应,即使是 Chrome 进程在我的测试运行之前正在杀死。

我尝试了我在网上找到的所有东西,比如更改我的 karma.config.js 文件、更改 customLauncher、更改我在工作期间使用的图像等。在 Log_DEBUG 中设置我的 lgo 以获取输出和其他内容....

我真的不知道下一步该怎么做,我什至看到多次提到“puppeteer”,所以我试了一下,但没有更好的事情发生

有人可以帮我解决这个问题吗?我的解决方案用完了

我的 gitlab 作业的最后输出:

22 02 2022 15:00:53.344:DEBUG [plugin]: Loading inline plugin defining framework:jasmine, reporter:karma-jasmine.
22 02 2022 15:00:53.344:DEBUG [plugin]: Loading inline plugin defining launcher:Chrome, launcher:ChromeHeadless, launcher:ChromeCanary, launcher:ChromeCanaryHeadless, launcher:Chromium, launcher:ChromiumHeadless, launcher:Dartium, test.
22 02 2022 15:00:53.344:DEBUG [plugin]: Loading inline plugin defining reporter:kjhtml.
22 02 2022 15:00:53.344:DEBUG [plugin]: Loading inline plugin defining preprocessor:coverage, reporter:coverage.
22 02 2022 15:00:53.345:DEBUG [plugin]: Loading inline plugin defining framework:@angular-devkit/build-angular, reporter:@angular-devkit/build-angular--sourcemap-reporter, reporter:@angular-devkit/build-angular--event-reporter, middleware:@angular-devkit/build-angular--blocker, middleware:@angular-devkit/build-angular--fallback.
22 02 2022 15:00:53.345:DEBUG [plugin]: Loading inline plugin defining launcher:ChromeHeadless.
22 02 2022 15:00:55.990:DEBUG [web-server]: Instantiating middleware
22 02 2022 15:00:55.991:DEBUG [reporter]: Trying to load reporter: @angular-devkit/build-angular--event-reporter
22 02 2022 15:00:55.992:DEBUG [reporter]: Trying to load color-version of reporter: @angular-devkit/build-angular--event-reporter (@angular-devkit/build-angular--event-reporter_color)
22 02 2022 15:00:55.992:DEBUG [reporter]: Couldn't load color-version.
22 02 2022 15:00:55.992:DEBUG [reporter]: Trying to load reporter: @angular-devkit/build-angular--sourcemap-reporter
22 02 2022 15:00:55.992:DEBUG [reporter]: Trying to load color-version of reporter: @angular-devkit/build-angular--sourcemap-reporter (@angular-devkit/build-angular--sourcemap-reporter_color)
22 02 2022 15:00:55.993:DEBUG [reporter]: Couldn't load color-version.
22 02 2022 15:00:56.106:DEBUG [reporter]: Trying to load reporter: kjhtml
22 02 2022 15:00:56.107:DEBUG [reporter]: Trying to load color-version of reporter: kjhtml (kjhtml_color)
22 02 2022 15:00:56.107:DEBUG [reporter]: Couldn't load color-version.
22 02 2022 15:00:56.154:INFO [karma-server]: Karma v6.3.13 server started at http://localhost:9876/
22 02 2022 15:00:56.154:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
22 02 2022 15:00:56.158:INFO [launcher]: Starting browser Chrome
22 02 2022 15:00:56.159:DEBUG [launcher]: null -> BEING_CAPTURED
22 02 2022 15:00:56.159:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-47542512
22 02 2022 15:00:56.159:DEBUG [launcher]: google-chrome --user-data-dir=/tmp/karma-47542512 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --headless --no-sandbox http://localhost:9876/?id=47542512
/scripts-711-48798/step_script: line 135:    76 Killed                  node_modules/@angular/cli/bin/ng.js test --browsers=ChromeHeadless --watch=false
+ runner_script_trap
+ exit_code=1
+ out_json='{"command_exit_code": 1, "script": "/scripts-711-48798/step_script"}'
+ echo ''
+ echo '{"command_exit_code": 1, "script": "/scripts-711-48798/step_script"}'
Cleaning up project directory and file based variables
00:00
+ exit 0
+ set -eo pipefail
+ set +o noclobber
+ :
+ eval '$'\''rm'\'' "-f" "/builds/gitlab/Nantes/outils/gamingbyapside_front.tmp/CI_SERVER_TLS_CA_FILE"
'
++ rm -f /builds/gitlab/Nantes/outils/gamingbyapside_front.tmp/CI_SERVER_TLS_CA_FILE
+ exit 0
+ runner_script_trap
+ exit_code=0
+ out_json='{"command_exit_code": 0, "script": "/scripts-711-48798/cleanup_file_variables"}'
+ echo ''
+ echo '{"command_exit_code": 0, "script": "/scripts-711-48798/cleanup_file_variables"}'
+ exit 0
ERROR: Job failed: command terminated with exit code 1

业力.config.js :

// 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'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      jasmine: {
        // you can add configuration options for Jasmine here
        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
        // for example, you can disable the random execution with `random: false`
        // or set a specific seed with `seed: 4321`
      },
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    jasmineHtmlReporter: {
      suppressAll: true // removes the duplicated traces
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage/gba'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' }
      ]
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    captureTimeout: 180000,
    browsers: ['Chrome','ChromeHeadless'],
    customLaunchers: {
      ChromeHeadless: {
        base: 'Chrome',
        flags: [
          '--headless',
          '--no-sandbox'
        ]
      }
    },
    singleRun: false,
    restartOnFileChange: true
  });
};

gitlab-ci.yml :

stages:
    - install
    - test
    - build
    - deploy

install_dependencies:
    stage: install
    only:
        - master
        - tag
    script : 
        - echo "Install job only on master and tag"

lint:
    stage: test
    script:
        - echo "Linting job is here BOY"

test-karma:
    variables:
        CI_DEBUG_TRACE: "true"
    image : trion/ng-cli-karma
    stage: test
    script:
        - echo "Unit testing our angular app with karma baby"
        - npm ci
        - node_modules/@angular/cli/bin/ng.js test --browsers=ChromeHeadless --watch=false

build:
    stage: build
    only:
        - master
        - tag
    script:
        - "I'm gonna build your app just for you, it will be 5$ ...."

deploy:
    stage: deploy
    only:
        - master
        - tag
    script:
        - "I'm not like build job, i'll deploy your app for free, I know you are broke"

包.json :

{
  "name": "gba",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~13.2.0",
    "@angular/cdk": "^13.2.1",
    "@angular/common": "~13.2.0",
    "@angular/compiler": "~13.2.0",
    "@angular/core": "~13.2.0",
    "@angular/forms": "~13.2.0",
    "@angular/material": "^13.2.1",
    "@angular/platform-browser": "~13.2.0",
    "@angular/platform-browser-dynamic": "~13.2.0",
    "@angular/router": "~13.2.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.2.2",
    "@angular-eslint/builder": "13.1.0",
    "@angular-eslint/eslint-plugin": "13.1.0",
    "@angular-eslint/eslint-plugin-template": "13.1.0",
    "@angular-eslint/schematics": "13.1.0",
    "@angular-eslint/template-parser": "13.1.0",
    "@angular/cli": "~13.2.2",
    "@angular/compiler-cli": "~13.2.0",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "5.11.0",
    "@typescript-eslint/parser": "5.11.0",
    "eslint": "^8.2.0",
    "jasmine-core": "~4.0.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.5.2"
  }
}

【问题讨论】:

  • 我也在为一些我认为现在已经彻底“解决”的事情而苦苦挣扎。尝试了很多东西,疯狂地用谷歌搜索,但就是无法让它运行测试。我期待那里有一张图片可以正常工作,但找不到它。令人沮丧。
  • 您是否在没有自定义 Chrome 启动器配置的情况下尝试过图像?

标签: angular google-chrome gitlab karma-jasmine cicd


【解决方案1】:

我也有一段时间陷入类似的问题。正如@Thomas 在这个问题的 cmet 中所指出的,我尝试了一个自定义的 chrome 启动器。原来我们使用的是非常旧的 chrome 版本。这个版本甚至没有加载我们的代码。将 chrome 升级到最新版本似乎已经为我解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-15
    • 2020-01-10
    • 2019-11-19
    • 2022-06-17
    • 2023-02-10
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    相关资源
    最近更新 更多