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 in browser #8

Open
jasonkarns opened this issue Sep 10, 2015 · 7 comments
Open

mocha in browser #8

jasonkarns opened this issue Sep 10, 2015 · 7 comments

Comments

@jasonkarns
Copy link
Contributor

Does anyone have experience using custom interfaces in the browser? We're getting errors when mocha-gwt is loaded at

Mocha.interfaces['mocha-gwt'] = mochaGWT
because interfaces doesn't exist on that Mocha object.

And then when we attempt to configure mocha to use mocha-gwt, it throws an error about an unknown UI (since mocha-gwt failed to register itself as a UI).

@jasonkarns
Copy link
Contributor Author

I found the underlying issue with the interfaces registration and I'm working on a browserify branch to build a browser-friendly distribution. I have the interface registration working well using browserify-shim to expose window.Mocha via require('mocha'). Further, I've changed all the global.* references to use context. as provided by mocha in the suite setup callback.

At this point, mocha-gwt is being registered correctly and the page loads without errors. However, none of the tests are being recognized by mocha (they are not being saved into the mocha suites/tests arrays so mocha.run() doesn't execute anything). Any pointers?

@TheLudd
Copy link
Owner

TheLudd commented Sep 25, 2015

I actually have very little insight in how mocha works and I have never used it in the browser. This interface was written mostly by working my way through trial and error to its current state.

If you look at the code for mocha-gwt you'll see that it listens to hoooks. All tests are registerd pre-require and they are added to mocha post-require by doing Suite.add.

I don't know about the browser but "require" seems quite nodish. Perhaps those hooks are not fired in the browser environment?

@jasonkarns
Copy link
Contributor Author

pre-require is triggered but post-require isn't. (mocha-given and the
built-in UIs still use these hooks, even in browser)

I attempted simply emitting post-require at the end of pre-require, which
at least executes the handler, but still no worky. Unless there's any more
interest in getting mocha-gwt to work in browser, I'm probably just going
to bail back to mocha-given :/

On Fri, Sep 25, 2015 at 4:46 PM, Ludwig Magnusson [email protected]
wrote:

I actually have very little insight in how mocha works and I have never
used it in the browser. This interface was written mostly by working my way
through trial and error to its current state.

If you look at the code for mocha-gwt you'll see that it listens to
hoooks. All tests are registerd pre-require
https://github.com/TheLudd/mocha-gwt/blob/master/lib/mocha-gwt.coffee#L25
and they are added to mocha post-require
https://github.com/TheLudd/mocha-gwt/blob/master/lib/mocha-gwt.coffee#L71
by doing Suite.add
https://github.com/TheLudd/mocha-gwt/blob/master/lib/mocha-gwt.coffee#L107
.

I don't know about the browser but "require" seems quite nodish. Perhaps
those hooks
https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L216 are not
fired in the browser environment?


Reply to this email directly or view it on GitHub
#8 (comment).

@TheLudd
Copy link
Owner

TheLudd commented Sep 25, 2015

I did a very quick search through the mocha code and if this is where mocha emits events in the browser then it seems that mocha-gwt is incompatible with mocha in the browser. I don't know if the implementation is a mistake or if it needs to be that way. Only the pre-hook is emitted and the file is not included.

@jasonkarns
Copy link
Contributor Author

Right. And the loadFiles implementation (in node) simply emits the three
events one after the other. pre-require, then the file is required, then
require event, then post-require. So to simulate that, I temporarily
emitted post-require as the very last statement in the pre-require handler.
But there's still something else wrong.

I should also point out that I set the file argument to 0 as
mocha-given doesn't even use the file param, but instead hardcodes 0.

On Fri, Sep 25, 2015 at 4:54 PM, Ludwig Magnusson [email protected]
wrote:

I did a very quick search through the mocha code and if this
https://github.com/mochajs/mocha/blob/ee0a55b572d7da7dd8b7abc418d594602692bbed/support/browser-entry.js#L112
is where mocha emits events in the browser than it seems that mocha-gwt is
incompatible with mocha in the browser. I don't know if the implementation
is a mistake or if it needs to be that way. Only the pre-hook is emitted
and the file is not included.


Reply to this email directly or view it on GitHub
#8 (comment).

@TheLudd
Copy link
Owner

TheLudd commented Sep 25, 2015

Yes, but in mocha-gwt the file parameter is used.
Can you make sure that the code inside the if statement here is executed? https://github.com/TheLudd/mocha-gwt/blob/master/lib/mocha-gwt.coffee#L109

@jasonkarns
Copy link
Contributor Author

I have a proof of concept working and have opened #9 as the results of my work. (partially dependent on mochajs/mocha#1905)

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