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

Closed
keithamus opened this Issue Mar 9, 2012 · 3 comments

Comments

Projects
None yet
4 participants
@keithamus
Contributor

keithamus commented Mar 9, 2012

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

This comment has been minimized.

Show comment Hide comment
@cjohansen

cjohansen Mar 11, 2012

Contributor

Thanks. Fixed and pushed in 1.3.2

Contributor

cjohansen commented Mar 11, 2012

Thanks. Fixed and pushed in 1.3.2

@cjohansen cjohansen closed this Mar 11, 2012

@broofa

This comment has been minimized.

Show comment Hide comment
@broofa

broofa Jun 29, 2012

Related: jquery/qunit#190

broofa commented Jun 29, 2012

Related: jquery/qunit#190

@chrisdarroch

This comment has been minimized.

Show comment Hide comment
@chrisdarroch

chrisdarroch Aug 3, 2012

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment