Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Implement a node stdout reporter #790

Closed
wants to merge 9 commits into from
51 changes: 4 additions & 47 deletions Gruntfile.js
Expand Up @@ -170,56 +170,13 @@ grunt.registerTask( "testswarm", function( commit, configFile, projectName, brow
});
});

// TODO: Extract this task later, if feasible
// Also spawn a separate process to keep tests atomic
grunt.registerTask( "test-on-node", function() {
var testActive = false,
runDone = false,
done = this.async(),
QUnit = require( "./dist/qunit" );
var done = this.async();
var reporterDone = require( "./test/reporter-stdout.js" );

QUnit.testStart(function() {
testActive = true;
reporterDone(function( details ) {
done( details.failed === 0 );
});
QUnit.log(function( details ) {
if ( !testActive || details.result ) {
return;
}
var message = "name: " + details.name + " module: " + details.module +
" message: " + details.message;
grunt.log.error( message );
});
QUnit.testDone(function() {
testActive = false;
});
QUnit.done(function( details ) {
if ( runDone ) {
return;
}
var succeeded = ( details.failed === 0 ),
message = details.total + " assertions in (" + details.runtime + "ms), passed: " +
details.passed + ", failed: " + details.failed;
if ( succeeded ) {
grunt.log.ok( message );
} else {
grunt.log.error( message );
}
done( succeeded );
runDone = true;
});
QUnit.config.autorun = false;

require( "./test/logs" );
require( "./test/test" );
require( "./test/assert" );
require( "./test/async" );
require( "./test/promise" );
require( "./test/modules" );
require( "./test/deepEqual" );
require( "./test/globals" );
require( "./test/globals-node" );

QUnit.load();
});

grunt.registerTask( "build", [ "concat" ] );
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -31,7 +31,9 @@
"qunit/qunit.css",
"LICENSE.txt"
],
"dependencies": {},
"dependencies": {
"chalk": "1.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing it.

},
"devDependencies": {
"browserstack-runner": "0.2.2",
"commitplease": "2.0.0",
Expand All @@ -45,6 +47,7 @@
"grunt-qunit-istanbul": "0.4.5",
"grunt-search": "0.1.6",
"load-grunt-tasks": "0.3.0",
"qunit-reporter-stdout": "0.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only a devDependency, how does QUnit.stdout() actually add any value? Is all we're removing from userland a single require-call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad here, it needs to be a dependency, not for development.

"testswarm": "1.1.0"
},
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/export.js
Expand Up @@ -51,10 +51,21 @@ if ( typeof window !== "undefined" ) {

// For nodejs
if ( typeof module !== "undefined" && module && module.exports ) {
/*jshint node:true*/

// Load node reporter
QUnit.stdout = function( options ) {
var stdout = require( "qunit-reporter-stdout" );

return stdout( QUnit, options );
};

module.exports = QUnit;

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

/*jshint node:false*/
}

// For CommonJS with exports, but without module.exports, like Rhino
Expand Down
21 changes: 21 additions & 0 deletions test/reporter-stdout.js
@@ -0,0 +1,21 @@
/*globals QUnit:true*/
/*jshint node:true*/
var QUnit = require( "../dist/qunit" );

// Options: { output: "minimal" || "verbose" }
QUnit.stdout();

// Load QUnit tests
require( "./logs" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these tests get access to QUnit? We must be assigning global.QUnit somewhere for that to work, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will use the QUnit variable assigned above. This current file test/reporter-stdout.js will work as a context module for its following requirements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required files in node don't have access to the scope of the file that is requiring it. So the only way for the required file to have QUnit in scope is for a global (right?). Where does the global come from?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See line 3 above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That var QUnit shouldn't be accessible in the scope of any other files required here. Its a local variable, not made global in any way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's okay, but still doesn't explain why it was working before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I told before, this looks like an undocumented feature. Node modules seems to be leaking the current file scope to their following required modules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? QUnit does some crazy stuff with globals and different environments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm not. I'll check this out on an example repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the this from outro.js refers in node to global, which we then alias as window, and in exports.js we then assign window.QUnit, which in node is the same as global.QUnit. Let's fix that.

require( "./test" );
require( "./assert" );
require( "./async" );
require( "./promise" );
require( "./modules" );
require( "./deepEqual" );
require( "./globals" );
require( "./globals-node" );

module.exports = QUnit.done;

QUnit.load();