mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
This first part of the testing framework upgrade: - enhances the jsdoc script to allow switching to debug mode from the command line - uses Jasmine to run tests - adds flexibility to run tests from multiple root directories - does automatic test discovery, so test files can just be created, dropped in an appropriate folder, and run without having to explicity add it to the test runner - cleans up the test directory layout - incorporates env.rhino.js which should make it easier to test templates - is incomplete: this is just a savepoint. About 1/3 of the tests have been converted. The rest are still run through the old testrunner
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
(function() {
|
|
var withoutAsync = {};
|
|
|
|
["it", "beforeEach", "afterEach"].forEach(function(jasmineFunction) {
|
|
withoutAsync[jasmineFunction] = jasmine.Env.prototype[jasmineFunction];
|
|
return jasmine.Env.prototype[jasmineFunction] = function() {
|
|
var args = Array.prototype.slice.call(arguments, 0);
|
|
var timeout = null;
|
|
if (isLastArgumentATimeout(args)) {
|
|
timeout = args.pop();
|
|
}
|
|
if (isLastArgumentAnAsyncSpecFunction(args))
|
|
{
|
|
var specFunction = args.pop();
|
|
args.push(function() {
|
|
return asyncSpec(specFunction, this, timeout);
|
|
});
|
|
}
|
|
return withoutAsync[jasmineFunction].apply(this, args);
|
|
};
|
|
});
|
|
|
|
function isLastArgumentATimeout(args)
|
|
{
|
|
return args.length > 0 && (typeof args[args.length-1]) === "number";
|
|
}
|
|
|
|
function isLastArgumentAnAsyncSpecFunction(args)
|
|
{
|
|
return args.length > 0 && (typeof args[args.length-1]) === "function" && args[args.length-1].length > 0;
|
|
}
|
|
|
|
function asyncSpec(specFunction, spec, timeout) {
|
|
if (timeout == null){timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL || 1000;}
|
|
var done = false;
|
|
spec.runs(function() {
|
|
try {
|
|
return specFunction(function(error) {
|
|
done = true;
|
|
if (error != null) {
|
|
return spec.fail(error);
|
|
}
|
|
});
|
|
} catch (e) {
|
|
done = true;
|
|
throw e;
|
|
}
|
|
});
|
|
return spec.waitsFor(function() {
|
|
if (done === true) {
|
|
return true;
|
|
}
|
|
}, "spec to complete", timeout);
|
|
};
|
|
|
|
}).call(this); |