Skip to content

Commit

Permalink
Build: Support Node.js export parity with CommonJS
Browse files Browse the repository at this point in the history
Ref #521

More info: #521 (comment)
  • Loading branch information
JamesMGreene committed Jan 9, 2015
1 parent 403897f commit 56279ad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ grunt.registerTask( "test-on-node", function() {
require( "./test/modules" );
require( "./test/deepEqual" );
require( "./test/globals" );
require( "./test/globals-node" );

QUnit.load();
});
Expand Down
7 changes: 5 additions & 2 deletions src/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ if ( typeof window !== "undefined" ) {
}

// For nodejs
if ( typeof module !== "undefined" && module.exports ) {
if ( typeof module !== "undefined" && module && module.exports ) {
module.exports = QUnit;

// For consistency with CommonJS environments' exports
module.exports.QUnit = QUnit;
}

// For CommonJS with exports, but without module.exports, like Rhino
if ( typeof exports !== "undefined" ) {
if ( typeof exports !== "undefined" && exports ) {
exports.QUnit = QUnit;
}
20 changes: 20 additions & 0 deletions test/globals-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*jshint node:true */
(function() {

QUnit.module( "globals for Node.js only" );

QUnit.test( "QUnit exports", function( assert ) {
var qunit = require( "../dist/qunit" );

assert.ok( qunit, "Required module QUnit truthy" );
assert.strictEqual( qunit, QUnit, "Required module QUnit matches global QUnit" );

assert.ok( qunit.hasOwnProperty( "QUnit" ), "Required module QUnit has property QUnit" );
assert.strictEqual(
qunit.QUnit,
qunit,
"Required module QUnit's property QUnit is self-referencing"
);
});

})();
4 changes: 0 additions & 4 deletions test/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ function checkExported( assert, methods, isAssertion ) {
}
}

QUnit.test( "QUnit object", function( assert ) {
assert.ok( QUnit instanceof QUnit.constructor, "Global QUnit built from it's own constructor" );
});

QUnit.test( "QUnit exported methods", function( assert ) {
var globals = [
"test", "asyncTest", "module",
Expand Down

0 comments on commit 56279ad

Please sign in to comment.