From 9a9e2b4125d1ce300e2fc13f12404871b918ac90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sat, 22 Mar 2014 20:44:52 +0100 Subject: [PATCH 01/14] rename test parameter as testNumber (old one can be left for compatibility) --- index.js | 9 +++++---- readme.md | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index c487655..da5971d 100644 --- a/index.js +++ b/index.js @@ -11,8 +11,9 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { var argv = require('optimist') .alias('module', 'm') .describe('module', 'Run an individual module') - .alias('test', 't') - .describe('test', 'Run an individual test by number') + .alias('testNumber', 'test') /** @deprecated */ + .alias('testNumber', 't') + .describe('testNumber', 'Run an individual test by number') .alias('quiet', 'q') .describe('quiet', 'Hide passed tests') .boolean('quiet') @@ -20,7 +21,7 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { QUnit.config.autorun = false; QUnit.config.module = argv.module; - QUnit.config.testNumber = argv.test; + QUnit.config.testNumber = argv.testNumber; module.exports = QUnit; var errors = [], @@ -76,4 +77,4 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { }); } -})(); \ No newline at end of file +})(); diff --git a/readme.md b/readme.md index 97069e2..8b6601a 100644 --- a/readme.md +++ b/readme.md @@ -45,9 +45,9 @@ There are several command line options available when running your tests using qunit-cli that mimic some of the options in the standard browser-based QUnit testing interface. They are: - --module, -m Limits testing to an individual module - --test, -t Limits testing to a single test (by number) - --quiet, -q Flag to hide passed tests from the output + --module, -m Limits testing to an individual module + --testNumber, -t Limits testing to a single test (by number) + --quiet, -q Flag to hide passed tests from the output The command-line test runner has some additional options available: From 765dc021ec690b3c7ca900ab446aa5c8c84b0411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sat, 22 Mar 2014 22:14:47 +0100 Subject: [PATCH 02/14] Added parameters for QUnit configs and deprecation messages --- index.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index da5971d..dd73f0a 100644 --- a/index.js +++ b/index.js @@ -9,19 +9,42 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { colors = require('colors'); var argv = require('optimist') + .describe('hidepassed', 'Show only the failing tests, hiding all that pass') + .default('hidepassed', false) .alias('module', 'm') .describe('module', 'Run an individual module') - .alias('testNumber', 'test') /** @deprecated */ + .describe('requireExpects', 'Require each test to specify the number of expected assertions') + .default('requireExpects', false) .alias('testNumber', 't') .describe('testNumber', 'Run an individual test by number') + .describe('test', 'Run an individual test by number (deprecated)') + .describe('testTimeout', 'Global timeout in milliseconds after which all tests will fail') .alias('quiet', 'q') - .describe('quiet', 'Hide passed tests') + .describe('quiet', 'Hide passed tests (deprecated)') .boolean('quiet') .argv; + // Deprecation notices + + if(argv.test != undefined) + { + console.warn('"test" parameter is deprecated, please use "testNumber" instead'); + argv.testNumber = argv.testNumber || argv.test; + }; + + if(argv.quiet != undefined) + console.warn('"quiet" parameter is deprecated, please use "hidepassed" instead'); + + // QUnit configurations + QUnit.config.autorun = false; + + QUnit.config.hidepassed = argv.hidepassed; QUnit.config.module = argv.module; + QUnit.config.requireExpects = argv.requireExpects; QUnit.config.testNumber = argv.testNumber; + QUnit.config.testTimeout = argv.testTimeout; + module.exports = QUnit; var errors = [], From c1085b0bd8ec53626e1b0eb2022c558cb3f9d7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sat, 22 Mar 2014 22:44:26 +0100 Subject: [PATCH 03/14] allow to set new entries on urlConfig, so we can check that the values are valid ones --- index.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index dd73f0a..4011db4 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { var QUnit = require('qunitjs'), colors = require('colors'); - var argv = require('optimist') + var optimist = require('optimist') .describe('hidepassed', 'Show only the failing tests, hiding all that pass') .default('hidepassed', false) .alias('module', 'm') @@ -22,7 +22,8 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { .alias('quiet', 'q') .describe('quiet', 'Hide passed tests (deprecated)') .boolean('quiet') - .argv; + .describe('urlConfig', 'Add a config parameter of your own in JSON'); + var argv = optimist.argv; // Deprecation notices @@ -45,6 +46,39 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { QUnit.config.testNumber = argv.testNumber; QUnit.config.testTimeout = argv.testTimeout; + // Add user own config parameters + var urlConfig = argv.urlConfig; + if (urlConfig) { + function addConfig(urlConfig) { + urlConfig = JSON.parse(urlConfig); + + // Add config parameter to QUnit-cli so it can be checked + var id = urlConfig.id; + var value = urlConfig.value; + + optimist.describe(id, urlConfig.tooltip || urlConfig.label); + + if(value == undefined) + optimist.boolean(id); + else if(typeof value == 'string') + optimist.boolean(id); + + // Add config parameter to QUnit so it can be processed + QUnit.config.urlConfig.push(urlConfig); + } + + if (urlConfig instanceof Array) { + urlConfig.forEach(function(config) { + addConfig(config); + }); + } else { + addConfig(urlConfig); + } + }; + + // Check arguments against user own config parameters + argv = optimist.argv; + module.exports = QUnit; var errors = [], From 49046a9d5394a64349e3bc4268555d9405bab320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 23 Mar 2014 00:08:32 +0100 Subject: [PATCH 04/14] allow to set "unknown" parameters on the QUnit.config object, so this can be easily initialized --- index.js | 58 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 4011db4..670f6c1 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,14 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { var QUnit = require('qunitjs'), colors = require('colors'); + // Get user own config parameters var optimist = require('optimist') + .describe('urlConfig', 'Add a config parameter of your own in JSON') + .string('urlConfig'); + var argv = optimist.argv; + + // Define normal config parameters + optimist .describe('hidepassed', 'Show only the failing tests, hiding all that pass') .default('hidepassed', false) .alias('module', 'm') @@ -21,32 +28,9 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { .describe('testTimeout', 'Global timeout in milliseconds after which all tests will fail') .alias('quiet', 'q') .describe('quiet', 'Hide passed tests (deprecated)') - .boolean('quiet') - .describe('urlConfig', 'Add a config parameter of your own in JSON'); - var argv = optimist.argv; - - // Deprecation notices - - if(argv.test != undefined) - { - console.warn('"test" parameter is deprecated, please use "testNumber" instead'); - argv.testNumber = argv.testNumber || argv.test; - }; - - if(argv.quiet != undefined) - console.warn('"quiet" parameter is deprecated, please use "hidepassed" instead'); - - // QUnit configurations - - QUnit.config.autorun = false; + .boolean('quiet'); - QUnit.config.hidepassed = argv.hidepassed; - QUnit.config.module = argv.module; - QUnit.config.requireExpects = argv.requireExpects; - QUnit.config.testNumber = argv.testNumber; - QUnit.config.testTimeout = argv.testTimeout; - - // Add user own config parameters + // Add user own config parameters and if so, override normal ones var urlConfig = argv.urlConfig; if (urlConfig) { function addConfig(urlConfig) { @@ -76,9 +60,31 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { } }; - // Check arguments against user own config parameters + // Check arguments argv = optimist.argv; + // Deprecation notices + if(argv.test != undefined) + { + console.warn('"test" parameter is deprecated, please use "testNumber" instead'); + argv.testNumber = argv.testNumber || argv.test; + delete argv.test; + }; + + if(argv.quiet != undefined) + { + console.warn('"quiet" parameter is deprecated, please use "hidepassed" instead'); + delete argv.quiet; + }; + + // QUnit configurations + delete argv.urlConfig; + + QUnit.config.autorun = false; + + for(var key in argv) + QUnit.config[key] = argv[key]; + module.exports = QUnit; var errors = [], From e5c9295453d5c11ac8c3826e3d453a6d961bd504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 23 Mar 2014 00:54:21 +0100 Subject: [PATCH 05/14] Fixed testing for deprecation of 'quiet' parameter --- index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.js b/index.js index 670f6c1..a8478c6 100644 --- a/index.js +++ b/index.js @@ -71,11 +71,8 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { delete argv.test; }; - if(argv.quiet != undefined) - { + if(argv.quiet) console.warn('"quiet" parameter is deprecated, please use "hidepassed" instead'); - delete argv.quiet; - }; // QUnit configurations delete argv.urlConfig; From 05bf82b137e9567ad998159c6b6bc995259808f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 23 Mar 2014 01:24:59 +0100 Subject: [PATCH 06/14] Updated readme with new parameters --- readme.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 8b6601a..7fb1048 100644 --- a/readme.md +++ b/readme.md @@ -45,9 +45,13 @@ There are several command line options available when running your tests using qunit-cli that mimic some of the options in the standard browser-based QUnit testing interface. They are: - --module, -m Limits testing to an individual module - --testNumber, -t Limits testing to a single test (by number) - --quiet, -q Flag to hide passed tests from the output + --hidepassed, Show only the failing tests, hiding all that pass + --module, -m Limits testing to an individual module + --requireExpects, Require each test to specify the number of expected assertions + --testNumber, -t Limits testing to a single test (by number) + --testTimeout, Global timeout in milliseconds after which all tests will fail + --quiet, -q Flag to hide passed tests from the output (deprecated) + --urlConfig, Add a config parameter of your own in JSON The command-line test runner has some additional options available: From 5cb40c9c3822df640707396f4fc59135998de61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 23 Mar 2014 16:40:39 +0100 Subject: [PATCH 07/14] Improved type checking of parameters --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a8478c6..0222536 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,8 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { .boolean('quiet'); // Add user own config parameters and if so, override normal ones + var consts = {}; + var urlConfig = argv.urlConfig; if (urlConfig) { function addConfig(urlConfig) { @@ -45,8 +47,14 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { if(value == undefined) optimist.boolean(id); else if(typeof value == 'string') + { optimist.boolean(id); + consts[id] = value; + } + else if(!(value instanceof Array)) + optimist.string(id); + // Add config parameter to QUnit so it can be processed QUnit.config.urlConfig.push(urlConfig); } @@ -80,7 +88,7 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { QUnit.config.autorun = false; for(var key in argv) - QUnit.config[key] = argv[key]; + QUnit.config[key] = consts[key] || argv[key]; module.exports = QUnit; From ecef1d34259002eb045970d2ea43b50c42ddc74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Mon, 12 May 2014 11:41:07 +0200 Subject: [PATCH 08/14] Unnamed modules and examples of QUnit globals This fixes issue #8 --- index.js | 15 ++++++++++---- readme.md | 60 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 21 deletions(-) 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 From b9cfbf2dad3fca77f334e91f052a8a54ca8c4829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Mon, 19 May 2014 17:04:57 +0200 Subject: [PATCH 09/14] Exec QUnit.load() to allow plugins to work --- bin/qunit-cli | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/qunit-cli b/bin/qunit-cli index 06d0ea0..292e602 100755 --- a/bin/qunit-cli +++ b/bin/qunit-cli @@ -52,7 +52,10 @@ if (code) { } }; +// Load QUnit tests +QUnit.load(); + // Run tests files.forEach(function(file) { require(resolve(file)) -}); \ No newline at end of file +}); From a7f4c6d7535d697a6ed9a10c41f75b0da6bbe945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Thu, 22 May 2014 18:44:25 +0200 Subject: [PATCH 10/14] [bug] QUnit.load() overwritted QUnit.config with QUnit.urlParams --- .gitignore | 3 ++- bin/qunit-cli | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 28f1ba7..b680d8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -.DS_Store \ No newline at end of file +.DS_Store +.project diff --git a/bin/qunit-cli b/bin/qunit-cli index 292e602..27682f3 100755 --- a/bin/qunit-cli +++ b/bin/qunit-cli @@ -52,8 +52,10 @@ if (code) { } }; -// Load QUnit tests +// Load QUnit test framework +var config = QUnit.extend({}, QUnit.config); QUnit.load(); +QUnit.extend(QUnit.config, config) // Run tests files.forEach(function(file) { From 02fd362041666321791a27d1616f98147ac97971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sat, 12 Jul 2014 11:51:39 +0200 Subject: [PATCH 11/14] Updated QUnit and optimist dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 078ab0d..b0245e9 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "bugs": "http://github.com/devongovett/qunit/issues", "dependencies": { "colors": "*", - "qunitjs": "1.10.x", - "optimist": ">=0.3" + "qunitjs": "1.14.x", + "optimist": ">=0.6" }, "bin": "bin/qunit-cli" } From 360525e7f2171e72506324254303446b6af8108f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Tue, 22 Jul 2014 16:06:06 +0200 Subject: [PATCH 12/14] Using ranges in versions --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b0245e9..4abbcec 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,9 @@ "bugs": "http://github.com/devongovett/qunit/issues", "dependencies": { "colors": "*", - "qunitjs": "1.14.x", - "optimist": ">=0.6" + "qunitjs": "^1.10.x", + "optimist": ">=0.3" }, - "bin": "bin/qunit-cli" + "bin": "bin/qunit-cli", + "preferGlobal": true } From 6ab82bf5a03b66da09314567f6e82a84f7d21e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Fri, 24 Oct 2014 10:06:19 +0200 Subject: [PATCH 13/14] Print the name of the QUnit test module when entering it --- index.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 3424d26..a82939e 100644 --- a/index.js +++ b/index.js @@ -95,9 +95,20 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { var errors = [], printedModule = false; + function printModule(name) + { + // Separate each module with an empty line + console.log('\n'); + + // Only print module name if it's defined + if (name) + console.log(name.bold.blue); + } + // keep track of whether we've printed the module name yet QUnit.moduleStart(function(details) { - printedModule = false; + if (printedModule = !argv.quiet) + printModule(details.name); }); // when an individual assertion fails, add it to the list of errors to display @@ -109,15 +120,8 @@ if (typeof QUnit === 'undefined' && typeof require === 'function') { // when a test ends, print success/failure and any errors QUnit.testDone(function(details) { // print the name of each module - if (!printedModule && (printedModule = !argv.quiet || details.failed)) - { - // 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 (!printedModule && details.failed) + printModule(details.module); if (details.failed) { console.log((' ✖ ' + details.name).red); From 89fc13343b85238cc0f808b618b7d6f6af6c8a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Thu, 27 Nov 2014 17:09:50 +0100 Subject: [PATCH 14/14] Allow directories as input files parameter --- bin/qunit-cli | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/bin/qunit-cli b/bin/qunit-cli index 27682f3..7848ba1 100755 --- a/bin/qunit-cli +++ b/bin/qunit-cli @@ -1,5 +1,9 @@ #!/usr/bin/env node +var fs = require('fs'); + +var extname = require('path').extname; + // Request at least one test file as parameter var argv = require('optimist') .alias('code', 'c') @@ -59,5 +63,27 @@ QUnit.extend(QUnit.config, config) // Run tests files.forEach(function(file) { - require(resolve(file)) + file = resolve(file); + + fs.stat(file, function(error, stats) + { + if(error) return console.warn(error); + + if(stats.isDirectory()) + fs.readdir(file, function(error, files) + { + if(error) return console.warn(error); + + files.forEach(function(name) + { + name = resolve(file, name); + + if(extname(name) != '.js') return console.warn('Unknown file type:',name) + + require(name) + }); + }) + else + require(file) + }) });