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

Commit

Permalink
fix(mocha): mocha globals should be re-wrapped for every new suite
Browse files Browse the repository at this point in the history
Closes #523, closes #962
  • Loading branch information
juliemr committed Jun 25, 2014
1 parent 82c1d47 commit dbf7ab5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/frameworks/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ exports.run = function(runner, specs, done) {
// Mocha doesn't set up the ui until the pre-require event, so
// wait until then to load mocha-webdriver adapters as well.
mocha.suite.on('pre-require', function() {
// We need to re-wrap all of the global functions, which selenium-webdriver/
// testing only does when it is required. So first we must remove it from
// the cache.
delete require.cache[require.resolve('selenium-webdriver/testing')];
var mochaAdapters = require('selenium-webdriver/testing');
global.after = mochaAdapters.after;
global.afterEach = mochaAdapters.afterEach;
Expand Down
6 changes: 6 additions & 0 deletions spec/mocha/lib_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe('no protractor at all', function() {
});

describe('protractor library', function() {
it.skip('should be able to skip tests', function() {
expect(true).to.equal(false);
});

it('should expose the correct global variables', function() {
expect(protractor).to.exist;
expect(browser).to.exist;
Expand All @@ -25,6 +29,8 @@ describe('protractor library', function() {
});

it('should wrap webdriver', function() {
// Mocha will report the spec as slow if it goes over this time in ms.
this.slow(6000);
browser.get('index.html');
expect(browser.getTitle()).to.eventually.equal('My AngularJS App');
});
Expand Down
4 changes: 4 additions & 0 deletions spec/mochaConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ exports.config = {
capabilities: env.capabilities,

baseUrl: env.baseUrl,

mochaOpts: {
reporter: 'spec'
}
};

0 comments on commit dbf7ab5

Please sign in to comment.