Angular 2 个项目的 Gitlab CI

Gitlab CI for Angular 2 Project

嗨,我正在尝试在 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

我有同样的问题,获取最新的 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

更新第一个答案:

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

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

Chrome 幸运的是现在有 --headless 模式(甚至还有一个 Debian 包)所以你不再需要 PhantomJS(这就是它的当前维护者宣布计划停止 PhantomJS 的原因)。

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