Because PhantomJS uses a CommonJS interface, but also has a window variable defined.
Detect CommonJS usage by exports variable only (because PhantomJS use…
…s a CommonJS interface, but also has a window variable defined).
Is there some docs somewhere about CommonJS for us to follow to detect this? This code seems to change every so often in pull requests and I'd like to solve this problem once and for all.
This is quite brief but seems to be the authoritative spec:
The "Module Context" section mentions require and exports, but not window. The linked executable specs also don't mention window.
Adding a check on require (that it's a function) might be a more complete check of the spec-defined conditions for CommonJS modules, but I'd prefer to just check for exports, because that's all Jasmine needs when exporting itself.
If someone has browser-based code that defines a global exports that can't be used to export a module, I don't have a problem with that breaking.
What do you think?
Later version of the same spec (same conclusion):
This slide of a presentation linked to by the spec suggests that a CommonJS-module environment may provide a window variable:
Just ran into this myself. Can we get some dev love on this? The only requirement of commonjs is a free exports object (or optionally a module with an exports property).
@akre54 are you using 2.0rc5?
@infews I'm using 1.3.1 via grunt-contrib-jasmine. Let me check with latest.
Just upgraded. Perfect, thanks. Maybe close this issue so others like me don't think it's still outstanding?
Per above. Closing. Thanks @akre54.