From aad17091a5906c16b22190a8dc1a565d3d441503 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 --- .travis.yml | 2 +- addon/ng2/tasks/e2e.ts | 4 +++- tests/e2e/e2e_workflow.spec.js | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 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/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..50978b124bc7 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -114,6 +114,27 @@ 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) => { + console.log(stdout) + console.log(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); @@ -128,6 +149,8 @@ describe('Basic end-to-end Workflow', function () { if (/Build successful/.test(data) && !startedProtractor) { startedProtractor = true; child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => { + console.log(stdout) + console.log(stderr) if (error !== null) { reject(stderr) } else { @@ -430,6 +453,8 @@ describe('Basic end-to-end Workflow', function () { if (/Build successful/.test(data) && !startedProtractor) { startedProtractor = true; child_process.exec(`${ngBin} e2e`, (error, stdout, stderr) => { + console.log(stdout) + console.log(stderr) if (error !== null) { reject(stderr) } else {