Как автоматизировать модульные тесты jasmine с помощью GCP cloudbuild.yaml? - PullRequest
0 голосов
/ 09 мая 2020

Я пытаюсь автоматизировать модульные тесты jasmine с помощью GCP cloudbuild, но столкнулся с некоторыми проблемами, которые не могу решить. Пожалуйста, помогите мне в решении этих проблем. Ниже мой cloudbuild.yaml:

steps:
- name: 'node:10.10.0'
  args: ['npm', 'install']
  dir: './UI'
- name: 'node:10.10.0'
  args: ['npm', 'install', '-g', 'karma-phantomjs-launcher']
  dir: './UI'
- name: 'node:10.10.0'
  args: ['npm', 'test']
  dir: './UI'

Ниже мой пакет. json:

{
  "name": "ema-customer-portal",
  "version": "0.0.1",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.14",
    "@angular/cdk": "~8.2.3",
    "@angular/cli": "^8.3.22",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/flex-layout": "^8.0.0-beta.27",
    "@angular/forms": "~8.2.14",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@fullcalendar/angular": "^4.3.1",
    "@fullcalendar/bootstrap": "^4.3.0",
    "@fullcalendar/core": "^4.3.1",
    "@fullcalendar/daygrid": "^4.3.0",
    "@fullcalendar/interaction": "^4.3.0",
    "@fullcalendar/list": "^4.3.0",
    "@fullcalendar/resource-common": "^4.3.1",
    "@fullcalendar/resource-timeline": "^4.3.0",
    "@fullcalendar/timegrid": "^4.3.0",
    "@fullcalendar/timeline": "^4.3.0",
    "@ng-idle/core": "^8.0.0-beta.4",
    "@ng-idle/keepalive": "^8.0.0-beta.4",
    "@ngmodule/material-carousel": "^0.6.0",
    "angular2-moment": "^1.9.0",
    "file-saver": "^2.0.2",
    "hammerjs": "^2.0.8",
    "moment": "^2.24.0",
    "moment-range": "^4.0.2",
    "moment-timezone": "^0.5.28",
    "ng-pick-datetime": "^7.0.0",
    "ng2-search-filter": "^0.5.1",
    "ngx-chips": "^2.1.0",
    "ngx-material-timepicker": "^5.3.0",
    "ngx-powerbi": "^2.0.0",
    "ngx-treeview": "^6.0.2",
    "node-sass": "^4.13.0",
    "panzoom": "^9.2.4",
    "powerbi-client": "^2.8.0",
    "rxjs": "~6.4.0",
    "tippy.js": "^5.2.1",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.801.0",
    "@angular/compiler-cli": "~8.1.0",
    "@angular/language-service": "~8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "husky": "^4.2.3",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "ng2-search-filter": "0.5.1",
    "prettier": "^1.19.1",
    "pretty-quick": "^2.0.1",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "tslint-angular": "^3.0.2",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "^3.4.5",
    "underscore": "1.10.2",
    "xlsx": "^0.15.6"
  },
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged && ng lint"
    }
  }
}

Вот мой karma.config. js:

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/EMA-CustomerPortal'
            ),
            reports: ['html', 'lcovonly', 'text-summary'],
            fixWebpackSourcePaths: true
        },
        reporters: ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['PhantomJS', 'Chrome'],
        captureTimeout: 500000,
        browserDisconnectTolerance: 3, 
        browserDisconnectTimeout : 210000,
        browserNoActivityTimeout : 500000,
        singleRun: false,
        restartOnFileChange: true
    });
};

Я создал триггер. Когда я фиксирую свой код, сборка запускается и генерирует следующий вывод:

starting build "6ed365d8-1e78-4a9b-8cea-225e0c091109"
FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
 * branch            7a73eb40919764f843916dd0f066ab04649eb072 -> FETCH_HEAD
