diff --git a/.travis.yml b/.travis.yml index ee29e4d..662bb31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,20 +3,33 @@ sudo: required language: node_js os: - linux + +addons: + sauce_connect: + username: "notkit" + jwt: + secure: "r7M8cgpDqP8NeJThQBCfqsCJDOVI/+HASWjirtHiKjnPGNu7hgPdAISn+gQP+w5RwC8HNysprNKNzSHm+wcUACZH+3zBxj9lVHB7V1dXcWV1W/kegvjaXnpo45V/1pJRft8EVKZSExncGegLz/RkM01d/b/EZvXSzViVoSgXWr4wXrRnH0yshqH1DswrDGfh31HpCP7XA75g9nPohZrJaX0ChsWQS5wUKKNRsbwdyNV5A2tl1BlJnYxMXMysbiiXBj++21lltSBJa5hT1GQKsJ9pGVyWdopWYXFFgRtxn4AJwM9N9e6Ns44m3sP6v3uYyYtlTgB+TBECHi4u5FrTaSiFgFpjk6Z+ljihrZ/iPWn1MQpfjuPlKdwOd6hfFLd79M/uw1Ih+0q0HGER01QwjvrA7nGCLu74SED60cu9UuJqSBQJceZ5nHmde3GMJHbw/u4RRiuWSU/7W/DoqGCLh/Q0FSYBeKTgN81NesUJp/Vk0xk5sPdRo3JuHDzqsFe6+6NMkqo46h3/G6ChfAhgyUAlPwPgVgWR8j6RHbZWgxsRll2KwmPXxzqoSct9OSsUQP4cIO1PrvmbZv933cPYppjjLKOV9RQsmUClZmzRqShcKB1Xt3ITdywTLaG/mKo5SrlQdol3y3Nkee+lzOpl8O91gNdHbgoYhpM+5OSoar8=" + env: global: - DBUS_SESSION_BUS_ADDRESS=/dev/null - DISPLAY=:99.0 - CHROME_BIN=chromium-browser + matrix: + - CI_MODE=local_e2e + - CI_MODE=saucelabs_e2e + cache: directories: - tour-of-heroes/node_modules -before_script: - - sh -e /etc/init.d/xvfb start + install: - cd tour-of-heroes - npm install + - cd .. + +before_script: + - ./scripts/travis_setup.sh + script: - - npm run lint - - npm run test -- --watch=false - - npm run travis \ No newline at end of file + - ./scripts/travis_test.sh diff --git a/scripts/travis_setup.sh b/scripts/travis_setup.sh new file mode 100755 index 0000000..cede07e --- /dev/null +++ b/scripts/travis_setup.sh @@ -0,0 +1,12 @@ +# Sets up the test environment on Travis. + +set -ex -o pipefail +cd `dirname $0` + +cd ../tour-of-heroes +webdriver-manager update + +# Start Xvfb when running locally. +if [[ ${TRAVIS} && (${CI_MODE} == "local_e2e") ]]; then + sh -e /etc/init.d/xvfb start +fi diff --git a/scripts/travis_test.sh b/scripts/travis_test.sh new file mode 100755 index 0000000..26ec43d --- /dev/null +++ b/scripts/travis_test.sh @@ -0,0 +1,20 @@ +# Runs the Travis CI + +set -ex -o pipefail +cd `dirname $0` +cd ../tour-of-heroes + +ng build + +if [[ ${TRAVIS} && (${CI_MODE} == "local_e2e") ]]; then + npm run lint + npm run test -- --watch=false + PROTRACTOR_CONFIG="./protractor.conf.js" +fi + +# When using saucelabs, use a different config. +if [[ ${TRAVIS} && (${CI_MODE} == "saucelabs_e2e") ]]; then + PROTRACTOR_CONFIG="./protractor-saucelabs.conf.js" +fi + +concurrently --success first --kill-others "lite-server" "protractor $PROTRACTOR_CONFIG" diff --git a/tour-of-heroes/package.json b/tour-of-heroes/package.json index 664cc6a..3a86a30 100644 --- a/tour-of-heroes/package.json +++ b/tour-of-heroes/package.json @@ -8,9 +8,7 @@ "lint": "tslint \"src/**/*.ts\"", "test": "ng test", "pree2e": "webdriver-manager update", - "e2e": "protractor", - "pretravis": "ng build", - "travis": "concurrently --success first --kill-others \"lite-server\" \"npm run e2e\"" + "e2e": "protractor" }, "private": true, "dependencies": { diff --git a/tour-of-heroes/protractor-saucelabs.conf.js b/tour-of-heroes/protractor-saucelabs.conf.js new file mode 100644 index 0000000..b2aa2f0 --- /dev/null +++ b/tour-of-heroes/protractor-saucelabs.conf.js @@ -0,0 +1,38 @@ +var testName = 'Tour of Heroes Smoke Tests' +var SpecReporter = require('jasmine-spec-reporter'); + +exports.config = { + sauceUser: process.env.SAUCE_USERNAME, + sauceKey: process.env.SAUCE_ACCESS_KEY, + + capabilities: { + 'browserName': 'internet explorer', + 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER, + 'build': process.env.TRAVIS_BUILD_NUMBER, + 'name': testName, + 'version': '11', + 'selenium-version': '2.53.1', + 'platform': 'Windows 7' + }, + + allScriptsTimeout: 30000, + specs: [ + './e2e/**/*.e2e-spec.ts' + ], + baseUrl: 'http://localhost:4200/', + framework: 'jasmine', + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000, + print: function() {} + }, + useAllAngular2AppRoots: true, + beforeLaunch: function() { + require('ts-node').register({ + project: 'e2e' + }); + }, + onPrepare: function() { + jasmine.getEnv().addReporter(new SpecReporter()); + } +};