From fa0a44aa1e48fb9431979de60364bbcc41ebe234 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Wed, 22 May 2019 22:30:56 +0200 Subject: [PATCH] fix(test): guard from repeated executions of the karma run 'data' event handler may be called multiple times, which will result in multiple calls to karma run. To take it even further its execution is delayed by setTimeout, which means that subsequent executions will run while next test scenario is in progress and may mess it up. To prevent this make sure that karma run is executed only once independently of how many time 'data' event is fired. --- test/e2e/step_definitions/core_steps.js | 35 ++++++++++++++----------- test/e2e/stop.feature | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/test/e2e/step_definitions/core_steps.js b/test/e2e/step_definitions/core_steps.js index 600fe6ee0..fac3852f7 100644 --- a/test/e2e/step_definitions/core_steps.js +++ b/test/e2e/step_definitions/core_steps.js @@ -65,6 +65,7 @@ cucumber.defineSupportCode((a) => { const runOut = command === 'runOut' if (command === 'run' || command === 'runOut') { + let isRun = false this.child = spawn('' + runtimePath, ['start', '--log-level', 'warn', configFile]) const done = () => { cleansingNeeded = true @@ -84,20 +85,24 @@ cucumber.defineSupportCode((a) => { this.child.stdout.on('data', (chunk) => { this.lastRun.stdout += chunk.toString() const cmd = runtimePath + ' run ' + configFile + ' ' + additionalArgs - setTimeout(() => { - exec(cmd, { - cwd: baseDir - }, (error, stdout, stderr) => { - if (error) { - this.lastRun.error = error - } - if (runOut) { - this.lastRun.stdout = stdout - this.lastRun.stderr = stderr - } - done() - }) - }, 1000) + if (!isRun) { + isRun = true + + setTimeout(() => { + exec(cmd, { + cwd: baseDir + }, (error, stdout, stderr) => { + if (error) { + this.lastRun.error = error + } + if (runOut) { + this.lastRun.stdout = stdout + this.lastRun.stderr = stderr + } + done() + }) + }, 1000) + } }) } else { executor((error, stdout, stderr) => { @@ -130,8 +135,8 @@ cucumber.defineSupportCode((a) => { setTimeout(function () { stopper.stop(_this.configFile, function (exitCode) { _this.stopperExitCode = exitCode + callback() }) - callback() }, 1000) }) diff --git a/test/e2e/stop.feature b/test/e2e/stop.feature index ce356c2cb..889569e12 100644 --- a/test/e2e/stop.feature +++ b/test/e2e/stop.feature @@ -44,7 +44,7 @@ Feature: Stop karma """ - Scenario: A server can be stopped programically + Scenario: A server can be stopped programmatically Given a configuration with: """ files = ['basic/plus.js', 'basic/test.js'];