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

Commit dbf7ab5

Browse files
committed
fix(mocha): mocha globals should be re-wrapped for every new suite
Closes #523, closes #962
1 parent 82c1d47 commit dbf7ab5

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/frameworks/mocha.js

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ exports.run = function(runner, specs, done) {
1313
// Mocha doesn't set up the ui until the pre-require event, so
1414
// wait until then to load mocha-webdriver adapters as well.
1515
mocha.suite.on('pre-require', function() {
16+
// We need to re-wrap all of the global functions, which selenium-webdriver/
17+
// testing only does when it is required. So first we must remove it from
18+
// the cache.
19+
delete require.cache[require.resolve('selenium-webdriver/testing')];
1620
var mochaAdapters = require('selenium-webdriver/testing');
1721
global.after = mochaAdapters.after;
1822
global.afterEach = mochaAdapters.afterEach;

spec/mocha/lib_spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ describe('no protractor at all', function() {
1616
});
1717

1818
describe('protractor library', function() {
19+
it.skip('should be able to skip tests', function() {
20+
expect(true).to.equal(false);
21+
});
22+
1923
it('should expose the correct global variables', function() {
2024
expect(protractor).to.exist;
2125
expect(browser).to.exist;
@@ -25,6 +29,8 @@ describe('protractor library', function() {
2529
});
2630

2731
it('should wrap webdriver', function() {
32+
// Mocha will report the spec as slow if it goes over this time in ms.
33+
this.slow(6000);
2834
browser.get('index.html');
2935
expect(browser.getTitle()).to.eventually.equal('My AngularJS App');
3036
});

spec/mochaConf.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ exports.config = {
1414
capabilities: env.capabilities,
1515

1616
baseUrl: env.baseUrl,
17+
18+
mochaOpts: {
19+
reporter: 'spec'
20+
}
1721
};

0 commit comments

Comments
 (0)