-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from unexpectedjs/wip/replaceTestFrameworkPat…
…chWithAfterHook Wip: Replace test framework patch with afterEach hook
- Loading branch information
Showing
7 changed files
with
134 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*global afterEach, jasmine*/ | ||
var pendingPromisesForTheCurrentTest = []; | ||
var afterEachRegistered = false; | ||
|
||
var currentSpec = null; | ||
|
||
if (typeof jasmine === 'object') { | ||
// Add a custom reporter that allows us to capture the name of the currently executing spec: | ||
jasmine.getEnv().addReporter({ | ||
specStarted: function (spec) { | ||
currentSpec = spec; | ||
}, | ||
specDone: function (spec) { | ||
currentSpec = null; | ||
} | ||
}); | ||
} | ||
|
||
function registerAfterEachHook() { | ||
if (typeof afterEach === 'function' && !afterEachRegistered) { | ||
afterEachRegistered = true; | ||
try { | ||
afterEach(function () { | ||
var error; | ||
if (pendingPromisesForTheCurrentTest.some(function (promise) {return promise.isPending();})) { | ||
var displayName; | ||
if (this.currentTest) { | ||
// mocha | ||
displayName = this.currentTest.title; | ||
} else if (currentSpec) { | ||
displayName = currentSpec.fullName; | ||
} | ||
error = new Error(displayName + ': You have created a promise that was not returned from the it block'); | ||
} | ||
pendingPromisesForTheCurrentTest = []; | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
} catch (e) { | ||
// The benchmark suite fails when attempting to add an afterEach | ||
} | ||
} | ||
} | ||
|
||
// When running in jasmine/node.js, afterEach is available immediately, | ||
// but doesn't work within the it block. Register the hook immediately: | ||
registerAfterEachHook(); | ||
|
||
module.exports = function notifyPendingPromise(promise) { | ||
pendingPromisesForTheCurrentTest.push(promise); | ||
// Register the afterEach hook lazily (mocha/node.js): | ||
registerAfterEachHook(); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters