sinonjs / sinon

Test spies, stubs and mocks for JavaScript.
https://sinonjs.org/
Other
9.66k stars 771 forks source link

Sandbox breaks code with QUnit because of "module" global var #91

Closed keithamus closed 12 years ago

keithamus commented 12 years ago

The sandbox module inside Sinon has a tendency to break commonjs libs because of the way it checks for module.exports.

All other libs in Sinon use this code:

var commonJSModule = typeof module == "object" && typeof require == "function";
...
if (commonJSModule) {

But the Sandbox module uses this:

if (typeof module !== "undefined") {
}

This of course becomes very fragile because, for a lib like QUnit, where "module" is a global variable, Sandbox attaches itself to QUnits module function, with a property of exports. This then breaks other code as well, for example RaphaelJS, which has this:

(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (glob.eve = eve);

Obviously module is defined (it's the QUnit module function) and exports is defined (from Sinon's Sandbox lib), so now RaphaelJS thinks it is in a nodejs style environment and breaks.

cjohansen commented 12 years ago

Thanks. Fixed and pushed in 1.3.2

broofa commented 12 years ago

Related: https://github.com/jquery/qunit/issues/190

chrisdarroch commented 12 years ago

Related: https://gitorious.org/buster/buster-core/merge_requests/2

This issue has resurfaced in recent releases by virtue of buster-core's inclusion in to the mix.