This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frameworks): Support
runner.afterEach
in jasmine and mocha ada…
- Loading branch information
Showing
5 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
lib/frameworks/__protractor_internal_afterEach_setup_spec.js
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,10 @@ | ||
// This is spec file is automatically added by protractor to implement our | ||
// `afterEach` functionality for jasmine and mocha. | ||
|
||
var hooks = require('./setupAfterEach').hooks; | ||
|
||
afterEach(function() { | ||
if (hooks.afterEach) { | ||
return hooks.afterEach(); | ||
} | ||
}); | ||
This comment has been minimized.
Sorry, 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
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,29 @@ | ||
/** | ||
* Setup afterEach hook for jasmine/mocha tests. | ||
* | ||
* One of the main purposes of this file is to give `__protractor_internal_afterEach_setup_spec.js` | ||
* a place to look up `runner.afterEach` at runtime without using globals. | ||
* This file needs to be separate from `__protractor_internal_afterEach_setup_spec.js` so that that | ||
* file is not prematurely executed. | ||
*/ | ||
|
||
var path = require('path'); | ||
|
||
// Queried by `protractor_internal_afterEach_setup_spec.js` for the `afterEach` hook | ||
var hooks = { | ||
afterEach: null | ||
}; | ||
|
||
exports.hooks = hooks; | ||
|
||
/** | ||
* Setup `runner.afterEach` to be called after every spec. | ||
* | ||
* @param {Runner} runner The current Protractor Runner. | ||
* @param {Array} specs Array of Directory Path Strings. Must be a reference to the same array | ||
* instance used by the framework | ||
*/ | ||
exports.setup = function(runner, specs) { | ||
hooks.afterEach = runner.afterEach.bind(runner); | ||
specs.push(path.resolve(__dirname, '__protractor_internal_afterEach_setup_spec.js')); | ||
}; |
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
Is there any other way to implement this? I guess it would be nice if jasmine (or jasminewd2) would expose the original global afterEach function.
In my project, I hook into the global afterEach function to do some things so that I don't have to write them into every single test. I'm trying to remember off the top of my head, but it looks something like:
This way my spec will execute whatever is in the
afterEach
in its spec file, followed by whatever I want it to do inmyAfterEach
.When I upgraded to the newer version of protractor I noticed that it was executing
myAfterEach
TWO times at the end of a spec. When I removedafterEach
from my spec, it was STILL executingmyAfterEach
so I tracked it down to this file. This file makes a call to the global afterEach, and my spec makes a call, so that would account for both occurrences.I don't know how many other people are modifying the global.afterEach function, but I suspect they might see similar issues. I suppose you could do a similar thing by passing your function through the global.afterEach so as not to interfere with how many times it is executing. But then you are not always guaranteed to have an afterEach per file, if that is your intent.
For the moment, my simple fix is to overwrite this file with a blank file when I start my tests, but that's not a great solution.