简体   繁体   English

Angular 2项目的Gitlab CI

[英]Gitlab CI for Angular 2 Project

Hi i am trying to setup a ci on gitlab to run a test for every commit and push but i can not setup configuration yml file can any please guide me what i am doing wrong my current yml file is 嗨,我想在gitlab上设置一个ci,为每次提交和推送运行测试,但我无法设置配置yml文件可以任何请指导我我做错了我当前的yml文件是

image: node:4.2.2
cache:
  paths:
  - node_modules/
test_app:
  script:
    - npm install  
    - npm test

This is giving me error during installation of Phantom.js module so i tried below configuration but is shows invalid syntax. 这在安装Phantom.js模块时给出了错误,所以我尝试了以下配置,但显示的语法无效。

image: node:4.2.2

befor_script:
  - mkdir ~/tmp
  - pushd ~/tmp
  - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
  - tar xf phantomjs-2.1.1-linux-x86_64.tar.bz2
  - mv phantomjs-2.1.1-linux-x86_64 phantomjs
  - ln -s ~/tmp/phantomjs/bin/phantomjs /usr/bin/phantomjs
  - phantomjs --version
  - cd ..

cache:
  paths:
  - node_modules/

test_app:
  script:
    - npm install  
    - npm test

My Package.Json files is 我的Package.Json文件是

{
  "name": "test",
  "version": "0.1.0",
  "description": "My Angular2-TypeScript App",
  "keywords": [
    "angular2",
    "typescript",
    "webpack"
  ],
  "scripts": {
    "lint": "tslint \"src/**/*.ts\"",
    "postinstall": "webdriver-manager update",
    "e2e": "protractor",
    "start": "gulp serve",
    "build": "gulp build",
    "test": "karma start"
  },
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "@types/core-js": "^0.9.34",
    "angular2-jwt": "^0.1.24",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "jquery": "^2.2.4",
    "ng2-bootstrap": "^1.1.16",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.5.35",
    "@types/node": "^6.0.45",
    "@types/protractor": "^1.5.20",
    "@types/selenium-webdriver": "2.44.28",
    "codelyzer": "0.0.19",
    "protractor": "^4.0.9",
    "protractor-jasmine2-screenshot-reporter": "^0.3.2",
    "gulp": "^3.9.1",
    "gulp-load-plugins": "^1.3.0",
    "gulp-shell": "^0.5.2",
    "run-sequence": "^1.2.2",
    "rimraf": "^2.5.2",
    "tslint": "^3.13.0",
    "typescript": "^2.0.3",
    "css-loader": "^0.23.1",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.5",
    "jasmine-core": "^2.4.1",
    "karma": "^0.13.22",
    "karma-coverage": "^1.0.0",
    "karma-jasmine": "^0.3.8",
    "karma-mocha-reporter": "^2.0.4",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.7.0",
    "html-loader": "^0.4.3",
    "html-webpack-plugin": "^2.15.0",
    "null-loader": "^0.1.1",
    "raw-loader": "^0.5.1",
    "style-loader": "^0.13.1",
    "ts-loader": "^0.8.1",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1",
    "webpack-merge": "^0.14.0"
  },
  "private": true
}

Error i am getting 我得到的错误

npm info build /builds/test/test/node_modules/rxjs/node_modules/symbol-observable
npm info linkStuff symbol-observable@1.0.4
npm info install symbol-observable@1.0.4
npm info postinstall symbol-observable@1.0.4
npm info build /builds/test/test/node_modules/rxjs
npm info linkStuff rxjs@5.0.0-beta.12
npm info install rxjs@5.0.0-beta.12
npm info postinstall rxjs@5.0.0-beta.12
npm info phantomjs-prebuilt@2.1.13 Failed to exec install script
npm ERR! Linux 4.7.0-coreos-r1
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.2.2
npm ERR! npm  v2.14.7
npm ERR! code ELIFECYCLE

npm ERR! phantomjs-prebuilt@2.1.13 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the phantomjs-prebuilt@2.1.13 install script 'node install.js'.
npm ERR! This is most likely a problem with the phantomjs-prebuilt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls phantomjs-prebuilt
npm ERR! There is likely additional logging output above.
npm info preuninstall phantomjs-prebuilt@2.1.13
npm info uninstall phantomjs-prebuilt@2.1.13
npm info postuninstall phantomjs-prebuilt@2.1.13
npm info preuninstall karma-phantomjs-launcher@1.0.2
npm info uninstall karma-phantomjs-launcher@1.0.2
npm info postuninstall karma-phantomjs-launcher@1.0.2

npm ERR! Please include the following file with any support request:
npm ERR!     /builds/test/test/npm-debug.log
ERROR: Build failed: exit code 1

I had same problem, getting the latest nodejs v6 packages solved the problem for me. 我有同样的问题,获取最新的nodejs v6包解决了我的问题。

Official Ubuntu packages for nodejs is far behind, to install the latest nodejs v6 packages for Ubuntu use below commands: nodejs的官方Ubuntu软件包远远落后,为命令安装最新的nodejs v6软件包用于Ubuntu:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Update to the first answer : 更新到第一个答案:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

The challenge for me was to run e2e tests requiring a real browser running. 我面临的挑战是运行需要真正浏览器运行的e2e测试。

Chrome fortunately has --headless mode now (and there's even a Debian package) so you don't need PhantomJS any more (reason why its current maintainer has announced plans to discontinue PhantomJS). Chrome幸运的是现在有了无--headless模式(甚至还有一个Debian软件包)所以你不再需要PhantomJS了(为什么它目前的维护者已经宣布计划停止使用PhantomJS)。

The key is to set up Xvfb before launching Chrome on GitLab CI. 关键是在GitLab CI上启动Chrome之前设置Xvfb For the exact setup code, check How to run AngularJS end-to-end tests on GitLab CI . 有关确切的设置代码,请查看如何在GitLab CI上运行AngularJS端到端测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM