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

Cannot run ui: 'exports' tests using API. #3004

Closed
4 tasks done
rpaterson opened this issue Sep 12, 2017 · 8 comments
Closed
4 tasks done

Cannot run ui: 'exports' tests using API. #3004

rpaterson opened this issue Sep 12, 2017 · 8 comments
Assignees
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@rpaterson
Copy link

Prerequisites

  • Checked that your issue isn't already filed by cross referencing issues with the common mistake label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
    node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

Cannot run ui: 'exports' tests using API. The call to mocha.run() throws an exception "TypeError: Cannot read property 'skip' of undefined".

Steps to Reproduce

Create a file MyTestFile.js with contents:

exports.MyTest = {
    myTestFunction() {
    }
};

Then run node -e "const Mocha = require('mocha'); const mocha = new Mocha({ ui: 'exports' }); mocha.addFile('./MyTestFile.js'); mocha.run();"

Expected behavior:
Test should pass.

Actual behavior:
Throws exception:

/home/rpaterson/programming/signpost/toshokan/node_modules/mocha/lib/mocha.js:207
    exports.xit = context.xit || context.test.skip;
                                             ^

TypeError: Cannot read property 'skip' of undefined
    at Suite.<anonymous> (/home/rpaterson/programming/signpost/toshokan/node_modules/mocha/lib/mocha.js:207:46)
    at emitThree (events.js:116:13)
    at Suite.emit (events.js:194:7)
    at /home/rpaterson/programming/signpost/toshokan/node_modules/mocha/lib/mocha.js:230:11
    at Array.forEach (native)
    at Mocha.loadFiles (/home/rpaterson/programming/signpost/toshokan/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/home/rpaterson/programming/signpost/toshokan/node_modules/mocha/lib/mocha.js:514:10)
    at [eval]:1:117
    at ContextifyScript.Script.runInThisContext (vm.js:25:33)
    at Object.exports.runInThisContext (vm.js:77:17)

Reproduces how often:
100% of the time.

Versions

Problem does not happen in v3.5.0, starts happening in v3.5.1. The line that is throwing the exception was added in that release by 1cc0fc0.

Additional Information

@ScottFreeCode
Copy link
Contributor

ScottFreeCode commented Sep 13, 2017

Hmm. Given that those assignments seem to depend on the BDD or TDD interface being chosen, I think we could put that whole callback in an if to filter out the Exports interface. ...And the QUnit interface if it isn't close enough to the TDD interface to make these assignments work, which I'd have to do a little more digging to confirm or deny. [EDITTED TO ADD:] The Qunit interface at least doesn't throw if I try the same experiment using it instead of the exports interface, so yeah, for now we just need to skip that callback if the chosen interface is Exports.

@arvind
Copy link

arvind commented Oct 11, 2018

@ScottFreeCode: I see you've self-assigned this issue, and I was wondering if you had an update? We're experiencing this issue as well (vega/vega-lite#4166) when using ui: "assert" for what I imagine is the same underlying issue (the assignments depend on BDD/TDD interfaces). Thanks!

@plroebuck
Copy link
Contributor

plroebuck commented Oct 12, 2018

@arvind, To my knowledge, no one is working on this issue!
Provide an MCVE and I'll take a look when I get a chance.

BTW, since I have never used either of these UIs, what is their equivalent of a skipped test?

@plroebuck
Copy link
Contributor

Unverified but...

exports ui:

  • minus sign prepended to title will skip test, same as calling it.skip
  • exclamation point prepended to title will make test exclusive, same as calling it.only

@juergba
Copy link
Contributor

juergba commented Nov 21, 2018

The ui: 'exports' interface is implemented in a basic manner. Only suites, tests and before-/beforeAll- and after-/afterAll-hooks are supported. Neither it.skip nor it.only are accepted.
To avoid TypeError: Cannot read property 'skip' of undefined one line of code has to be changed:

mocha.js line 256:

this.suite.on('pre-require', function(context) {
...
    exports.it = context.it || context.test;
    exports.xit = context.xit || context.test.skip;                     //old
    exports.xit = context.xit || context.test && context.test.skip;     //new
    exports.setup = context.setup || context.beforeEach;

exports.MyTest = {
    before() { console.log("before hook");},
    after() { console.log("after hook");},
    myTestFunction() { console.log("test function");
    }
};
   MyTest
before hook
test function
    √ myTestFunction
after hook

  1 passing (13ms)

@juergba
Copy link
Contributor

juergba commented Dec 11, 2018

@boneskull please close, since solved in b5c0fb0

@juergba
Copy link
Contributor

juergba commented Dec 17, 2018

@outsideris could you please close this issue? Thanks.

@outsideris
Copy link
Contributor

I confirmed it fixed as @juergba said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

7 participants