From dbf7ab5fdf7832676f37328e2ad96b9097db3f62 Mon Sep 17 00:00:00 2001 From: Julie Ralph Date: Wed, 25 Jun 2014 13:35:39 -0700 Subject: [PATCH] fix(mocha): mocha globals should be re-wrapped for every new suite Closes #523, closes #962 --- lib/frameworks/mocha.js | 4 ++++ spec/mocha/lib_spec.js | 6 ++++++ spec/mochaConf.js | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/lib/frameworks/mocha.js b/lib/frameworks/mocha.js index e74554f30..108786324 100644 --- a/lib/frameworks/mocha.js +++ b/lib/frameworks/mocha.js @@ -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; diff --git a/spec/mocha/lib_spec.js b/spec/mocha/lib_spec.js index e8bbbd0b7..05246e945 100644 --- a/spec/mocha/lib_spec.js +++ b/spec/mocha/lib_spec.js @@ -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; @@ -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'); }); diff --git a/spec/mochaConf.js b/spec/mochaConf.js index e032c193f..bc7f8474c 100644 --- a/spec/mochaConf.js +++ b/spec/mochaConf.js @@ -14,4 +14,8 @@ exports.config = { capabilities: env.capabilities, baseUrl: env.baseUrl, + + mochaOpts: { + reporter: 'spec' + } };