Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

window.mocha not defined when running in nw.js #184

Open
kierans opened this issue May 6, 2017 · 2 comments
Open

window.mocha not defined when running in nw.js #184

kierans opened this issue May 6, 2017 · 2 comments

Comments

@kierans
Copy link

kierans commented May 6, 2017

Just like this question I'm trying to run Mocha tests via Karma in NW.js.

However my tests aren't running as window.mocha isn't defined.

Uncaught TypeError: Cannot read property 'setup' of undefined
at node_modules/karma-mocha/lib/adapter.js:250

Is it possible to do something like window.mocha = window.mocha || require("mocha") in the Adapter? Any other tips/suggestions.

@insightfuls
Copy link

It turns out this is an issue with Browserify, which is used to package Mocha for the browser. Mocha simply assigns global.mocha = ... and Browserify injects the first defined of global, self and window as global. In most browsers, global isn't defined, so window.mocha ends up being defined, which is what you want. But in NW.js both global and window are defined (because NW.js puts global on window.global) so Mocha ends up defined at global.mocha which is the wrong context. It also defines global.describe, global.it, etc. which in the browser should all be on window to work.

The issue is being tracked here:
browserify/insert-module-globals#48

@kierans
Copy link
Author

kierans commented May 18, 2017

I've created https://github.com/kierans/karma-nodewebkit-mocha as a wrapper for karma-mocha until the underlying bug is fixed.

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

No branches or pull requests

2 participants