HEAD is now at 7a73eb4 cloudbuild.yaml edited online with Bitbucket
BUILD
Starting Step #0
Step #0: 1dca192b9b44: Pull complete
Step #0: 4b3efb8dd890: Pull complete
Step #0: Digest: sha256:499dc14186a1f363c366f39aba4cf4e0a153aabc9ee3b5b5802dc6b29e3cef36
Step #0: Status: Downloaded newer image for node:10.10.0
Step #0: docker.io/library/node:10.10.0
Step #0: 
Step #0: > husky@4.2.3 install /workspace/UI/node_modules/husky
Step #0: > node husky install
Step #0: 
Step #0: husky > Setting up git hooks
Step #0: Husky requires Git >=2.13.0. Got v2.1.4.
Step #0: husky > Failed to install
Step #0: 
Step #0: > node-sass@4.13.1 install /workspace/UI/node_modules/node-sass
Step #0: > node scripts/install.js
Step #0: 
Step #0: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.13.1/linux-x64-64_binding.node
Step #0: Download complete
Step #0: Binary saved to /workspace/UI/node_modules/node-sass/vendor/linux-x64-64/binding.node
Step #0: Caching binary to /builder/home/.npm/node-sass/4.13.1/linux-x64-64_binding.node
Step #0: 
Step #0: > core-js@2.6.11 postinstall /workspace/UI/node_modules/babel-runtime/node_modules/core-js
Step #0: > node -e "try{require('./postinstall')}catch(e){}"
Step #0: 
Step #0: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
Step #0: 
Step #0: [96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
Step #0: [96m>[94m https://opencollective.com/core-js [0m
Step #0: [96m>[94m https://www.patreon.com/zloirock [0m
Step #0: 
Step #0: [96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
Step #0: 
Step #0: 
Step #0: > core-js@3.1.4 postinstall /workspace/UI/node_modules/core-js
Step #0: > node scripts/postinstall || echo "ignore"
Step #0: 
Step #0: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
Step #0: 
Step #0: [96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
Step #0: [96m>[94m https://opencollective.com/core-js [0m
Step #0: [96m>[94m https://www.patreon.com/zloirock [0m
Step #0: 
Step #0: [96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
Step #0: 
Step #0: 
Step #0: > core-js@2.6.11 postinstall /workspace/UI/node_modules/karma/node_modules/core-js
Step #0: > node -e "try{require('./postinstall')}catch(e){}"
Step #0: 
Step #0: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
Step #0: 
Step #0: [96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
Step #0: [96m>[94m https://opencollective.com/core-js [0m
Step #0: [96m>[94m https://www.patreon.com/zloirock [0m
Step #0: 
Step #0: [96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
Step #0: 
Step #0: 
Step #0: > @angular/cli@8.3.22 postinstall /workspace/UI/node_modules/@angular/cli
Step #0: > node ./bin/postinstall/script.js
Step #0: 
Step #0: 
Step #0: > husky@4.2.3 postinstall /workspace/UI/node_modules/husky
Step #0: > opencollective-postinstall || exit 0
Step #0: 
Step #0: [96m[1mThank you for using husky![96m[1m
Step #0: [0m[96mIf you rely on this package, please consider supporting our open collective:[22m[39m
Step #0: > [94mhttps://opencollective.com/husky/donate[0m
Step #0: 
Step #0: 
Step #0: > node-sass@4.13.1 postinstall /workspace/UI/node_modules/node-sass
Step #0: > node scripts/build.js
Step #0: 
Step #0: Binary found at /workspace/UI/node_modules/node-sass/vendor/linux-x64-64/binding.node
Step #0: Testing binary
Step #0: Binary is fine
Step #0: npm WARN The package ng2-search-filter is included as both a dev and production dependency.
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/webpack-dev-server/node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/watchpack/node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/karma/node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/@angular/compiler-cli/node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: 
Step #0: added 1305 packages from 1136 contributors and audited 17914 packages in 43.597s
Step #0: found 86 vulnerabilities (80 low, 4 moderate, 2 high)
Step #0:   run `npm audit fix` to fix them, or `npm audit` for details
Finished Step #0
Starting Step #1
Step #1: Already have image: node:10.10.0
Step #1: npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated
Step #1: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
Step #1: 
Step #1: > phantomjs-prebuilt@2.1.16 install /usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt
Step #1: > node install.js
Step #1: 
Step #1: PhantomJS not found on PATH
Step #1: Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Step #1: Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Step #1: Receiving...
Step #1: 
Step #1: Received 22866K total.
Step #1: Extracting tar contents (via spawned process)
Step #1: Removing /usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt/lib/phantom
Step #1: Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1588937893274/phantomjs-2.1.1-linux-x86_64 -> /usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt/lib/phantom
Step #1: Phantom installation failed { [Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1588937893274/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt/lib/phantom']
Step #1:   errno: -13,
Step #1:   code: 'EACCES',
Step #1:   syscall: 'link',
Step #1:   path:
Step #1:    '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1588937893274/phantomjs-2.1.1-linux-x86_64',
Step #1:   dest:
Step #1:    '/usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1588937893274/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt/lib/phantom'
Step #1: npm WARN karma-phantomjs-launcher@1.0.4 requires a peer of karma@>=0.9 but none is installed. You must install peer dependencies yourself.
Step #1: 
Step #1: npm ERR! code ELIFECYCLE
Step #1: npm ERR! errno 1
Step #1: npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
Step #1: npm ERR! Exit status 1
Step #1: npm ERR! 
Step #1: npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
Step #1: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Step #1: 
Step #1: npm ERR! A complete log of this run can be found in:
Step #1: npm ERR!     /builder/home/.npm/_logs/2020-05-08T11_38_17_328Z-debug.log
Finished Step #1
ERROR
ERROR: build step 1 "node:10.10.0" failed: step exited with non-zero status: 1

Что мне здесь не хватает!

Изменить:

Ниже приведены мои журналы после удаление "-g":

Step #1: added 19 packages from 39 contributors and audited 18019 packages in 18.112s
Step #1: found 86 vulnerabilities (80 low, 4 moderate, 2 high)
Step #1:   run `npm audit fix` to fix them, or `npm audit` for details
Finished Step #1
Starting Step #2
Step #2: Already have image: node:10.10.0
Step #2: 
Step #2: > ema-customer-portal@0.0.1 test /workspace/UI
Step #2: > ng test
Step #2: 
Step #2: 09 05 2020 18:41:23.410:WARN [karma]: No captured browser, open http://localhost:9876/
Step #2: 09 05 2020 18:41:23.467:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
Step #2: 09 05 2020 18:41:23.468:INFO [launcher]: Launching browsers PhantomJS, Chrome with concurrency unlimited
Step #2: 09 05 2020 18:41:23.469:ERROR [launcher]: Cannot load browser "PhantomJS": it is not registered! Perhaps you are missing some plugin?
Step #2: 09 05 2020 18:41:23.471:ERROR [karma-server]: Error: Found 1 load error
Step #2:     at Server.webServer.listen (/workspace/UI/node_modules/karma/lib/server.js:182:27)
Step #2:     at Object.onceWrapper (events.js:273:13)
Step #2:     at Server.emit (events.js:187:15)
Step #2:     at emitListeningNT (net.js:1320:10)
Step #2:     at process._tickCallback (internal/process/next_tick.js:63:19)
Step #2: 09 05 2020 18:41:23.474:INFO [launcher]: Starting browser Chrome
Step #2: 09 05 2020 18:41:23.475:ERROR [launcher]: No binary for Chrome browser on your platform.
Step #2:   Please, set "CHROME_BIN" env variable.

Edit-14/05/2020: cloudbuild.yaml:

steps:
- name: 'node:10.10.0'
  args: ['npm', 'install']
  dir: './UI'
