From 17a8d4241b77c003a3341a546a3d1a14810843c7 Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Thu, 9 Apr 2020 16:01:02 -0700 Subject: [PATCH] fix(ci): stop the proxy before killing the child, handle errors This should fix #3464, hopefully. Since the test is flaky and only on Travis we can't be sure until we try for awhile. --- test/e2e/step_definitions/hooks.js | 13 +++++++------ test/e2e/support/proxy.js | 8 ++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/e2e/step_definitions/hooks.js b/test/e2e/step_definitions/hooks.js index 21a04481e..163c50025 100644 --- a/test/e2e/step_definitions/hooks.js +++ b/test/e2e/step_definitions/hooks.js @@ -4,12 +4,13 @@ cucumber.defineSupportCode((a) => { a.After(function (scenario, callback) { const running = this.child != null && typeof this.child.kill === 'function' - if (running) { - this.child.kill() - this.child = null - } - // stop the proxy if it was started - this.proxy.stop(callback) + this.proxy.stop(() => { + if (running) { + this.child.kill() + this.child = null + } + callback() + }) }) }) diff --git a/test/e2e/support/proxy.js b/test/e2e/support/proxy.js index 4a5757ca0..be18b770e 100644 --- a/test/e2e/support/proxy.js +++ b/test/e2e/support/proxy.js @@ -9,6 +9,10 @@ function Proxy () { target: 'http://localhost:9876' }) + self.proxy.on('error', function proxyError (err, req, res) { + console.log('support/proxy onerror', err) + }) + self.server = http.createServer(function (req, res) { const url = req.url const match = url.match(self.proxyPathRegExp) @@ -22,6 +26,10 @@ function Proxy () { } }) + self.server.on('clientError', (err, socket) => { + console.log('support/proxy clientError', err) + }) + self.start = function (port, proxyPath, callback) { self.proxyPathRegExp = new RegExp('^' + proxyPath + '(.*)') self.server.listen(port, function (error) {