Files
meteor/packages/tinytest/tinytest_client.js
2012-03-02 03:27:55 -08:00

73 lines
2.2 KiB
JavaScript

(function () {
var globals = (function () {return this;})();
globals.tinytest = {
run: function (reportFunc, onComplete) {
var run_id = LocalCollection.uuid();
var local_complete = false;
var remote_complete = false;
var done = false;
var maybeDone = function () {
if (!done && local_complete && remote_complete) {
done = true;
onComplete && onComplete();
}
}
var testRun = Meteor._TestManager.createRun(reportFunc);
testRun.run(function () {
local_complete = true;
maybeDone();
});
App.call('tinytest/run', run_id, function (error, result) {
if (error)
// XXX better report error
throw new Error("Test server returned an error");
});
App.onQuiesce(function () {
// XXX use _.defer to avoid calling into minimongo
// reentrantly. we need to handle this better..
// (XXX code got refactored -- still necessary?)
_.defer(function () {
// XXX this is a really sloppy way to GC the test results
// XXX huge mess. have to use onQuiesce (supposed to be
// private/for testing only) because otherwise we might start
// removing the results before they've actually all arrived at
// the client, since methods can complete before subs
// update. or, could use the complete:true hack from before..
Meteor._ServerTestResults.remove({run_id: run_id});
// and of course we shouldn't print "All tests pass!"
// until we have actually received the test results :)
remote_complete = true;
maybeDone();
});
});
var sub_handle = App.subscribe('tinytest/results', {run_id: run_id});
var query_handle = Meteor._ServerTestResults.find().observe({
added: function (doc) {
_.each(doc.report.events || [], function (event) {
delete event.cookie; // can't debug a server test on the client..
});
doc.report.server = true;
reportFunc(doc.report);
}
});
},
debug: function (cookie, reportFunc, onComplete) {
var testRun = Meteor._TestManager.createRun(reportFunc);
testRun.debug(cookie, function () {
onComplete && onComplete();
});
}
};
})();