Skip to content

Commit

Permalink
fix(test): guard from repeated executions of the karma run
Browse files Browse the repository at this point in the history
'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.
  • Loading branch information
devoto13 committed May 22, 2019
1 parent 4859ee9 commit fa0a44a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions test/e2e/step_definitions/core_steps.js
Expand Up @@ -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
Expand All @@ -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) => {
Expand Down Expand Up @@ -130,8 +135,8 @@ cucumber.defineSupportCode((a) => {
setTimeout(function () {
stopper.stop(_this.configFile, function (exitCode) {
_this.stopperExitCode = exitCode
callback()
})
callback()
}, 1000)
})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/stop.feature
Expand Up @@ -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'];
Expand Down

0 comments on commit fa0a44a

Please sign in to comment.