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

Mocha anonymizes Errors in beforeEach/afterEach #47

Closed
bvanderdrift opened this issue Nov 24, 2017 · 6 comments
Closed

Mocha anonymizes Errors in beforeEach/afterEach #47

bvanderdrift opened this issue Nov 24, 2017 · 6 comments

Comments

@bvanderdrift
Copy link

I am currently setting up a testing environment for a project. Upon writing the very first test I received a very vague error:

Uncaught TypeError: Cannot read property 'replace' of undefined
    at Object.exports.clean (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:5991)
    at Runner.<anonymous> (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:2572)
    at Runner.EventEmitter.emit (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:254)
    at Runner.<anonymous> (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:2505)
    at Runner.EventEmitter.emit (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:254)
    at Runner.fail (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:4618)
    at Runner.failHook (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:4647)
    at practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:4692
    at done (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:4305)
    at Hook.Runnable.run (practicalmeteor_mocha-core.js?hash=daa1a30419e7324186e59f74d68a42f96a352274:4340)

I was for a long time unable to find out the problem, but after a while found out that this error gets thrown because I made a very simple and small mistake in the beforeEach function. In my code the mistake was handled by a custom error which is very specific and was made to help developing easier. Somehow Mocha translated it into the above error.

I tried testing a bit more why I got that error instead of my own error. The code of Mocha was complex, but it looks it has something to do with the error being caught, but the message not being passed well between functions so that once the clean function gets called the str parameter is undefined.

@bvanderdrift bvanderdrift changed the title Mocha crashes on Error handling in beforeEach/afterEach Mocha anonymizes Errors in beforeEach/afterEach Nov 24, 2017
@aldeed
Copy link
Contributor

aldeed commented Apr 2, 2018

Not sure if there is anything to be done here? If it's a mocha issue, then this should be filed in the mocha repo.

@mitar
Copy link
Member

mitar commented Sep 8, 2018

I just had the same problem.

@SimonSimCity
Copy link
Member

Is this just occasionally or reproducible? If it's reproducible, can someone facing this issue please create a plain meteor project and re-create the problem there and provide a link to the repository here? This would help me analyzing this problem ...

Make sure you already have the latest version of this package as well as meteortesting:browser-tests and meteortesting:mocha-core installed.

@coagmano
Copy link
Member

coagmano commented Oct 7, 2018

Happens every time, here's a quick repro:
https://github.com/coagmano/meteortesting-mocha-47

Pretty sure this is a mocha issue.
The issue is when the HTML reporter is trying to display test results on the page it also tries to include the body of the test. When a before hook fails, the body of the test doesn't end up on the test object. When mocha tries to sanitise the body, it fails because it's undefined.

// test.body is undefined here ------------------------------⌄⌄⌄⌄⌄⌄⌄⌄⌄
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.body));
      el.appendChild(pre);
      pre.style.display = 'none';

@coagmano
Copy link
Member

coagmano commented Oct 7, 2018

Digging a bit further, this was fixed loooong ago in mocha, and fixed in meteortesting:mocha-core >= 5.2.0_1

The repro is fixed after a simple meteor update meteortesting:mocha-core

So it seems the issue that people are running into is that Meteor installs 1.0.1 of mocha-core when you run meteor add meteortesting:mocha

Would there be unwanted side-effects if you bumped the required version of mocha-core to 5.2.0_2?

@SimonSimCity
Copy link
Member

SimonSimCity commented Oct 8, 2018

The only side-effect I saw is that you can't use phantomjs anymore. More on that here: Meteor-Community-Packages/meteor-mocha-core#1

But (as I also said in the referenced ticket) since the project phantomjs is officially stopped, I published a new version of mocha-core but kept the reference in this package so people still can fall back to the old version if they really need to.

My advice: Use puppeteer instead of phantomjs. And yes ... I need to do an update on the documentation of this package ...

I'll close this issue here as it's fixed long ago. If you sincerely need a specific version of mocha, please open an issue at https://github.com/meteortesting/meteor-mocha-core mentioning the version of mocha you need and I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants