From 5fcd383470700e7c15d6b8faa18aafdb8c0ac5a1 Mon Sep 17 00:00:00 2001 From: Ben Loveridge Date: Wed, 22 Nov 2017 17:07:07 -0700 Subject: [PATCH] Make sure `spec._suite` is always defined in the specDone handler if 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. --- src/junit_reporter.js | 15 +++++++++------ src/nunit_reporter.js | 15 +++++++++------ src/tap_reporter.js | 13 ++++++++----- src/terminal_reporter.js | 17 ++++++++++------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/junit_reporter.js b/src/junit_reporter.js index 651a47a..3f3001d 100644 --- a/src/junit_reporter.js +++ b/src/junit_reporter.js @@ -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) { @@ -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++; } diff --git a/src/nunit_reporter.js b/src/nunit_reporter.js index 92b9f88..ea00897 100644 --- a/src/nunit_reporter.js +++ b/src/nunit_reporter.js @@ -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) { @@ -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++; diff --git a/src/tap_reporter.js b/src/tap_reporter.js index 0dc68aa..99c41e7 100644 --- a/src/tap_reporter.js +++ b/src/tap_reporter.js @@ -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) { @@ -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)) { diff --git a/src/terminal_reporter.js b/src/terminal_reporter.js index aedd0cb..86b86c6 100644 --- a/src/terminal_reporter.js +++ b/src/terminal_reporter.js @@ -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) { @@ -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,