Angular 2项目的Gitlab CI

时间:2016-10-29 07:29:11

标签: angular continuous-integration gitlab-ci

您好我正在尝试在gitlab上设置ci来为每次提交和推送运行测试但是我无法设置配置yml文件可以任何指导我做错了我当前的yml文件

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

这在安装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

我的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
}

我遇到错误

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

3 个答案:

答案 0 :(得分:2)

我有同样的问题,获取最新的nodejs v6包解决了我的问题。

nodejs的官方Ubuntu软件包远远落后,在命令下使用Ubuntu安装最新的nodejs v6软件包:

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

答案 1 :(得分:0)

更新第一个答案:

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

答案 2 :(得分:0)

我面临的挑战是运行需要真正浏览器运行的e2e测试。

Chrome幸运的是现在有--headless模式(甚至还有Debian软件包)所以你不再需要PhantomJS了(为什么它目前的维护者已经宣布计划停止使用PhantomJS)。

关键是在GitLab CI上启动Chrome之前设置Xvfb 。有关确切的设置代码,请选中How to run AngularJS end-to-end tests on GitLab CI