Comparing version 0.6.2 to 0.7.0
@@ -100,4 +100,4 @@ define(["require","exports","module","../litmus","./formatting","./utils","util"],function(require,exports,module){ | ||
test = tests[i]; | ||
var mod = require(test); | ||
var run = mod.test.createRun(); | ||
var module = require(test); | ||
var run = getLitmusForModule(module).createRun(); | ||
run.finished.then(function () { | ||
@@ -110,4 +110,22 @@ util.print(formatter.format(run)); | ||
/** | ||
* Find the litmus.Test or litmus.Suite for a module. | ||
* Previous versions of litmus expected this to be exposed under a 'test' key. | ||
*/ | ||
function getLitmusForModule (module) { | ||
if (isLitmus(module)) { | ||
return module; | ||
} | ||
if (module.test && isLitmus(module.test)) { | ||
return module.test; | ||
} | ||
throw new Error('litmus: expected module to export litmus.Test or litmus.Suite'); | ||
} | ||
function isLitmus (module) { | ||
return (module.constructor == litmus.Test || module.constructor == litmus.Suite) | ||
} | ||
}); |
@@ -214,3 +214,3 @@ define(["require","exports","module","../litmus","./utils"],function(require,exports,module){ | ||
'Litmus Test Result\n', | ||
'====================\n\n', | ||
'==================\n\n', | ||
'Result: ', | ||
@@ -328,3 +328,3 @@ setColour(run.passed ? 'green' : 'red'), | ||
for (var i = 0, l = run.exceptions.length; i < l; i++) { | ||
buffer.push('\n[ ' + setColour('red') + 'ERROR' + unsetColour() + ' ] ', run.exceptions[i].message, '\n'); | ||
buffer.push('\n' + setColour('red') + '[ ERROR ] ', run.exceptions[i].message || run.exceptions[i], unsetColour(), '\n'); | ||
} | ||
@@ -331,0 +331,0 @@ buffer.push('\n'); |
@@ -50,3 +50,3 @@ define(["require","exports","module","./lib/assertions","./lib/utils","promised-io/promise"],function(require,exports,module){/** | ||
// TODO check this | ||
promise.all( | ||
all( | ||
this.suite.tests.map(function (test) { | ||
@@ -59,3 +59,3 @@ var run = test.createRun(); | ||
promise.when( | ||
promise.all(runs.map(function (run) { return run.finished; })), | ||
all(runs.map(function (run) { return run.finished; })), | ||
function () { | ||
@@ -68,7 +68,18 @@ run.finished.resolve(runs); | ||
function _moduleName (module) { | ||
var name = module.id || module; | ||
if (process && process.cwd) { | ||
var cwd = process.cwd() | ||
if (name.indexOf(cwd) == 0) { | ||
name = name.substr(cwd.length + 1); | ||
} | ||
} | ||
return name; | ||
} | ||
/** | ||
* @constructor Collection of tests. | ||
* | ||
* @param {String} name | ||
* A readable name for the test suite. | ||
* @param {object} module | ||
* The module for the test suite. | ||
* @param {Array of litmus.Test and litmus.Suite objects} tests | ||
@@ -78,7 +89,7 @@ * The tests that make up the suite. | ||
var Suite = exports.Suite = function (name, tests) { | ||
this.name = name; | ||
var Suite = exports.Suite = function (module, tests) { | ||
this.name = _moduleName(module); | ||
this.tests = tests; | ||
if (typeof tests === 'undefined') { | ||
throw new Error('no tests passed to new litmus.Suite(name, tests) - missing name?'); | ||
throw new Error('no tests passed to new litmus.Suite(name, tests) - missing module?'); | ||
} | ||
@@ -193,2 +204,46 @@ if (typeof tests.length === 'undefined') { | ||
// the trouble with promised-io's all method is that it's failure modes are hard to handle | ||
// it seems to reject a promise more than once when faced with more than one failure | ||
// TODO propose these semantics to Kris Zyp | ||
function all (promises) { | ||
var done = new promise.Promise, | ||
successes = [], | ||
failures = [], | ||
failed = false, | ||
completed = 0, | ||
total = promises.length; | ||
if (promises.length === 0) { | ||
done.resolve([]); | ||
return done; | ||
} | ||
var check = function () { | ||
if (++completed < total) { | ||
return; | ||
} | ||
if (failures.length) { | ||
failures.successes = successes; | ||
done.reject(failures); | ||
} | ||
else { | ||
done.resolve(successes); | ||
} | ||
}; | ||
for (var i = 0; i < total; i++) { | ||
promise.when(promises[i], function (result) { | ||
successes[i] = result; | ||
check(); | ||
}, function (error) { | ||
failures[i] = error; | ||
check(); | ||
}); | ||
} | ||
return done; | ||
} | ||
/** | ||
@@ -210,8 +265,3 @@ * @method Runs the test running with the TestRun as the invocant. | ||
} | ||
promise.all(this.asyncPromises).then(function (results) { | ||
for (var i = 0, l = results.length; i < l; i++) { | ||
if (typeof(results[i]) !== 'undefined') { | ||
run.addException(results[i]); | ||
} | ||
} | ||
all(this.asyncPromises).then(function (results) { | ||
if (! run.plannedAssertionsRan()) { | ||
@@ -226,2 +276,11 @@ run.failed = true; | ||
run.finished.resolve(); | ||
}, function (err) { | ||
for (var i = 0, l = err.length; i < l; i++) { | ||
if (typeof(err[i]) !== 'undefined') { | ||
run.addException(err[i]); | ||
} | ||
} | ||
run.failed = true; | ||
run.state = finishedState; | ||
run.finished.resolve(); | ||
}); | ||
@@ -355,2 +414,4 @@ }; | ||
clearTimeout(timeout); | ||
}, function (err) { | ||
clearTimeout(timeout); | ||
}); | ||
@@ -507,4 +568,4 @@ } | ||
* | ||
* @param {String} name | ||
* The name of the test. | ||
* @param {object} module | ||
* The module for the test. | ||
* @param {Function} runFunc | ||
@@ -515,4 +576,4 @@ * The function performs the testing. This is called as a result of calling the run method and is | ||
var Test = exports.Test = function (name, runFunc) { | ||
this.name = name; | ||
var Test = exports.Test = function (module, runFunc) { | ||
this.name = _moduleName(module); | ||
this.runFunc = runFunc; | ||
@@ -519,0 +580,0 @@ }; |
define(["require","exports","module","../litmus"],function(require,exports,module){ | ||
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('basic assertions', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
@@ -6,0 +6,0 @@ this.plan(109); |
define(["require","exports","module","../litmus"],function(require,exports,module){ | ||
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('asynchronous tests', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
this.plan(5); | ||
@@ -6,0 +6,0 @@ |
define(["require","exports","module","../litmus"],function(require,exports,module){ | ||
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('events tests', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
this.plan(1); | ||
@@ -6,0 +6,0 @@ |
define(["require","exports","module","../litmus"],function(require,exports,module){ | ||
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('skipif', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
this.plan(7); | ||
@@ -6,0 +6,0 @@ |
@@ -1,11 +0,12 @@ | ||
define(["require","exports","module","../litmus","./assertions","./async","./events","./skipif"],function(require,exports,module){ | ||
define(["require","exports","module","../litmus","./assertions","./async","./commandline","./events","./skipif"],function(require,exports,module){ | ||
var litmus = require('../litmus'); | ||
exports.test = new litmus.Suite('Litmus Test Suite', [ | ||
require('./assertions').test, | ||
require('./skipif').test, | ||
require('./async').test, | ||
require('./events').test | ||
module.exports = new litmus.Suite(module, [ | ||
require('./assertions'), | ||
require('./skipif'), | ||
require('./async'), | ||
require('./events'), | ||
require('./commandline') | ||
]); | ||
}); |
@@ -100,4 +100,4 @@ | ||
test = tests[i]; | ||
var mod = require(test); | ||
var run = mod.test.createRun(); | ||
var module = require(test); | ||
var run = getLitmusForModule(module).createRun(); | ||
run.finished.then(function () { | ||
@@ -110,2 +110,21 @@ util.print(formatter.format(run)); | ||
/** | ||
* Find the litmus.Test or litmus.Suite for a module. | ||
* Previous versions of litmus expected this to be exposed under a 'test' key. | ||
*/ | ||
function getLitmusForModule (module) { | ||
if (isLitmus(module)) { | ||
return module; | ||
} | ||
if (module.test && isLitmus(module.test)) { | ||
return module.test; | ||
} | ||
throw new Error('litmus: expected module to export litmus.Test or litmus.Suite'); | ||
} | ||
function isLitmus (module) { | ||
return (module.constructor == litmus.Test || module.constructor == litmus.Suite) | ||
} |
@@ -214,3 +214,3 @@ | ||
'Litmus Test Result\n', | ||
'====================\n\n', | ||
'==================\n\n', | ||
'Result: ', | ||
@@ -328,3 +328,3 @@ setColour(run.passed ? 'green' : 'red'), | ||
for (var i = 0, l = run.exceptions.length; i < l; i++) { | ||
buffer.push('\n[ ' + setColour('red') + 'ERROR' + unsetColour() + ' ] ', run.exceptions[i].message, '\n'); | ||
buffer.push('\n' + setColour('red') + '[ ERROR ] ', run.exceptions[i].message || run.exceptions[i], unsetColour(), '\n'); | ||
} | ||
@@ -331,0 +331,0 @@ buffer.push('\n'); |
@@ -50,3 +50,3 @@ /** | ||
// TODO check this | ||
promise.all( | ||
all( | ||
this.suite.tests.map(function (test) { | ||
@@ -59,3 +59,3 @@ var run = test.createRun(); | ||
promise.when( | ||
promise.all(runs.map(function (run) { return run.finished; })), | ||
all(runs.map(function (run) { return run.finished; })), | ||
function () { | ||
@@ -68,7 +68,18 @@ run.finished.resolve(runs); | ||
function _moduleName (module) { | ||
var name = module.id || module; | ||
if (process && process.cwd) { | ||
var cwd = process.cwd() | ||
if (name.indexOf(cwd) == 0) { | ||
name = name.substr(cwd.length + 1); | ||
} | ||
} | ||
return name; | ||
} | ||
/** | ||
* @constructor Collection of tests. | ||
* | ||
* @param {String} name | ||
* A readable name for the test suite. | ||
* @param {object} module | ||
* The module for the test suite. | ||
* @param {Array of litmus.Test and litmus.Suite objects} tests | ||
@@ -78,7 +89,7 @@ * The tests that make up the suite. | ||
var Suite = exports.Suite = function (name, tests) { | ||
this.name = name; | ||
var Suite = exports.Suite = function (module, tests) { | ||
this.name = _moduleName(module); | ||
this.tests = tests; | ||
if (typeof tests === 'undefined') { | ||
throw new Error('no tests passed to new litmus.Suite(name, tests) - missing name?'); | ||
throw new Error('no tests passed to new litmus.Suite(name, tests) - missing module?'); | ||
} | ||
@@ -193,2 +204,46 @@ if (typeof tests.length === 'undefined') { | ||
// the trouble with promised-io's all method is that it's failure modes are hard to handle | ||
// it seems to reject a promise more than once when faced with more than one failure | ||
// TODO propose these semantics to Kris Zyp | ||
function all (promises) { | ||
var done = new promise.Promise, | ||
successes = [], | ||
failures = [], | ||
failed = false, | ||
completed = 0, | ||
total = promises.length; | ||
if (promises.length === 0) { | ||
done.resolve([]); | ||
return done; | ||
} | ||
var check = function () { | ||
if (++completed < total) { | ||
return; | ||
} | ||
if (failures.length) { | ||
failures.successes = successes; | ||
done.reject(failures); | ||
} | ||
else { | ||
done.resolve(successes); | ||
} | ||
}; | ||
for (var i = 0; i < total; i++) { | ||
promise.when(promises[i], function (result) { | ||
successes[i] = result; | ||
check(); | ||
}, function (error) { | ||
failures[i] = error; | ||
check(); | ||
}); | ||
} | ||
return done; | ||
} | ||
/** | ||
@@ -210,8 +265,3 @@ * @method Runs the test running with the TestRun as the invocant. | ||
} | ||
promise.all(this.asyncPromises).then(function (results) { | ||
for (var i = 0, l = results.length; i < l; i++) { | ||
if (typeof(results[i]) !== 'undefined') { | ||
run.addException(results[i]); | ||
} | ||
} | ||
all(this.asyncPromises).then(function (results) { | ||
if (! run.plannedAssertionsRan()) { | ||
@@ -226,2 +276,11 @@ run.failed = true; | ||
run.finished.resolve(); | ||
}, function (err) { | ||
for (var i = 0, l = err.length; i < l; i++) { | ||
if (typeof(err[i]) !== 'undefined') { | ||
run.addException(err[i]); | ||
} | ||
} | ||
run.failed = true; | ||
run.state = finishedState; | ||
run.finished.resolve(); | ||
}); | ||
@@ -355,2 +414,4 @@ }; | ||
clearTimeout(timeout); | ||
}, function (err) { | ||
clearTimeout(timeout); | ||
}); | ||
@@ -507,4 +568,4 @@ } | ||
* | ||
* @param {String} name | ||
* The name of the test. | ||
* @param {object} module | ||
* The module for the test. | ||
* @param {Function} runFunc | ||
@@ -515,4 +576,4 @@ * The function performs the testing. This is called as a result of calling the run method and is | ||
var Test = exports.Test = function (name, runFunc) { | ||
this.name = name; | ||
var Test = exports.Test = function (module, runFunc) { | ||
this.name = _moduleName(module); | ||
this.runFunc = runFunc; | ||
@@ -519,0 +580,0 @@ }; |
{ | ||
"name" : "litmus", | ||
"description" : "JavaScript Unit Test Library", | ||
"version" : "0.6.2", | ||
"version" : "0.7.0", | ||
"author" : "Thomas Yandell <tom.deletethis@yandell.me.uk> (http://tom.yandell.me.uk/blog/)", | ||
@@ -6,0 +6,0 @@ "contributors" : [ |
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('basic assertions', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
@@ -6,0 +6,0 @@ this.plan(109); |
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('asynchronous tests', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
this.plan(5); | ||
@@ -6,0 +6,0 @@ |
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('events tests', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
this.plan(1); | ||
@@ -6,0 +6,0 @@ |
var litmus = require('../litmus'); | ||
exports.test = new litmus.Test('skipif', function () { | ||
module.exports = new litmus.Test(module, function () { | ||
this.plan(7); | ||
@@ -6,0 +6,0 @@ |
var litmus = require('../litmus'); | ||
exports.test = new litmus.Suite('Litmus Test Suite', [ | ||
require('./assertions').test, | ||
require('./skipif').test, | ||
require('./async').test, | ||
require('./events').test | ||
module.exports = new litmus.Suite(module, [ | ||
require('./assertions'), | ||
require('./skipif'), | ||
require('./async'), | ||
require('./events'), | ||
require('./commandline') | ||
]); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
284690
39
7487
3