cjohansen/Sinon.JS — Issue #91: Sandbox breaks code with QUnit because of "module" global var
Author: keithamus
Created: 2012-03-09 13:40:06+00:00
State: open

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:
```javascript
var commonJSModule = typeof module == "object" && typeof require == "function";
...
if (commonJSModule) {
```

But the Sandbox module uses this:
```javascript
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:

```javascript
(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.