- name: 'geekykaran/headless-chrome-node-docker:latest'
  id: 'install_chromium'
  args: ['bash', './myscript.bash']
  dir: './UI'
- name: 'node:10.10.0'
  args: ['npm', 'test']
  dir: './UI'

myscript. bash:

#!/bin/bash

google-chrome \
  --headless \
  --hide-scrollbars \
  --disable-gpu \
  --remote-debugging-port=9222

Журналы:

Finished Step #0
Starting Step #1 - "install_chromium"
Step #1 - "install_chromium": Pulling image: geekykaran/headless-chrome-node-docker:latest
Step #1 - "install_chromium": latest: Pulling from geekykaran/headless-chrome-node-docker
Step #1 - "install_chromium": d861b37f0502: Pulling fs layer
Step #1 - "install_chromium": 3913fb5c5d05: Pulling fs layer
Step #1 - "install_chromium": 5ea164360049: Pulling fs layer
Step #1 - "install_chromium": 3cfd0a770824: Pulling fs layer
Step #1 - "install_chromium": 3cfd0a770824: Waiting
Step #1 - "install_chromium": 5ea164360049: Verifying Checksum
Step #1 - "install_chromium": 5ea164360049: Download complete
Step #1 - "install_chromium": d861b37f0502: Verifying Checksum
Step #1 - "install_chromium": d861b37f0502: Download complete
Step #1 - "install_chromium": 3cfd0a770824: Verifying Checksum
Step #1 - "install_chromium": 3cfd0a770824: Download complete
Step #1 - "install_chromium": 3913fb5c5d05: Verifying Checksum
Step #1 - "install_chromium": 3913fb5c5d05: Download complete
Step #1 - "install_chromium": d861b37f0502: Pull complete
Step #1 - "install_chromium": 3913fb5c5d05: Pull complete
Step #1 - "install_chromium": 5ea164360049: Pull complete
Step #1 - "install_chromium": 3cfd0a770824: Pull complete
Step #1 - "install_chromium": Digest: sha256:a4e5086062ee8c87a1cca0f43778fd47eb5b80ff6195de449cb5afc6dd15d740
Step #1 - "install_chromium": Status: Downloaded newer image for geekykaran/headless-chrome-node-docker:latest
Step #1 - "install_chromium": docker.io/geekykaran/headless-chrome-node-docker:latest
Step #1 - "install_chromium": [0512/072512.212510:ERROR:zygote_host_impl_linux.cc(88)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Finished Step #1 - "install_chromium"
ERROR
ERROR: build step 1 "geekykaran/headless-chrome-node-docker:latest" failed: step exited with non-zero status: 1

После добавления --no-sandbox в качестве параметра в myscript. bash, ниже журнал:

Step #1 - "install_chromium": Status: Downloaded newer image for geekykaran/headless-chrome-node-docker:latest
Step #1 - "install_chromium": docker.io/geekykaran/headless-chrome-node-docker:latest
Step #1 - "install_chromium": 
Step #1 - "install_chromium": DevTools listening on ws://127.0.0.1:9222/devtools/browser/33bcee16-a088-4f6d-a985-5f3946d385fa
TIMEOUT
ERROR: context deadline exceeded

1 Ответ

0 голосов
/ 09 мая 2020

В Cloud Build от одного шага к другому сохраняется только каталог /workspace. Остальная часть среды принадлежит контейнеру, который вы определяете в параметре name.

На шаге 2 (# 1 в журналах) вы выполняете следующее:

 args: ['npm', 'install', '-g', 'karma-phantomjs-launcher']

A глобальная установка -> это действие необходимо для установки файла здесь: /usr/local/lib/node_modules/, и вы не можете, это файловая система только для чтения. И даже если вы сможете (возможно, с sudo), установленные файлы зависимостей не будут сохранены для следующего шага.

Итак, удалите опцию -g

...