Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 6c3be8c

Browse files
committed
feat(frameworks): Support runner.afterEach in jasmine and mocha adapter (#3988)
Closes #3894, #3908, and #3909
1 parent 4a59412 commit 6c3be8c

File tree

5 files changed

+46
-1
lines changed

5 files changed

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

lib/frameworks/jasmine.js

+3
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

+3
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

+29
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.bind(runner);
28+
specs.push(path.resolve(__dirname, '__protractor_internal_afterEach_setup_spec.js'));
29+
};

scripts/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ executor.addCommandlineTest('node built/cli.js spec/errorTest/timeoutConf.js')
7676
message: 'Timeout - Async callback was not invoked within timeout ' +
7777
'specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
7878
})
79-
.expectTestDuration(0, 100);
79+
.expectTestDuration(0, 1000);
8080

8181
executor.addCommandlineTest('node built/cli.js spec/errorTest/afterLaunchChangesExitCodeConf.js')
8282
.expectExitCode(11)

0 commit comments

Comments
 (0)