Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});
}

})();
})();
60 changes: 43 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down