Skip to content

Commit de9e55b

Browse files
committed
feat(frameworks): Support runner.afterEach in jasmine and mocha adapter
Closes angular#3894, angular#3908, and angular#3909
1 parent 23bc943 commit de9e55b

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This is spec file is automatically added by protractor to implement our
2+
// `afterEach` functionality for jasmine and mocha.
3+
4+
afterEach(function() {
5+
let hook = require('./setupAfterEach').hooks.afterEach;
6+
if (hook) {
7+
return hook();
8+
}
9+
});

lib/frameworks/jasmine.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ exports.run = function(runner, specs) {
7575
var reporter = new RunnerReporter(runner);
7676
jasmine.getEnv().addReporter(reporter);
7777

78+
// Add hooks for afterEach
79+
require('./setupAfterEach').setup(runner, specs);
80+
7881
// Filter specs to run based on jasmineNodeOpts.grep and jasmineNodeOpts.invert.
7982
jasmine.getEnv().specFilter = function(spec) {
8083
var grepMatch = !jasmineNodeOpts ||

lib/frameworks/mocha.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ exports.run = function(runner, specs) {
1212
var Mocha = require('mocha'),
1313
mocha = new Mocha(runner.getConfig().mochaOpts);
1414

15+
// Add hooks for afterEach
16+
require('./setupAfterEach').setup(runner, specs);
17+
1518
var deferred = q.defer();
1619

1720
// Mocha doesn't set up the ui until the pre-require event, so

lib/frameworks/setupAfterEach.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Setup afterEach hook for jasmine/mocha tests.
3+
*
4+
* One of the main purposes of this file is to give `__protractor_internal_afterEach_setup_spec.js`
5+
* a place to look up `runner.afterEach` at runtime without using globals.
6+
* This file needs to be separate from `__protractor_internal_afterEach_setup_spec.js` so that that
7+
* file is not prematurely executed.
8+
*/
9+
10+
var path = require('path');
11+
12+
// Queried by `protractor_internal_afterEach_setup_spec.js` for the `afterEach` hook
13+
var hooks = {
14+
afterEach: null
15+
};
16+
17+
exports.hooks = hooks;
18+
19+
/**
20+
* Setup `runner.afterEach` to be called after every spec.
21+
*
22+
* @param {Runner} runner The current Protractor Runner.
23+
* @param {Array} specs Array of Directory Path Strings. Must be a reference to the same array
24+
* instance used by the framework
25+
*/
26+
exports.setup = function(runner, specs) {
27+
hooks.afterEach = runner.afterEach;
28+
specs.push(path.resolve(__dirname, '__protractor_internal_afterEach_setup_spec.js'));
29+
};

0 commit comments

Comments
 (0)