Skip to content

Commit

Permalink
Make sure spec._suite is always defined in the specDone handler if …
Browse files Browse the repository at this point in the history
…things execute oddly.

Fixes #158. I'm still not sure what might cause specDone to be called without specStarted
being called first for the same object, but apparently it can happen sometimes. Rather than
set that one property inside specDone, this performs all the same steps that would normally
happen during `specStarted` related to `currentSuite` so things should stay lined up well.
  • Loading branch information
putermancer committed Nov 23, 2017
1 parent 1091e8f commit 5fcd383
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
15 changes: 9 additions & 6 deletions src/junit_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,14 @@
__suites[suite.id] = extend(__suites[suite.id] || {}, suite);
return __suites[suite.id];
}
function getSpec(spec) {
function getSpec(spec, suite) {
__specs[spec.id] = extend(__specs[spec.id] || {}, spec);
return __specs[spec.id];
var ret = __specs[spec.id];
if (suite && !ret._suite) {
ret._suite = suite;
suite._specs.push(ret);
}
return ret;
}

self.jasmineStarted = function(summary) {
Expand Down Expand Up @@ -259,14 +264,12 @@
// focused spec (fit) -- suiteStarted was never called
self.suiteStarted(fakeFocusedSuite);
}
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
spec._startTime = new Date();
spec._suite = currentSuite;
spec._stdout = "";
currentSuite._specs.push(spec);
};
self.specDone = function(spec) {
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
spec._endTime = new Date();
storeOutput(spec);
if (isSkipped(spec)) { spec._suite._skipped++; }
Expand Down
15 changes: 9 additions & 6 deletions src/nunit_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@
__suites[suite.id] = extend(__suites[suite.id] || {}, suite);
return __suites[suite.id];
}
function getSpec(spec) {
function getSpec(spec, suite) {
__specs[spec.id] = extend(__specs[spec.id] || {}, spec);
return __specs[spec.id];
var ret = __specs[spec.id];
if (suite && !ret._suite) {
ret._suite = suite;
suite._specs.push(ret);
}
return ret;
}

self.jasmineStarted = function(summary) {
Expand Down Expand Up @@ -135,13 +140,11 @@
// focused spec (fit) -- suiteStarted was never called
self.suiteStarted(fakeFocusedSuite);
}
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
spec._startTime = new Date();
spec._suite = currentSuite;
currentSuite._specs.push(spec);
};
self.specDone = function(spec) {
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
spec._endTime = new Date();
if (isSkipped(spec)) {
spec._suite._skipped++;
Expand Down
13 changes: 8 additions & 5 deletions src/tap_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@
__suites[suite.id] = extend(__suites[suite.id] || {}, suite);
return __suites[suite.id];
}
function getSpec(spec) {
function getSpec(spec, suite) {
__specs[spec.id] = extend(__specs[spec.id] || {}, spec);
return __specs[spec.id];
var ret = __specs[spec.id];
if (suite && !ret._suite) {
ret._suite = suite;
}
return ret;
}

self.jasmineStarted = function(summary) {
Expand All @@ -81,12 +85,11 @@
// focused spec (fit) -- suiteStarted was never called
self.suiteStarted(fakeFocusedSuite);
}
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
totalSpecsExecuted++;
spec._suite = currentSuite;
};
self.specDone = function(spec) {
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
var resultStr = 'ok ' + totalSpecsExecuted + ' - ' + spec._suite.description + ' : ' + spec.description;
var failedStr = '';
if (isFailed(spec)) {
Expand Down
17 changes: 10 additions & 7 deletions src/terminal_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@
__suites[suite.id] = extend(__suites[suite.id] || {}, suite);
return __suites[suite.id];
}
function getSpec(spec) {
function getSpec(spec, suite) {
__specs[spec.id] = extend(__specs[spec.id] || {}, spec);
return __specs[spec.id];
var ret = __specs[spec.id];
if (suite && !ret._suite) {
ret._suite = suite;
ret._depth = suite._depth+1;
suite._specs++;
}
return ret;
}

self.jasmineStarted = function(summary) {
Expand Down Expand Up @@ -117,16 +123,13 @@
// focused spec (fit) -- suiteStarted was never called
self.suiteStarted(fakeFocusedSuite);
}
spec = getSpec(spec);
spec._suite = currentSuite;
spec._depth = currentSuite._depth+1;
currentSuite._specs++;
spec = getSpec(spec, currentSuite);
if (self.verbosity > 2) {
log(indentWithLevel(spec._depth, spec.description + ' ...'));
}
};
self.specDone = function(spec) {
spec = getSpec(spec);
spec = getSpec(spec, currentSuite);
var failed = false,
skipped = false,
disabled = false,
Expand Down

0 comments on commit 5fcd383

Please sign in to comment.