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

ReferenceError: Can't find variable: Mocha when running test #7

Closed
doberkofler opened this issue Jul 21, 2015 · 8 comments
Closed

ReferenceError: Can't find variable: Mocha when running test #7

doberkofler opened this issue Jul 21, 2015 · 8 comments

Comments

@doberkofler
Copy link

After upgrading to the latest version if gulp-mocha-phantomjs (0.8.0) that is depending on mocha-phantomjs-core (1.0.0) and therefore also got upgraded I have a set of test that report the following error:

ReferenceError: Can't find variable: Mocha
   at browser-shim.js:27

All required files in runner.html seem to be available and the test do work as expected in an actual browser like FF or Chrome. Any help would be appreciated.

@nathanboktae
Copy link
Owner

Can you share your test.html, or at least how you're loading mocha?

@doberkofler
Copy link
Author

runner.html:

    <!doctype html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Mocha Test Runner</title>
            <link rel="stylesheet" href="HTTP://localhost:7777/q/p/lj_unittest/test/mocha.css">
            <link rel="stylesheet" href="HTTP://localhost:7777/q/p/lj_unittest/css/core.css">
        </head>
        <body>
            <div id="mocha"></div>

            <div id="fixture" style="display:none;">
                <div id="charset_ascii"> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</div>
                <div id="charset_other">ÄäÆæß</div>
            </div>

            <script src="HTTP://localhost:7777/q/p/lj_unittest/js/core.js"></script>
            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/mocha.js"></script>
            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/chai.js"></script>
            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/chai-datetime.js"></script>
            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/sinon.js"></script>

            <script>
                mocha.setup("bdd");
            </script>

            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/backend/ods/charset_backend.js"></script>
            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/backend/ods/ods.log_backend.js"></script>
            <script src="HTTP://localhost:7777/q/p/lj_unittest/test/backend/ods/date.js"></script>

            <script>
                mocha.run();
            </script>
        </body>
    </html>

Gulpfile.js:

gulp.task('test:backend:ODS', function (/*callback*/) {
    var stream = mochaPhantomJS({'reporter': 'spec'});
    stream.write({path: config.URL_ROOT + '/TEST_WEB_ODS.main'});
    stream.end();
    return stream;
});

@nathanboktae
Copy link
Owner

ah yeah can you call mocha.ui instead of mocha.setup for now? I didn't know about mocha.setup... i need to investigate the differences, but a bug for sure.

@doberkofler
Copy link
Author

Thank you for the feedback. I've now changed <script>mocha.setup("bdd");</script> to <script>mocha.ui("bdd");</script> but I still get the same error message:
ReferenceError: Can't find variable: Mocha at browser-shim.js:27

@nathanboktae
Copy link
Owner

Do you still have the issue if you load mocha.js as the very first script?

@doberkofler
Copy link
Author

I now rearranged the script to include mocha.js as the first script and this seems to have done the trick. It now also works with mocha.setup as expected. Would be please be so kind to elaborate a little on what went wrong before in the first place? Thanks a lot!

@nathanboktae
Copy link
Owner

Glad it's working.

Would be please be so kind to elaborate a little on what went wrong before in the first place?

I don't know what's going on in HTTP://localhost:7777/q/p/lj_unittest/js/core.js and it's interaction with mocha. It could possibly be setting up an AMD or CommonJS environment and causing mocha to think it's not running in the browser and not set window.Mocha would be my guess.

@doberkofler
Copy link
Author

Unlikely as it does work when running directly in the browser but I'm also glad it does work now. Thank you!

sanemat added a commit to sanemat/octokat.js that referenced this issue Aug 22, 2015
related:
ReferenceError: Can't find variable: Mocha when running test Issue philschatz#7
nathanboktae/mocha-phantomjs-core
nathanboktae/mocha-phantomjs-core#7
sanemat added a commit to sanemat/octokat.js that referenced this issue Aug 22, 2015
related:
ReferenceError: Can't find variable: Mocha when running test Issue philschatz#7
nathanboktae/mocha-phantomjs-core
nathanboktae/mocha-phantomjs-core#7
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

2 participants