From bdb29588814c405bbcb8ca2973014cd91890eae3 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 6 Dec 2016 07:54:00 +0100 Subject: [PATCH] chore: properly exit e2e tasks (#2064) * Instead of manually exiting the process we should just ensure that everything is properly cleaned up and then gulp can take care of the exit codes. * If we have the `e2e:done` task at the end of the sequence it will be never called when an error occurred before --- tools/gulp/tasks/ci.ts | 4 ++-- tools/gulp/tasks/e2e.ts | 46 +++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/tools/gulp/tasks/ci.ts b/tools/gulp/tasks/ci.ts index 9bd14e3a99b..b3c9c12a5a6 100644 --- a/tools/gulp/tasks/ci.ts +++ b/tools/gulp/tasks/ci.ts @@ -10,5 +10,5 @@ task('ci:forbidden-identifiers', function() { // Travis sometimes does not exit the process and times out. This is to prevent that. task('ci:test', ['test:single-run'], () => process.exit(0)); -// Travis sometimes does not exit the process and times out. This is to prevent that. -task('ci:e2e', ['e2e:single-run'], () => process.exit(0)); + +task('ci:e2e', ['e2e:single-run']); diff --git a/tools/gulp/tasks/e2e.ts b/tools/gulp/tasks/e2e.ts index 83070eab65f..085c5f639f6 100644 --- a/tools/gulp/tasks/e2e.ts +++ b/tools/gulp/tasks/e2e.ts @@ -7,11 +7,14 @@ import { vendorTask, sequenceTask, serverTask } from '../task_helpers'; +const gulpRunSequence = require('run-sequence'); const appDir = path.join(SOURCE_ROOT, 'e2e-app'); const outDir = DIST_ROOT; const PROTRACTOR_CONFIG_PATH = path.join(PROJECT_ROOT, 'test/protractor.conf.js'); +/** Method to stop a running e2e web server, which may have not exited properly */ +let stopE2eServer = () => {}; task(':watch:e2eapp', () => { watch(path.join(appDir, '**/*.ts'), [':build:e2eapp:ts']); @@ -39,17 +42,6 @@ task(':test:protractor:setup', execNodeTask('protractor', 'webdriver-manager', [ /** Runs protractor tests (assumes that server is already running. */ task(':test:protractor', execNodeTask('protractor', [PROTRACTOR_CONFIG_PATH])); -/** - * Forces process termination. - * - * This task is used because, in some cases, protractor will block and not exit the process, - * causing Travis to timeout. This task should always be used in a synchronous sequence as - * the last step. - */ -task(':e2e:done', () => process.exit(0)); - -let stopE2eServer: () => void = null; - /** Starts up the e2e app server. */ task(':serve:e2eapp', serverTask(false, stream => { stopE2eServer = () => stream.emit('kill'); })); @@ -70,23 +62,27 @@ task('serve:e2eapp:watch', ['serve:e2eapp', ':watch:components', ':watch:e2eapp' * * This task should only be used when running the e2e tests locally. */ -task('e2e', sequenceTask( - ':test:protractor:setup', - 'serve:e2eapp:watch', - ':test:protractor', - ':serve:e2eapp:stop', - ':e2e:done', -)); +task('e2e', (done: (err?: string) => void) => { + gulpRunSequence( + ':test:protractor:setup', + 'serve:e2eapp:watch', + ':test:protractor', + ':serve:e2eapp:stop', + (err: any) => stopE2eServer() && done(err) + ); +}); /** * Runs the e2e once. Does not watch for changes. * * This task should be used when running tests on the CI server. */ -task('e2e:single-run', sequenceTask( - ':test:protractor:setup', - 'serve:e2eapp', - ':test:protractor', - ':serve:e2eapp:stop', - ':e2e:done', -)); +task('e2e:single-run', (done: (err?: string) => void) => { + gulpRunSequence( + ':test:protractor:setup', + 'serve:e2eapp', + ':test:protractor', + ':serve:e2eapp:stop', + (err: any) => stopE2eServer() && done(err) + ); +});