-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
browserify breaks at require('./lib-cov/mocha') #880
Comments
sucks to be browserify I guess, I'm not breaking test coverage just for that. I thought browserify does all its hacky stuff to populate fake |
Please reconsider this issue. |
First off, the process has nothing to do with it. Browserify sees that the above has two Whether the merits of such an implementation of a pre-compiler is in question or not it would seem that assuming a node based project could be used in browser via such a tool is faulty. I would highly recommend that a fork of mocha offer a browser compatible solution. Yes mocha works in browser but it is not browserify friendly. The npm ecosystem however could support spin-off projects such as Or you could look into a more browserify friendly test framework like Jasmine. Hope that helps. |
I also forgot. If you use testem or mochify then you can use mocha with browserify. Just don't |
Sukima thank you for your recommendations. Testem is an awesome library and I plan on using that for x browser testing for my Window's deployments but locally and in Jenkins, I like to use grunt-mocha which uses this library. I've resulted into putting a script tag of mocha in my page but I feel that browserify is gaining traction as an awesome tool and Mocha should consider supporting it. |
if we remove the lib-cov will it work? or do we need other hacks as well? I'd be ok with removing that line for now |
Unfortunately I tried that. Once browserify makes it past that line it hits other The real answer to the problem is that the npm version of mocha is designed for node and browserfiy is hacking it back out into the browser. When what it should be doing is using the browser build for mocha. So my suggestion is to offer the browser version in a separate npm package. The advantage there is browser based projects can use npm to manage the mocha lib and browserify happily takes care of it. For clarity the sinon project suffers the same problem of straddling both worlds. When asking browserify to include sinon it includes the node version which lacks some features. You have to manually require the browser version buried in the
I also don't know what build of mocha testem is including with their project since the above is asking testem to inject their own copy of mocha into the served HTML file. Whether that's packaged in testem or pulled from mocha (via I hope that clears up the confusion. |
yeah, they're fundamentally quite different (none of the reporters are useful on the client etc) so separating may be a good idea some day regardless of browserify. Ideally this works with component as well but it was pre-component and back when browserify 1.x wasn't too great |
FTR, my use case is a lot of my code is shared between the client and server with browserify, I really enjoy using mocha, the way I've solved this isn't clean for my shared tests. I export a function that takes mocha as the param and contains logic for both client and server, on the server it takes a require('mocha') as the param, on the client, window.mocha, as it's loaded in with a script tag because of this issue. Does anyone have any other suggestions besides browserify where I can use mocha? Or should I switch to Jasmine? |
@michaelBenin I've handled this by having two different launchers. a Than in node you run the Again test runners like testem automate this process for you. Hence, why I offered a possible configuration example above. |
Configuring an alias like this, in Browserify, sort of works.
Except it still finds Jade deeper into the chain. And... it's a tremendously horrible hack. Suggestions? |
@bevacqua read my comment above. It explains that you include the browser version of mocha in your test runner (i.e. |
wtf haha why is it loading jade, leaky abstractions be leaking |
in package.json i believe this might work if you specify (mocha.js is commonjs)
From docs: browser field There is a special "browser" field you can set in your package.json on a per-module basis to override file resolution for browser-specific versions of files. For example, if you want to have a browser-specific module entry point for your "main" field you can just set the "browser" field to a string: "browser": "./browser.js" |
- Add: browser property to package.json specifying lib/mocha_browserify.js - Fix: require calls in the browser mocha.js
So I have it working bundling. Basically had to copy over mocha.js into lib, renamed require to rqr, and declared and exported mocha. Still going to just keep the script tag though. |
This will tell any browserify project to package the browser version of mocha and not the Node version. Fixes issue mochajs#880 This will only cover the JavaScript packaging, CSS is still done manually through <link> tags.
I'm still unable to browserify a file that require's mocha. Error:
Anyone else in the same boat? Tried it with node 0.10, 0.12, the latest browserify in npm (11.2.0), the latest mocha in npm (2.3.3). |
Same here with node 4 in package.json of mocha module |
@tj reopen? |
Yes it should be defenitively. Right now it is broken with browserify and the only solution i have for the moment is to keep mocha library (with all my js files that use it), out of browserify process |
I'm reopening this, but tentatively. Maybe mochify will help you guys. |
don't need whatever ancient coverage stuff is baked in. we should use something else. |
Webpack has the same issue, by the way. Why is mocha conditionally requiring a file that does not exist? Is this file generated under some conditions? What triggers this file to be generated? |
Yes, why? |
Should be |
Same issue here with webpack. |
@SonofNun15 It's all in the makefile. when running @boneskull I see you added PR PLEASE -- what's the scope of a PR you'd accept? To switch coverage to something less obtrusive -- or get I think this can be fixed by ignoring lib-cov/mocha, i.e. adding |
Came here to offer my 2 cents for a webpack workaround resolve: {
alias: {
stylus$: 'stylus/lib/stylus',
},
} |
mocha/index.js
:The text was updated successfully, but these errors were encountered: