So, it sounds like your first function is basically a setup function for the other tests.
It is possible to do - basically using Deferreds/promises, but it's a little bit icky, and you might get badly stung by test timeouts.
So, here's something that does a setup with a bit of asynchronous code that takes 2s. All the tests become asynchronous tests that do their work once the 'setup' Deferred has completed.
Because your 'follow on' tests have become asynchronous, you need to make sure that their timeouts cope with the time that'll be taken by your asynchronous setup (at least for the first one that happens to run).
// Some asynchronous initialization that takes 2s
setTimeout(function() {
setupCompletion.resolve({ result: 42 });
}, 2000);
doh.register("my.test1", [
{
name: "waits for async setup to complete",
timeout: 5000,
runTest: function() {
var d = new doh.Deferred();
setupCompletion.then(function (res) {
doh.is(42, res.result);
d.callback(true);
});
return d;
}
},
{
name: "also waits for async setup to complete",
timeout: 5000,
runTest: function() {
var d = new doh.Deferred();
setupCompletion.then(function (res) {
doh.is(43, res.result + 1);
d.callback(true);
});
return d;
}
}
]);
Of course, it would be nice if it were possible to arrange for a test's setUp
function to return a Deferred, but doh doesn't support that right now (as of v1.7.2).