Angular +因果关系+ CI/CD gitlab:Chrome和测试在本地正确运行,但不在CI/CD作业中

osh3o9ms  于 2023-01-22  发布在  Go
关注(0)|答案(1)|浏览(115)

实际上,我在gitlab上绑定到kubernetes的CI/CD管道的测试karma作业遇到了一个问题,我的gitlab runner就是在kubernetes上安装的。
这是我的问题:当我在本地机器上使用ChromeHeadless运行“ng测试”时,所有测试都被正确触发,并且我的控制台上有所有输出,但当我尝试使用CI/CD作业触发测试时,什么也没有发生,甚至Chrome进程在我的测试运行之前就被杀死了。
我尝试了我在网上找到的所有东西,比如更改karma.config.js文件、更改customLauncher、更改我在作业过程中使用的图像等。在Log_DEBUG中设置我的lgo用于输出和其他事情......
我真的不知道接下来该怎么做,我甚至看到“ puppet 师”被提到了好几次,所以我尝试了一下,没有更好的效果
有人能帮我一下吗?我的溶液快用完了
我的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

卡尔马配置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.视频文件:

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"
  }
}
wfypjpf4

wfypjpf41#

我也曾经遇到过类似的问题。正如@托马斯在这个问题的评论中指出的,我尝试了一个自定义的chrome启动器。结果我们使用的是一个非常旧的chrome版本。这个版本甚至没有加载我们的代码。值得指出的是,这个问题是在我们将一个依赖项升级到typescript时开始的。将chrome升级到最新版本似乎为我解决了这个问题。

相关问题