From d0c07acc6034b886a8b15a35e4e9f31a1d6f68f2 Mon Sep 17 00:00:00 2001 From: Marc Sensenich Date: Mon, 6 Jun 2016 15:38:06 -0400 Subject: [PATCH] fix(e2e): return exit codes on failure of e2e tests Fix #1017 Close #1025 Close #1044 --- .travis.yml | 2 +- .../blueprints/ng2/files/e2e/app.e2e-spec.ts | 2 +- addon/ng2/blueprints/ng2/files/e2e/app.po.ts | 2 +- addon/ng2/tasks/e2e.ts | 4 +++- tests/e2e/e2e_workflow.spec.js | 19 +++++++++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1483e447d760..8a9876e669c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source ~/.nvm/nvm-exec; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew tap caskroom/cask; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew cask install google-chrome; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew cask install google-chrome --force; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CHROME_BIN=chromium-browser; fi diff --git a/addon/ng2/blueprints/ng2/files/e2e/app.e2e-spec.ts b/addon/ng2/blueprints/ng2/files/e2e/app.e2e-spec.ts index 5b020693bc2a..2d9a848286c8 100644 --- a/addon/ng2/blueprints/ng2/files/e2e/app.e2e-spec.ts +++ b/addon/ng2/blueprints/ng2/files/e2e/app.e2e-spec.ts @@ -9,6 +9,6 @@ describe('<%= htmlComponentName %> App', function() { it('should display message saying app works', () => { page.navigateTo(); - expect(page.getParagraphText()).toEqual('<%= htmlComponentName %> works!'); + expect(page.getParagraphText()).toEqual('<%= prefix %> works!'); }); }); diff --git a/addon/ng2/blueprints/ng2/files/e2e/app.po.ts b/addon/ng2/blueprints/ng2/files/e2e/app.po.ts index c68572d8a7d9..b83fa858daf6 100644 --- a/addon/ng2/blueprints/ng2/files/e2e/app.po.ts +++ b/addon/ng2/blueprints/ng2/files/e2e/app.po.ts @@ -4,6 +4,6 @@ export class <%= jsComponentName %>Page { } getParagraphText() { - return element(by.css('<%= htmlComponentName %>-app h1')).getText(); + return element(by.css('<%= prefix %>-root h1')).getText(); } } diff --git a/addon/ng2/tasks/e2e.ts b/addon/ng2/tasks/e2e.ts index 3d377db6ba80..fea4af5738d3 100644 --- a/addon/ng2/tasks/e2e.ts +++ b/addon/ng2/tasks/e2e.ts @@ -6,6 +6,7 @@ import {exec} from 'child_process'; module.exports = Task.extend({ run: function () { var ui = this.ui; + var exitCode = 0; return new Promise((resolve) => { exec(`npm run e2e -- ${this.project.ngConfig.e2e.protractor.config}`, (err, stdout, stderr) => { @@ -13,10 +14,11 @@ module.exports = Task.extend({ if (err) { ui.writeLine(stderr); ui.writeLine(chalk.red('Some end-to-end tests failed, see above.')); + exitCode = err.code; } else { ui.writeLine(chalk.green('All end-to-end tests pass.')); } - resolve(); + resolve(exitCode); }); }); } diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 6a579fb1a7cb..3c90073b84fe 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -114,6 +114,25 @@ describe('Basic end-to-end Workflow', function () { }); }); + it('ng e2e fails with error exit code', function () { + this.timeout(240000); + + function executor(resolve, reject) { + child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => { + if (error !== null) { + resolve(stderr); + } else { + reject(stdout); + } + }); + } + + return new Promise(executor) + .catch((msg) => { + throw new Error(msg); + }); + }); + it('Serve and run e2e tests after initial build', function () { this.timeout(240000);