Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frameworks): Support runner.afterEach in jasmine and mocha ada… #3988

Merged
merged 1 commit into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/frameworks/__protractor_internal_afterEach_setup_spec.js
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();
}
});
3 changes: 3 additions & 0 deletions lib/frameworks/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ exports.run = function(runner, specs) {
var reporter = new RunnerReporter(runner);
jasmine.getEnv().addReporter(reporter);

// Add hooks for afterEach
require('./setupAfterEach').setup(runner, specs);

// Filter specs to run based on jasmineNodeOpts.grep and jasmineNodeOpts.invert.
jasmine.getEnv().specFilter = function(spec) {
var grepMatch = !jasmineNodeOpts ||
Expand Down
3 changes: 3 additions & 0 deletions lib/frameworks/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ exports.run = function(runner, specs) {
var Mocha = require('mocha'),
mocha = new Mocha(runner.getConfig().mochaOpts);

// Add hooks for afterEach
require('./setupAfterEach').setup(runner, specs);

var deferred = q.defer();

// Mocha doesn't set up the ui until the pre-require event, so
Expand Down
29 changes: 29 additions & 0 deletions lib/frameworks/setupAfterEach.js
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'));
};
2 changes: 1 addition & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ executor.addCommandlineTest('node built/cli.js spec/errorTest/timeoutConf.js')
message: 'Timeout - Async callback was not invoked within timeout ' +
'specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
})
.expectTestDuration(0, 100);
.expectTestDuration(0, 1000);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a lot of bench-marking, I have concluded that this change only matters for extremely short tests like this one, and shouldn't matter to normal users.


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