diff --git a/index.js b/index.js index c487655..5ed5efc 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ // Make sure we're in a non-browser environment if (typeof QUnit === 'undefined' && typeof require === 'function') { - // Currently requires an old version of QUnit because + // Currently requires an old version of QUnit because // of a regression that breaks Node.js compatibility. // See https://github.com/jquery/qunit/pull/401 var QUnit = require('qunitjs'), @@ -41,7 +41,14 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { QUnit.testDone(function(details) { // print the name of each module if (!printedModule && (printedModule = !argv.quiet || details.failed)) - console.log('\n' + details.module.bold.blue); + { + // Separate each module with an empty line + console.log('\n'); + + // Only print module name if it's defined + if (details.module) + console.log(details.module.bold.blue); + } if (details.failed) { console.log((' ✖ ' + details.name).red); @@ -70,10 +77,10 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { else console.log((msg + '.').green.bold); - process.once('exit', function() { + process.once('exit', function() { process.exit(details.failed); }); }); } -})(); \ No newline at end of file +})(); diff --git a/readme.md b/readme.md index 97069e2..8d48341 100644 --- a/readme.md +++ b/readme.md @@ -10,34 +10,60 @@ testing framework. There are two ways to use qunit-cli: -1. Include it at the top of your test files. First, install the module using npm. +1. Include it at the top of your test files. First, install the module using + npm. - npm install qunit-cli + ```bash + npm install qunit-cli + ``` And now, require it in your test files: - if (typeof QUnit == 'undefined') // if your tests also run in the browser... - QUnit = require('qunit-cli'); - - // use QUnit as you normally would. + ```Javascript + if (typeof QUnit == 'undefined') // if your tests also run in the browser... + QUnit = require('qunit-cli'); - Note that this module does not introduce QUnit into the global scope like QUnit - does in the browser, so you'll have to do that yourself if needed. + // use QUnit as you normally would. + ``` + + Note that this module does not introduce QUnit into the global scope like + QUnit does in the browser, so you'll have to do that yourself if needed: + + ```Javascript + // you can use directly the QUnit namespace... + QUnit.module('blah'); + + // ...or you can set the QUnit exports to variables as you normally would, + // or set them to the 'global' namespace so they can be available everywhere + // in your code, but this is considered a bad practice. + var asyncTest = QUnit.asyncTest; + global.ok = QUnit.ok; + + asyncTest('foo', function() + { + // 'ok' has been asigned to the global namespace + ok(true); + }); + ``` To run, use the `node` program. - node mytests.js + ```bash + node mytests.js + ``` -2. Use the command-line testrunner located at `bin/qunit-cli`, passing it the test files as arguments. - If you install the module globally using npm, you can use the `qunit-cli` command which will be - installed into your PATH. +2. Use the command-line testrunner located at `bin/qunit-cli`, passing it the + test files as arguments. If you install the module globally using npm, you + can use the `qunit-cli` command which will be installed into your PATH. - npm install qunit-cli -g - qunit-cli mytests.js + ```bash + npm install qunit-cli -g + qunit-cli mytests.js + ``` - This will introduce QUnit into the global scope like QUnit does in the browser, - so you don't need to modify the tests themselves. You can use both methods in - the same test files without problems. + This will introduce QUnit into the global scope like QUnit does in the + browser, so you don't need to modify the tests themselves. You can use both + methods in the same test files without problems. ## Command line options