Skip to content

Mocha BDD wrapping incorrectly for it.only #2302

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

Closed
noisette44 opened this issue Jun 16, 2016 · 8 comments
Closed

Mocha BDD wrapping incorrectly for it.only #2302

noisette44 opened this issue Jun 16, 2016 · 8 comments
Labels
C-nodejs JavaScript Bindings

Comments

@noisette44
Copy link

Meta -

OS: Windows 7
Selenium Version: 2.53.2
Mocha version : 2.5.3

Expected Behavior -

"it.only" function inside javascript/node/selenium-webdriver/testing/index.js should correctly wrapped for asynchronous code.

exports.it = wrapped(global.it);
exports.iit = exports.it.only = wrapped(global.it.only);

Actual Behavior -

Since mocha V2.4.1 and this commit "it.only" function is not correctly wrapped because it call original "it" mocha function and no more "it" wrapped function. So, test is not run in asynchronous mode.

context.it.only = function(title, fn) {
   var test = it(title, fn); // => Since mocha 2.4.1 - use original mocha "it" function
   var reString = '^' + escapeRe(test.fullTitle()) + '$';
   mocha.grep(new RegExp(reString));
   return test;
}

mocha issue : https://github.com/mochajs/mocha/issues/2157

Now using own it.only function is necessary instead of wrapping.

@jleyba
Copy link
Contributor

jleyba commented Jun 17, 2016

Do yo have a reduced test case demonstrating the actual problem you are experiencing?

@jleyba
Copy link
Contributor

jleyba commented Jun 17, 2016

To clarify: I need a reproducible test case (selenium-webdriver only, no protractor stuff) to know what I'm looking for. Everything I've tried with it.only works as expected.

@benbracha
Copy link

I couldn't reproduce it as well with selenium-webdriver only, without protractor.
@ScottFreeCode, @noisette44 maybe we have a protractor issue here? Can you try to reproduce?

@jleyba
Copy link
Contributor

jleyba commented Jun 21, 2016

Ok, I'm closing this because the supposed issue cannot be reproduced.

For the record, selenium-webdriver does not monkey-patch mocha. It provides an API shim that wraps your functions before calling global.it, global.it.only, etc.

var test = require('selenium-webdriver/testing');
var assert = require('assert');

describe('wrapping', function() {
  it('does not monkey-patch', function() {
    assert.ok(test.it !== global.it);
    assert.ok(test.it.only !== global.it.only);
    console.log('test.it.only:______________');
    console.log(test.it.only + '');
    console.log();
    console.log('it.only:______________');
    console.log(it.only + '');
  });
});
$ mocha test.js

  wrapping
test.it.only:______________
function () {
    if (arguments.length === 1) {
      return globalFn(makeAsyncTestFn(arguments[0]));
    }
    else if (arguments.length === 2) {
      return globalFn(arguments[0], makeAsyncTestFn(arguments[1]));
    }
    else {
      throw Error('Invalid # arguments: ' + arguments.length);
    }
  }

it.only:______________
function (title, fn) {
      var test = it(title, fn);
      var reString = '^' + escapeRe(test.fullTitle()) + '$';
      mocha.grep(new RegExp(reString));
      return test;
    }
    ✓ does not monkey-patch


  1 passing (9ms)

@jleyba jleyba closed this as completed Jun 21, 2016
@jleyba
Copy link
Contributor

jleyba commented Jun 21, 2016

As always, we can revisit this issue if a reproducible test case is provided.

@ScottFreeCode
Copy link

Bother, you're right, this isn't patching -- I misread the exporting of wrapped versions of the functions as replacing the global ones (which in fact it's not doing) when I was trying to understand the reports we were getting pointing at the Selenium wrapper to explain the behavioral differences... But that can't be it since it's just exporting the wrapped functions, not replacing the originals with them.

My bad, sorry about that! I'm thinking, at this point, that unless somebody comes up with a Selenium-only (no Protractor) test demonstrating a problem with Selenium's wrapped it.only (I'll see if I can double-check this, but it isn't my main priority at this point as long as I can get the original issue fixed), Selenium's wrapping per se is probably a red herring...

In fact, while Protractor does appear to be using Selenium's wrapped versions (replacing most of Mocha's global functions with them -- this is what I went looking for on a hunch once I realized what Selenium itself doesn't do the global replacement), it looks like it goes out of its way to keep the original it.only, which would explain the issue. So, I will try loading up both of these and the example app from the Mocha issue, and see whether I can resolve it just by tinkering with how the Protractor code handles it.only (e.g. whether there's any problem with having it just keep Selenium's version). Then I'll report my findings and update all three issues as applicable.

Thanks for pointing me back in the right direction!

@noisette44
Copy link
Author

@jleyba Sorry for the delay - and thanks a lot for your feedback

I agree with @ScottFreeCode - it's a protractor issue since mocha "it.only" no more uses "global.it"

@ScottFreeCode
Copy link

Well, I eventually ended up having to try it in a VM in order to properly test it because my copy of Firefox wasn't cooperating with WebDriver, but I finally managed to confirm that Selenium's only wrapper is doing the right thing, and simply changing Protractor to use Selenium's wrapped only fixes the issue: angular/protractor#3045 (comment)

@lock lock bot locked and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-nodejs JavaScript Bindings
Projects
None yet
Development

No branches or pull requests

4 participants