diff --git a/packages/htmljs/htmljs_test.js b/packages/htmljs/htmljs_test.js
index 8377b3490d..cbbedf642a 100644
--- a/packages/htmljs/htmljs_test.js
+++ b/packages/htmljs/htmljs_test.js
@@ -1,6 +1,6 @@
-test("htmljs", function() {
+test("htmljs", function (test) {
// Make sure "style" works, which has to be special-cased for IE.
- assert.equal(DIV({style:"display:none"}).style.display, "none");
+ test.equal(DIV({style:"display:none"}).style.display, "none");
});
\ No newline at end of file
diff --git a/packages/livedata/livedata_tests.js b/packages/livedata/livedata_tests.js
index 28b52a8f16..ac00296619 100644
--- a/packages/livedata/livedata_tests.js
+++ b/packages/livedata/livedata_tests.js
@@ -1,9 +1,10 @@
// XXX should probably move this into a testing helpers package so it
// can be used by other tests
-var ExpectationManager = function (onComplete) {
+var ExpectationManager = function (test, onComplete) {
var self = this;
+ self.test = test;
self.onComplete = onComplete;
self.closed = false;
self.dead = false;
@@ -27,7 +28,7 @@ _.extend(ExpectationManager.prototype, {
if (typeof expected === "function")
expected.apply({}, arguments);
else
- assert.equal(_.toArray(arguments), expected);
+ self.test.equal(_.toArray(arguments), expected);
self.outstanding--;
self._check_complete();
@@ -57,7 +58,7 @@ _.extend(ExpectationManager.prototype, {
var testAsyncMulti = function (name, funcs) {
var timeout = 5000;
- testAsync(name, function (onComplete) {
+ testAsync(name, function (test, onComplete) {
var remaining = _.clone(funcs);
var runNext = function () {
@@ -65,7 +66,7 @@ var testAsyncMulti = function (name, funcs) {
if (!func)
onComplete();
else {
- var em = new ExpectationManager(function () {
+ var em = new ExpectationManager(test, function () {
Meteor.clearTimeout(timer);
runNext();
});
@@ -78,7 +79,7 @@ var testAsyncMulti = function (name, funcs) {
}, timeout);
try {
- func(_.bind(em.expect, em));
+ func(test, _.bind(em.expect, em));
} catch (exception) {
em.cancel();
test.exception(exception);
@@ -97,137 +98,137 @@ var testAsyncMulti = function (name, funcs) {
/******************************************************************************/
// XXX should check error codes
-var failure = function (code, reason) {
+var failure = function (test, code, reason) {
return function (error, result) {
- assert.equal(result, undefined);
- assert.isTrue(error && typeof error === "object");
+ test.equal(result, undefined);
+ test.isTrue(error && typeof error === "object");
if (error && typeof error === "object") {
- code && assert.equal(error.error, code);
- reason && assert.equal(error.reason, reason);
+ code && test.equal(error.error, code);
+ reason && test.equal(error.reason, reason);
// XXX should check that other keys aren't present.. should
// probably use something like the Matcher we used to have
}
};
}
-test("livedata - methods with colliding names", function () {
+test("livedata - methods with colliding names", function (test) {
var x = LocalCollection.uuid();
var m = {};
m[x] = function () {};
App.methods(m);
- assert.throws(function () {
+ test.throws(function () {
App.methods(m);
});
});
testAsyncMulti("livedata - basic method invocation", [
- function (expect) {
+ function (test, expect) {
try {
var ret = App.call("unknown method",
- expect(failure(404, "Method not found")));
+ expect(failure(test, 404, "Method not found")));
} catch (e) {
// throws immediately on server, but still calls callback
- assert.isTrue(Meteor.is_server);
+ test.isTrue(Meteor.is_server);
return;
}
// returns undefined on client, then calls callback
- assert.isTrue(Meteor.is_client);
- assert.equal(ret, undefined);
+ test.isTrue(Meteor.is_client);
+ test.equal(ret, undefined);
},
- function (expect) {
+ function (test, expect) {
var ret = App.call("echo", expect(undefined, []));
- assert.equal(ret, []);
+ test.equal(ret, []);
},
- function (expect) {
+ function (test, expect) {
var ret = App.call("echo", 12, expect(undefined, [12]));
- assert.equal(ret, [12]);
+ test.equal(ret, [12]);
},
- function (expect) {
+ function (test, expect) {
var ret = App.call("echo", 12, {x: 13}, expect(undefined, [12, {x: 13}]));
- assert.equal(ret, [12, {x: 13}]);
+ test.equal(ret, [12, {x: 13}]);
},
- function (expect) {
- assert.throws(function () {
+ function (test, expect) {
+ test.throws(function () {
var ret = App.call("exception", "both",
- expect(failure(500, "Internal server error")));
+ expect(failure(test, 500, "Internal server error")));
});
},
- function (expect) {
+ function (test, expect) {
try {
var ret = App.call("exception", "server",
- expect(failure(500, "Internal server error")));
+ expect(failure(test, 500, "Internal server error")));
} catch (e) {
- assert.isTrue(Meteor.is_server);
+ test.isTrue(Meteor.is_server);
return;
}
- assert.isTrue(Meteor.is_client);
- assert.equal(ret, undefined);
+ test.isTrue(Meteor.is_client);
+ test.equal(ret, undefined);
},
- function (expect) {
+ function (test, expect) {
if (Meteor.is_client) {
- assert.throws(function () {
+ test.throws(function () {
var ret = App.call("exception", "client", expect(undefined, undefined));
});
} else {
var ret = App.call("exception", "client", expect(undefined, undefined));
- assert.equal(ret, undefined);
+ test.equal(ret, undefined);
}
}
]);
-var checkBalances = function (a, b) {
+var checkBalances = function (test, a, b) {
var alice = Ledger.findOne({name: "alice", world: test.runId()});
var bob = Ledger.findOne({name: "bob", world: test.runId()});
- assert.equal(alice.balance, a);
- assert.equal(bob.balance, b);
+ test.equal(alice.balance, a);
+ test.equal(bob.balance, b);
}
// would be nice to have a database-aware test harness of some kind --
// this is a big hack (and XXX pollutes the global test namespace)
testAsyncMulti("livedata - compound methods", [
- function () {
+ function (test) {
if (Meteor.is_client)
Meteor.subscribe("ledger", {world: test.runId()});
Ledger.insert({name: "alice", balance: 100, world: test.runId()});
Ledger.insert({name: "bob", balance: 50, world: test.runId()});
},
- function (expect) {
+ function (test, expect) {
App.call('ledger/transfer', test.runId(), "alice", "bob", 10,
expect(undefined, undefined));
- checkBalances(90, 60);
+ checkBalances(test, 90, 60);
var release = expect();
App.onQuiesce(function () {
- checkBalances(90, 60);
+ checkBalances(test, 90, 60);
Meteor.defer(release);
});
},
- function (expect) {
+ function (test, expect) {
App.call('ledger/transfer', test.runId(), "alice", "bob", 100, true,
- expect(failure(409)));
+ expect(failure(test, 409)));
if (Meteor.is_client)
// client can fool itself by cheating, but only until the sync
// finishes
- checkBalances(-10, 160);
+ checkBalances(test, -10, 160);
else
- checkBalances(90, 60);
+ checkBalances(test, 90, 60);
var release = expect();
App.onQuiesce(function () {
- checkBalances(90, 60);
+ checkBalances(test, 90, 60);
Meteor.defer(release);
});
}
diff --git a/packages/liveui/liverange_tests.js b/packages/liveui/liverange_tests.js
index cf88bc2ded..bd4902702f 100644
--- a/packages/liveui/liverange_tests.js
+++ b/packages/liveui/liverange_tests.js
@@ -40,8 +40,8 @@ var dump = function (what, tag) {
};
// actual can be a range or a fragment
-var assert_dump = function (expected, actual, tag) {
- assert.equal(dump(actual), expected, "Tree doesn't match");
+var assert_dump = function (test, expected, actual, tag) {
+ test.equal(dump(actual), expected, "Tree doesn't match");
if (actual instanceof Meteor.ui._LiveRange)
check_liverange_integrity(actual);
else {
@@ -88,198 +88,198 @@ var assert_contained = function (r, expected) {
/******************************************************************************/
-test("liverange - single node", function () {
+test("liverange - single node", function (test) {
var f = frag("
");
var r_a = create("a", f);
- assert.instanceOf(r_a, Meteor.ui._LiveRange);
- assert_dump("<1>1>", r_a);
- assert_dump("<1>1>", f);
+ test.instanceOf(r_a, Meteor.ui._LiveRange);
+ assert_dump(test, "<1>1>", r_a);
+ assert_dump(test, "<1>1>", f);
assert_contained(r_a, {range: r_a, children: []});
var r_b = create("b", f);
- assert_dump("<1>1>", r_a);
- assert_dump("<1>1>", r_b);
- assert_dump("<1>1>", f);
+ assert_dump(test, "<1>1>", r_a);
+ assert_dump(test, "<1>1>", r_b);
+ assert_dump(test, "<1>1>", f);
assert_contained(r_a, {range: r_a, children: []});
assert_contained(r_b, {range: r_b, children: [{range: r_a, children: []}]});
- assert.equal(r_a.firstNode(), f.firstChild);
- assert.equal(r_a.lastNode(), f.lastChild);
- assert.equal(r_b.firstNode(), f.firstChild);
- assert.equal(r_b.lastNode(), f.lastChild);
+ test.equal(r_a.firstNode(), f.firstChild);
+ test.equal(r_a.lastNode(), f.lastChild);
+ test.equal(r_b.firstNode(), f.firstChild);
+ test.equal(r_b.lastNode(), f.lastChild);
var ret1 = r_a.replace_contents(frag(""));
- assert.equal(ret1.nodeType, 11 /* DocumentFragment */);
- assert_dump("<1>1>", ret1);
- assert_dump("<2>2>", r_a);
- assert_dump("<2>2>", r_b);
- assert_dump("<2>2>", f);
+ test.equal(ret1.nodeType, 11 /* DocumentFragment */);
+ assert_dump(test, "<1>1>", ret1);
+ assert_dump(test, "<2>2>", r_a);
+ assert_dump(test, "<2>2>", r_b);
+ assert_dump(test, "<2>2>", f);
var ret2 = r_b.replace_contents(frag(""));
- assert_dump("<2>2>", ret2);
- assert_dump("<2>2>", r_a);
- assert_dump("<3>3>", r_b);
- assert_dump("<3>3>", f);
+ assert_dump(test, "<2>2>", ret2);
+ assert_dump(test, "<2>2>", r_a);
+ assert_dump(test, "<3>3>", r_b);
+ assert_dump(test, "<3>3>", f);
r_a.destroy();
- assert_dump("<2>2>", ret2);
+ assert_dump(test, "<2>2>", ret2);
var r_c = create("c", f);
var r_d = create("d", f);
var r_e = create("e", f);
- assert_dump("<3>3>", r_c);
- assert_dump("<3>3>", r_d);
- assert_dump("<3>3>", r_e);
- assert_dump("<1>1>", ret1);
- assert_dump("<3>3>", r_b);
+ assert_dump(test, "<3>3>", r_c);
+ assert_dump(test, "<3>3>", r_d);
+ assert_dump(test, "<3>3>", r_e);
+ assert_dump(test, "<1>1>", ret1);
+ assert_dump(test, "<3>3>", r_b);
r_d.destroy();
- assert_dump("<3>3>", r_b);
- assert_dump("<3>3>", r_c);
- assert_dump("<3>3>", r_e);
- assert_dump("<1>1>", ret1);
+ assert_dump(test, "<3>3>", r_b);
+ assert_dump(test, "<3>3>", r_c);
+ assert_dump(test, "<3>3>", r_e);
+ assert_dump(test, "<1>1>", ret1);
assert_contained(r_e,
{range: r_e,
children: [{range: r_c,
children: [{range: r_b, children: []}]}]});
- assert.equal(r_b.firstNode(), f.firstChild);
- assert.equal(r_b.lastNode(), f.lastChild);
- assert.equal(r_c.firstNode(), f.firstChild);
- assert.equal(r_c.lastNode(), f.lastChild);
- assert.equal(r_e.firstNode(), f.firstChild);
- assert.equal(r_e.lastNode(), f.lastChild);
+ test.equal(r_b.firstNode(), f.firstChild);
+ test.equal(r_b.lastNode(), f.lastChild);
+ test.equal(r_c.firstNode(), f.firstChild);
+ test.equal(r_c.lastNode(), f.lastChild);
+ test.equal(r_e.firstNode(), f.firstChild);
+ test.equal(r_e.lastNode(), f.lastChild);
r_b.destroy();
- assert_dump("<3>3>", r_c);
- assert_dump("<3>3>", r_e);
+ assert_dump(test, "<3>3>", r_c);
+ assert_dump(test, "<3>3>", r_e);
r_e.destroy();
- assert_dump("<3>3>", r_c);
+ assert_dump(test, "<3>3>", r_c);
});
-test("liverange - multiple nodes", function () {
+test("liverange - multiple nodes", function (test) {
var f = frag("");
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_a = create("a", f.childNodes[2], f.childNodes[3]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
var r_b = create("b", f.childNodes[3], f.childNodes[3]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
var r_c = create("c", f.childNodes[2], f.childNodes[3]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
var r_d = create("d", f.childNodes[3], f.childNodes[3]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
- assert_dump("<4>4>", r_d);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
+ assert_dump(test, "<4>4>", r_d);
var r_e = create("e", f.childNodes[2], f.childNodes[2]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
- assert_dump("<4>4>", r_d);
- assert_dump("<3>3>", r_e);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
+ assert_dump(test, "<4>4>", r_d);
+ assert_dump(test, "<3>3>", r_e);
var r_f = create("f", f.childNodes[2], f.childNodes[3]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
- assert_dump("<4>4>", r_d);
- assert_dump("<3>3>", r_e);
- assert_dump("<3>3><4>4>", r_f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
+ assert_dump(test, "<4>4>", r_d);
+ assert_dump(test, "<3>3>", r_e);
+ assert_dump(test, "<3>3><4>4>", r_f);
assert_contained(r_f, {range: r_f, children: [{range: r_c, children: [{range: r_a, children: [{range: r_e, children: []},{range: r_d, children: [{range: r_b, children: []}]}]}]}]});
var r_g = create("g", f.childNodes[0], f.childNodes[3]);
var r_h = create("h", f.childNodes[0], f.childNodes[3]);
var r_i = create("i", f.childNodes[1], f.childNodes[3]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
- assert_dump("<4>4>", r_d);
- assert_dump("<3>3>", r_e);
- assert_dump("<3>3><4>4>", r_f);
- assert_dump("<1>1><2>2><3>3><4>4>", r_g);
- assert_dump("<1>1><2>2><3>3><4>4>", r_h);
- assert_dump("<2>2><3>3><4>4>", r_i);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
+ assert_dump(test, "<4>4>", r_d);
+ assert_dump(test, "<3>3>", r_e);
+ assert_dump(test, "<3>3><4>4>", r_f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4>", r_g);
+ assert_dump(test, "<1>1><2>2><3>3><4>4>", r_h);
+ assert_dump(test, "<2>2><3>3><4>4>", r_i);
var f2 = frag("");
f2.childNodes[1].appendChild(f);
- assert_dump("", f);
- assert_dump("<6>6><7><1>1><2>2><3>3><4>4><5>5>7><8>8>", f2);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
- assert_dump("<4>4>", r_d);
- assert_dump("<3>3>", r_e);
- assert_dump("<3>3><4>4>", r_f);
- assert_dump("<1>1><2>2><3>3><4>4>", r_g);
- assert_dump("<1>1><2>2><3>3><4>4>", r_h);
- assert_dump("<2>2><3>3><4>4>", r_i);
+ assert_dump(test, "", f);
+ assert_dump(test, "<6>6><7><1>1><2>2><3>3><4>4><5>5>7><8>8>", f2);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
+ assert_dump(test, "<4>4>", r_d);
+ assert_dump(test, "<3>3>", r_e);
+ assert_dump(test, "<3>3><4>4>", r_f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4>", r_g);
+ assert_dump(test, "<1>1><2>2><3>3><4>4>", r_h);
+ assert_dump(test, "<2>2><3>3><4>4>", r_i);
var r_j = create("j", f2.childNodes[1], f2.childNodes[2]);
var r_k = create("k", f2.childNodes[0], f2.childNodes[2]);
var r_l = create("l", f2.childNodes[0], f2.childNodes[2]);
- assert_dump("<6>6><7><1>1><2>2><3>3><4>4><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><2>2><3>3><4>4><5>5>7><8>8>", f2);
var f3 = frag("");
var r_m = create("m", f3.childNodes[0], f3.childNodes[2]);
var r_n = create("n", f3.childNodes[0], f3.childNodes[0]);
var r_o = create("o", f3.childNodes[0], f3.childNodes[0]);
- assert_dump("<9>9><10>10><11>11>", f3);
+ assert_dump(test, "<9>9><10>10><11>11>", f3);
var ret1 = r_i.replace_contents(f3);
- assert_dump("", f3);
- assert_dump("<2>2><3>3><4>4>", ret1);
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
- assert_dump("<3>3><4>4>", r_a);
- assert_dump("<4>4>", r_b);
- assert_dump("<3>3><4>4>", r_c);
- assert_dump("<4>4>", r_d);
- assert_dump("<3>3>", r_e);
- assert_dump("<3>3><4>4>", r_f);
- assert_dump("<1>1><9>9><10>10><11>11>", r_g);
- assert_dump("<1>1><9>9><10>10><11>11>", r_h);
- assert_dump("<9>9><10>10><11>11>",r_i);
- assert_dump("<7><1>1><9>9><10>10><11>11><5>5>7><8>8>", r_j);
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", r_k);
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", r_l);
+ assert_dump(test, "", f3);
+ assert_dump(test, "<2>2><3>3><4>4>", ret1);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<3>3><4>4>", r_a);
+ assert_dump(test, "<4>4>", r_b);
+ assert_dump(test, "<3>3><4>4>", r_c);
+ assert_dump(test, "<4>4>", r_d);
+ assert_dump(test, "<3>3>", r_e);
+ assert_dump(test, "<3>3><4>4>", r_f);
+ assert_dump(test, "<1>1><9>9><10>10><11>11>", r_g);
+ assert_dump(test, "<1>1><9>9><10>10><11>11>", r_h);
+ assert_dump(test, "<9>9><10>10><11>11>",r_i);
+ assert_dump(test, "<7><1>1><9>9><10>10><11>11><5>5>7><8>8>", r_j);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", r_k);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", r_l);
r_h.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_m.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_n.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_j.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_o.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_g.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_l.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_i.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
r_k.destroy();
- assert_dump("<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
+ assert_dump(test, "<6>6><7><1>1><9>9><10>10><11>11><5>5>7><8>8>", f2);
});
-test("liverange - deep visit", function () {
+test("liverange - deep visit", function (test) {
var f = frag("");
@@ -294,71 +294,71 @@ test("liverange - deep visit", function () {
var r_c = create("c", dive(f, 2), dive(f, 2));
var r_d = create("d", f);
- assert_dump("<1><2><3><4><5>5>4>3>2>1>",
+ assert_dump(test, "<1><2><3><4><5>5>4>3>2>1>",
f);
assert_contained(r_d,
{range: r_d, children: [{range: r_c, children: [{range: r_b, children: [{range: r_a, children: []}]}]}]});
});
-test("liverange - create inner", function () {
+test("liverange - create inner", function (test) {
// Basics
var f = frag("");
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_a = create("a", f.childNodes[2], f.childNodes[4], true);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_b = create("b", f.childNodes[2], f.childNodes[4], true);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_c = create("c", f.childNodes[2], f.childNodes[4]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
// [{[a] [b]}]
var r_d = create("d", f.childNodes[0], f.childNodes[0]);
var r_e = create("e", f.childNodes[1], f.childNodes[1]);
var r_f = create("f", f.childNodes[0], f.childNodes[1]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_g = create("g", f.childNodes[0], f.childNodes[1], true);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_h = create("h", f.childNodes[0], f.childNodes[1]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_i = create("i", f.childNodes[0], f.childNodes[1], true);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_j = create("j", f.childNodes[0], f.childNodes[0], true);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_k = create("k", f.childNodes[0], f.childNodes[0]);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
var r_l = create("l", f.childNodes[0], f.childNodes[1], true);
- assert_dump("<1>1><2>2><3>3><4>4><5>5>", f);
- assert_dump("<3>3><4>4><5>5>", r_c);
- assert_dump("<3>3><4>4><5>5>", r_b);
- assert_dump("<3>3><4>4><5>5>", r_a);
- assert_dump("<1>1>", r_d);
- assert_dump("<2>2>", r_e);
- assert_dump("<1>1><2>2>", r_f);
- assert_dump("<1>1><2>2>", r_g);
- assert_dump("<1>1><2>2>", r_h);
- assert_dump("<1>1><2>2>", r_i);
- assert_dump("<1>1>", r_j);
- assert_dump("<1>1>", r_k);
- assert_dump("<1>1><2>2>", r_l);
+ assert_dump(test, "<1>1><2>2><3>3><4>4><5>5>", f);
+ assert_dump(test, "<3>3><4>4><5>5>", r_c);
+ assert_dump(test, "<3>3><4>4><5>5>", r_b);
+ assert_dump(test, "<3>3><4>4><5>5>", r_a);
+ assert_dump(test, "<1>1>", r_d);
+ assert_dump(test, "<2>2>", r_e);
+ assert_dump(test, "<1>1><2>2>", r_f);
+ assert_dump(test, "<1>1><2>2>", r_g);
+ assert_dump(test, "<1>1><2>2>", r_h);
+ assert_dump(test, "<1>1><2>2>", r_i);
+ assert_dump(test, "<1>1>", r_j);
+ assert_dump(test, "<1>1>", r_k);
+ assert_dump(test, "<1>1><2>2>", r_l);
// [{a b [c]}]
f = frag("");
r_a = create("a", f.childNodes[2], f.childNodes[2]);
r_b = create("b", f.childNodes[0], f.childNodes[2]);
r_c = create("c", f.childNodes[0], f.childNodes[2], true);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
// [{[a] b c}]
@@ -366,7 +366,7 @@ test("liverange - create inner", function () {
r_a = create("a", f.childNodes[0], f.childNodes[0]);
r_b = create("b", f.childNodes[0], f.childNodes[2]);
r_c = create("c", f.childNodes[0], f.childNodes[2], true);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
// [{[a b] c}]
@@ -374,7 +374,7 @@ test("liverange - create inner", function () {
r_a = create("a", f.childNodes[0], f.childNodes[1]);
r_b = create("b", f.childNodes[0], f.childNodes[2]);
r_c = create("c", f.childNodes[0], f.childNodes[2], true);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
// Cases where start and end have no common ranges, and so the
// balance counter will have to run
@@ -382,22 +382,22 @@ test("liverange - create inner", function () {
f = frag("");
r_a = create("a", f.childNodes[0], f.childNodes[0]);
r_b = create("b", f.childNodes[0], f.childNodes[2]);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
f = frag("");
r_a = create("a", f.childNodes[0], f.childNodes[2]);
r_b = create("b", f.childNodes[0], f.childNodes[0]);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
f = frag("");
r_a = create("a", f.childNodes[2], f.childNodes[2]);
r_b = create("b", f.childNodes[0], f.childNodes[2]);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
f = frag("");
r_a = create("a", f.childNodes[0], f.childNodes[2]);
r_b = create("b", f.childNodes[2], f.childNodes[2]);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
f = frag("");
r_a = create("a", f.childNodes[0], f.childNodes[0]);
@@ -405,14 +405,14 @@ test("liverange - create inner", function () {
r_c = create("c", f.childNodes[2], f.childNodes[2]);
r_d = create("d", f.childNodes[2], f.childNodes[2]);
r_e = create("e", f.childNodes[0], f.childNodes[2]);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
f = frag("");
r_a = create("a", f.childNodes[0], f.childNodes[0]);
r_b = create("b", f.childNodes[0], f.childNodes[0]);
r_c = create("c", f.childNodes[2], f.childNodes[2]);
r_e = create("e", f.childNodes[0], f.childNodes[2]);
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
try_all_permutations(
function () {
@@ -424,7 +424,7 @@ test("liverange - create inner", function () {
function () { create("c", f.childNodes[0], f.childNodes[2]); }
],
function () {
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
}
);
@@ -438,7 +438,7 @@ test("liverange - create inner", function () {
function () { create("c", f.childNodes[0], f.childNodes[2]); }
],
function () {
- assert_dump("<1>1><2>2><3>3>", f);
+ assert_dump(test, "<1>1><2>2><3>3>", f);
}
);
});
diff --git a/packages/liveui/liveui_tests.js b/packages/liveui/liveui_tests.js
index 7bbbf61302..5be6be7f46 100644
--- a/packages/liveui/liveui_tests.js
+++ b/packages/liveui/liveui_tests.js
@@ -30,13 +30,13 @@ var dump_frag = function (frag) {
// if expected includes '~', it will be interpreted to mean "either
// or nothing". this is useful because LiveRange is sometimes
// forced to insert placeholder comments on older versions of IE.
-var assert_frag = function (expected, actual_frag) {
+var assert_frag = function (test, expected, actual_frag) {
var expected1 = expected.replace(/~/g, "");
var expected2 = expected.replace(/~/g, "");
var actual = dump_frag(actual_frag);
if (actual !== expected1 && actual !== expected2)
- assert.equal(actual, expected, "Fragment doesn't match pattern");
+ test.equal(actual, expected, "Fragment doesn't match pattern");
if (actual.firstChild) {
/* XXX get Meteor.ui._tag in a cleaner way */
@@ -66,58 +66,58 @@ var set_weather = function (where, what) {
// XXX SECTION: LiveUI
-test("render - coercion", function () {
+test("render - coercion", function (test) {
- assert_frag("", Meteor.ui.render(function () {
+ assert_frag(test, "", Meteor.ui.render(function () {
return DIV({id: "a"});
}));
- assert_frag("", Meteor.ui.render(function () {
+ assert_frag(test, "", Meteor.ui.render(function () {
var f = document.createDocumentFragment();
f.appendChild(DIV({id: "b"}));
f.appendChild(DIV({id: "c"}));
return f;
}));
- assert_frag("", Meteor.ui.render(function () {
+ assert_frag(test, "", Meteor.ui.render(function () {
return [
DIV({id: "d"}),
DIV({id: "e"})
];
}));
- assert_frag("", Meteor.ui.render(function () {
+ assert_frag(test, "", Meteor.ui.render(function () {
return $('');
}));
- assert_frag("~hi~", Meteor.ui.render(function () {
+ assert_frag(test, "~hi~", Meteor.ui.render(function () {
return document.createTextNode("hi");
}));
- assert_frag("~igloo~", Meteor.ui.render(function () {
+ assert_frag(test, "~igloo~", Meteor.ui.render(function () {
return "igloo";
}));
- assert_frag("", Meteor.ui.render(function () {
+ assert_frag(test, "", Meteor.ui.render(function () {
return document.createComment('');
}));
});
-test("render - updating and GC", function () {
+test("render - updating and GC", function (test) {
set_weather("here", "cloudy");
- assert.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.here), 0);
var r = Meteor.ui.render(function () {
return get_weather("here");
});
- assert.length(_.keys(weather_listeners.here), 1);
- assert_frag("~cloudy~", r);
+ test.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~cloudy~", r);
set_weather("here", "icy");
- assert.length(_.keys(weather_listeners.here), 1);
- assert_frag("~cloudy~", r);
+ test.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~cloudy~", r);
Meteor.flush(); // not onscreen -- gets GC'd
- assert.length(_.keys(weather_listeners.here), 0);
- assert_frag("~cloudy~", r);
+ test.length(_.keys(weather_listeners.here), 0);
+ assert_frag(test, "~cloudy~", r);
r = Meteor.ui.render(function () {
return get_weather("here");
@@ -126,36 +126,36 @@ test("render - updating and GC", function () {
onscreen.appendChild(r);
document.body.appendChild(onscreen);
- assert_frag("~icy~", onscreen);
- assert.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~icy~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
set_weather("here", "vanilla");
- assert.length(_.keys(weather_listeners.here), 1);
- assert_frag("~icy~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~icy~", onscreen);
Meteor.flush();
- assert.length(_.keys(weather_listeners.here), 1);
- assert_frag("~vanilla~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~vanilla~", onscreen);
document.body.removeChild(onscreen);
Meteor.flush();
- assert.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.here), 1);
set_weather("here", "curious"); // safe from GC until flush
document.body.appendChild(onscreen);
Meteor.flush();
- assert.length(_.keys(weather_listeners.here), 1);
- assert_frag("~curious~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~curious~", onscreen);
document.body.removeChild(onscreen);
set_weather("here", "penguins");
- assert.length(_.keys(weather_listeners.here), 1);
- assert_frag("~curious~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~curious~", onscreen);
Meteor.flush();
- assert.length(_.keys(weather_listeners.here), 0);
- assert_frag("~curious~", onscreen);
+ test.length(_.keys(weather_listeners.here), 0);
+ assert_frag(test, "~curious~", onscreen);
});
-test("render - recursive", function () {
+test("render - recursive", function (test) {
set_weather("there", "wet");
var outer_count = 0;
@@ -172,51 +172,51 @@ test("render - recursive", function () {
})
]);
document.body.appendChild(onscreen);
- assert_frag("penguins~wet~", onscreen);
- assert.equal(outer_count, 1);
- assert.equal(inner_count, 1);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "penguins~wet~", onscreen);
+ test.equal(outer_count, 1);
+ test.equal(inner_count, 1);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
set_weather("there", "dry");
Meteor.flush();
- assert_frag("penguins~dry~", onscreen);
- assert.equal(outer_count, 1);
- assert.equal(inner_count, 2);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "penguins~dry~", onscreen);
+ test.equal(outer_count, 1);
+ test.equal(inner_count, 2);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
set_weather("here", "chocolate");
Meteor.flush();
- assert_frag("chocolate~dry~", onscreen);
- assert.equal(outer_count, 2);
- assert.equal(inner_count, 3);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "chocolate~dry~", onscreen);
+ test.equal(outer_count, 2);
+ test.equal(inner_count, 3);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
document.body.removeChild(onscreen);
set_weather("there", "melting"); // safe from GC until flush
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
document.body.appendChild(onscreen);
Meteor.flush();
- assert_frag("chocolate~melting~", onscreen);
- assert.equal(outer_count, 2);
- assert.equal(inner_count, 4);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "chocolate~melting~", onscreen);
+ test.equal(outer_count, 2);
+ test.equal(inner_count, 4);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
document.body.removeChild(onscreen);
set_weather("here", "silent");
Meteor.flush();
- assert_frag("chocolate~melting~", onscreen);
- assert.equal(outer_count, 2);
- assert.equal(inner_count, 4);
- assert.length(_.keys(weather_listeners.here), 0);
- assert.length(_.keys(weather_listeners.there), 0);
+ assert_frag(test, "chocolate~melting~", onscreen);
+ test.equal(outer_count, 2);
+ test.equal(inner_count, 4);
+ test.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.there), 0);
});
-test("render - events", function () {
+test("render - events", function (test) {
var evts = '';
var onscreen = DIV({style: "display: none;"}, [
Meteor.ui.render(function () {
@@ -246,27 +246,27 @@ test("render - events", function () {
];
}, {
"click": function (e) {
- assert.equal(12, this.x);
+ test.equal(12, this.x);
evts += "a" + e.originalEvent.data;
},
"mousedown #outer": function (e) {
- assert.equal(12, this.x);
+ test.equal(12, this.x);
evts += "b" + e.originalEvent.data;
},
"mouseup #inner1": function (e) {
- assert.equal(12, this.x);
+ test.equal(12, this.x);
evts += "c1" + e.originalEvent.data;
},
"mouseup #inner2": function (e) {
- assert.equal(12, this.x);
+ test.equal(12, this.x);
evts += "c2" + e.originalEvent.data;
},
"keypress, keydown #inner2": function (e) {
- assert.equal(12, this.x);
+ test.equal(12, this.x);
evts += "de" + e.originalEvent.data;
},
"keyup #wrapper": function (e) {
- assert.equal(12, this.x);
+ test.equal(12, this.x);
evts += "f" + e.originalEvent.data;
}
}, {x : 12})
@@ -291,7 +291,7 @@ test("render - events", function () {
var test_event = function (expected, id, event, args) {
evts = "";
simulate($('#' + id), event, args);
- assert.equal(evts, expected);
+ test.equal(evts, expected);
}
var main_event_tests = function () {
@@ -346,7 +346,7 @@ test("render - events", function () {
document.body.removeChild(onscreen);
});
-test("renderList - basics", function () {
+test("renderList - basics", function (test) {
var c = new LocalCollection();
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
@@ -358,20 +358,20 @@ test("renderList - basics", function () {
}
});
- assert_frag("", r);
+ assert_frag(test, "", r);
// Insertion
c.insert({id: "D"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "E"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "F"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "C"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "D2"});
- assert_frag("", r);
+ assert_frag(test, "", r);
// this should hit all of the edge cases in insert_before
var parts;
@@ -379,13 +379,13 @@ test("renderList - basics", function () {
c.insert({id: id});
parts.push("<" + id + ">" + id + ">");
parts.sort();
- assert_frag(parts.join(''), r);
+ assert_frag(test, parts.join(''), r);
};
try_all_permutations(
function () {
c.remove();
parts = [];
- assert_frag("", r);
+ assert_frag(test, "", r);
},
[
_.bind(do_insert, null, "D"),
@@ -394,7 +394,7 @@ test("renderList - basics", function () {
_.bind(do_insert, null, "G")
],
function () {
- assert_frag("", r);
+ assert_frag(test, "", r);
}
);
@@ -405,14 +405,14 @@ test("renderList - basics", function () {
// Change without move
c.update({id: "E"}, {$set: {id: "E2"}});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "F"}, {$set: {id: "F2"}});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "C"}, {$set: {id: "C2"}});
- assert_frag("", r);
+ assert_frag(test, "", r);
});
-test("renderList - removal", function () {
+test("renderList - removal", function (test) {
var c = new LocalCollection();
// (test is written in this weird way for historical reasons; feel
// free to refactor)
@@ -437,21 +437,21 @@ test("renderList - removal", function () {
});
c.remove({id: "D2"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.remove({id: "F2"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.remove({id: "C2"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.remove({id: "E2"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.remove({id: "D"});
- assert_frag("", r);
+ assert_frag(test, "", r);
// this should hit all of the edge cases in extract
var do_remove = function (id) {
c.remove({id: id});
delete parts["<" + id + ">" + id + ">"];
- assert_frag(_.keys(parts).sort().join('') || '', r);
+ assert_frag(test, _.keys(parts).sort().join('') || '', r);
};
try_all_permutations(
function () {
@@ -460,7 +460,7 @@ test("renderList - removal", function () {
c.insert({id: id});
parts["<" + id + ">" + id + ">"] = true;
});
- assert_frag("", r);
+ assert_frag(test, "", r);
},
[
_.bind(do_remove, null, "D"),
@@ -469,12 +469,12 @@ test("renderList - removal", function () {
_.bind(do_remove, null, "G")
],
function () {
- assert_frag("", r);
+ assert_frag(test, "", r);
}
);
});
-test("renderList - default render empty", function () {
+test("renderList - default render empty", function (test) {
var c = new LocalCollection();
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
@@ -482,15 +482,15 @@ test("renderList - default render empty", function () {
return DIV({id: doc.id});
}
});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "D"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.remove({id: "D"});
- assert_frag("", r);
+ assert_frag(test, "", r);
});
-test("renderList - change and move", function () {
+test("renderList - change and move", function (test) {
var c = new LocalCollection();
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
@@ -501,28 +501,28 @@ test("renderList - change and move", function () {
c.insert({id: "D"});
c.insert({id: "E"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "D"}, {id: "F"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "E"}, {id: "G"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "G"}, {id: "C"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "E"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.insert({id: "D"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "C"}, {id: "D2"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "F"}, {id: "D3"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "D3"}, {id: "C"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.update({id: "D2"}, {id: "F"});
- assert_frag("", r);
+ assert_frag(test, "", r);
});
-test("renderList - termination", function () {
+test("renderList - termination", function (test) {
var c = new LocalCollection();
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
@@ -533,14 +533,14 @@ test("renderList - termination", function () {
c.remove();
c.insert({id: "A"});
- assert_frag("", r);
+ assert_frag(test, "", r);
Meteor.flush(); // not onscreen, so terminates
c.insert({id: "B"});
- assert_frag("", r);
+ assert_frag(test, "", r);
c.remove({id: "A"});
- assert_frag("", r);
+ assert_frag(test, "", r);
Meteor.flush();
- assert_frag("", r);
+ assert_frag(test, "", r);
var before_flush;
var should_gc;
@@ -557,7 +557,7 @@ test("renderList - termination", function () {
return DIV({id: doc.id});
}
});
- assert_frag("", r);
+ assert_frag(test, "", r);
should_gc = false;
onscreen = null;
second_is_noop = false;
@@ -572,7 +572,7 @@ test("renderList - termination", function () {
],
function () {
before_flush = dump_frag(r);
- assert.notEqual("", before_flush);
+ test.notEqual("", before_flush);
},
// Possibly put onscreen.
[1,
@@ -603,9 +603,9 @@ test("renderList - termination", function () {
// triggered.
function () {
if (should_gc || second_is_noop)
- assert_frag(before_flush, onscreen || r);
+ assert_frag(test, before_flush, onscreen || r);
else
- assert.notEqual(before_flush, dump_frag(onscreen || r));
+ test.notEqual(before_flush, dump_frag(onscreen || r));
if (onscreen)
document.body.removeChild(onscreen);
@@ -613,7 +613,7 @@ test("renderList - termination", function () {
);
});
-test("renderList - list items are reactive", function () {
+test("renderList - list items are reactive", function (test) {
var c = new LocalCollection();
set_weather("here", "cloudy");
@@ -633,74 +633,74 @@ test("renderList - list items are reactive", function () {
onscreen.appendChild(r);
document.body.appendChild(onscreen);
- assert.equal(render_count, 0);
+ test.equal(render_count, 0);
c.insert({id: "A", want_weather: "here"});
- assert.equal(render_count, 1);
- assert_frag("", onscreen);
+ test.equal(render_count, 1);
+ assert_frag(test, "", onscreen);
c.insert({id: "B", want_weather: "here"});
- assert.equal(render_count, 2);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 2);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
c.insert({id: "C"});
- assert.equal(render_count, 3);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 3);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
c.update({id: "B"}, {$set: {id: "B2"}});
- assert.equal(render_count, 4);
- assert.length(_.keys(weather_listeners.here), 3);
- assert_frag("", onscreen);
+ test.equal(render_count, 4);
+ test.length(_.keys(weather_listeners.here), 3);
+ assert_frag(test, "", onscreen);
Meteor.flush();
- assert.equal(render_count, 4);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 4);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
c.update({id: "B2"}, {$set: {id: "D"}});
- assert.equal(render_count, 5); // move doesn't rerender
- assert.length(_.keys(weather_listeners.here), 3);
- assert_frag("", onscreen);
+ test.equal(render_count, 5); // move doesn't rerender
+ test.length(_.keys(weather_listeners.here), 3);
+ assert_frag(test, "", onscreen);
Meteor.flush();
- assert.equal(render_count, 5);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 5);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
set_weather("here", "sunny");
- assert.equal(render_count, 5);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 5);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
Meteor.flush();
- assert.equal(render_count, 7);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 7);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
c.remove({id: "A"});
- assert.equal(render_count, 7);
- assert.length(_.keys(weather_listeners.here), 2);
- assert_frag("", onscreen);
+ test.equal(render_count, 7);
+ test.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "", onscreen);
Meteor.flush();
- assert.equal(render_count, 7);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 0);
- assert_frag("", onscreen);
+ test.equal(render_count, 7);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 0);
+ assert_frag(test, "", onscreen);
c.insert({id: "F", want_weather: "there"});
- assert.equal(render_count, 8);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
- assert_frag("", onscreen);
+ test.equal(render_count, 8);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "", onscreen);
r.appendChild(onscreen); // take offscreen
Meteor.flush();
- assert.equal(render_count, 8);
- assert.length(_.keys(weather_listeners.here), 1);
- assert.length(_.keys(weather_listeners.there), 1);
- assert_frag("", onscreen);
+ test.equal(render_count, 8);
+ test.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "", onscreen);
// it's offscreen, but it wasn't taken off through a mechanism that
// calls Meteor.ui._cleanup, so we take the slow GC path. the entries
@@ -709,34 +709,34 @@ test("renderList - list items are reactive", function () {
// entries will get torn down too.)
set_weather("here", "ducky");
Meteor.flush();
- assert.equal(render_count, 8);
- assert.length(_.keys(weather_listeners.here), 0);
- assert.length(_.keys(weather_listeners.there), 1);
- assert_frag("", onscreen);
+ test.equal(render_count, 8);
+ test.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "", onscreen);
c.insert({id: "E"});
// insert renders the doc -- it has to, since renderList GC happens
// only on flush
- assert.equal(render_count, 9);
- assert.length(_.keys(weather_listeners.here), 0);
- assert.length(_.keys(weather_listeners.there), 1);
- assert_frag("", onscreen);
+ test.equal(render_count, 9);
+ test.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.there), 1);
+ assert_frag(test, "", onscreen);
Meteor.flush();
- assert.equal(render_count, 9);
- assert.length(_.keys(weather_listeners.here), 0);
- assert.length(_.keys(weather_listeners.there), 0);
- assert_frag("", onscreen);
+ test.equal(render_count, 9);
+ test.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.there), 0);
+ assert_frag(test, "", onscreen);
c.insert({id: "G"});
Meteor.flush();
- assert.equal(render_count, 9);
- assert.length(_.keys(weather_listeners.here), 0);
- assert.length(_.keys(weather_listeners.there), 0);
- assert_frag("", onscreen);
+ test.equal(render_count, 9);
+ test.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.there), 0);
+ assert_frag(test, "", onscreen);
});
-test("renderList - multiple elements in an item", function () {
+test("renderList - multiple elements in an item", function (test) {
var c = new LocalCollection();
var r;
@@ -776,7 +776,7 @@ test("renderList - multiple elements in an item", function () {
if (lengths[index] === 0)
expected += "";
});
- assert_frag(expected || "", r);
+ assert_frag(test, expected || "", r);
};
/* Consider uncommenting the 6 lines below in a "slow tests" mode */
try_all_permutations(
@@ -832,7 +832,7 @@ test("renderList - multiple elements in an item", function () {
);
});
-test("renderList - #each", function () {
+test("renderList - #each", function (test) {
var c = new LocalCollection();
var render_count = 0;
@@ -856,35 +856,35 @@ test("renderList - #each", function () {
onscreen.appendChild(Template.test_renderList_each());
document.body.appendChild(onscreen);
- assert_frag("~Before0Middle~Else~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 0);
+ assert_frag(test, "~Before0Middle~Else~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 0);
c.insert({x: 2, name: "A"});
- assert_frag("~Before0~Aducky~Middle~Else~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~Before0~Aducky~Middle~Else~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
c.insert({x: 3, name: "B"});
- assert_frag("~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 2);
set_weather("here", "clear");
- assert_frag("~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 2);
Meteor.flush();
- assert_frag("~Before0~Aclear~~Bclear~Middle~Else~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "~Before0~Aclear~~Bclear~Middle~Else~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 2);
c.update({x: 3}, {$set: {x: 8}}, {multi: true});
- assert_frag("~Before0~Aclear~Middle~B~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 2);
+ assert_frag(test, "~Before0~Aclear~Middle~B~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 2);
Meteor.flush();
- assert.length(_.keys(weather_listeners.here), 1);
+ test.length(_.keys(weather_listeners.here), 1);
c.update({}, {$set: {x: 5}}, {multi: true});
- assert_frag("~Before0Middle~Else~After~", onscreen);
- assert.length(_.keys(weather_listeners.here), 1);
+ assert_frag(test, "~Before0Middle~Else~After~", onscreen);
+ test.length(_.keys(weather_listeners.here), 1);
Meteor.flush();
- assert.length(_.keys(weather_listeners.here), 0);
+ test.length(_.keys(weather_listeners.here), 0);
document.body.removeChild(onscreen);
diff --git a/packages/logging/logging_test.js b/packages/logging/logging_test.js
index 66864a3d0b..a94a0c9b66 100644
--- a/packages/logging/logging_test.js
+++ b/packages/logging/logging_test.js
@@ -1,4 +1,4 @@
-test("logging", function() {
+test("logging", function (test) {
// Just run a log statement and make sure it doesn't explode.
Meteor._debug();
diff --git a/packages/meteor/client_environment_test.js b/packages/meteor/client_environment_test.js
index 85aee4718b..c7b38c6437 100644
--- a/packages/meteor/client_environment_test.js
+++ b/packages/meteor/client_environment_test.js
@@ -1,4 +1,4 @@
-test("environment - client basics", function () {
- assert.isTrue(Meteor.is_client);
- assert.isFalse(Meteor.is_server);
+test("environment - client basics", function (test) {
+ test.isTrue(Meteor.is_client);
+ test.isFalse(Meteor.is_server);
});
diff --git a/packages/meteor/dynamics_test.js b/packages/meteor/dynamics_test.js
index 795ec830c6..6f7ecbb714 100644
--- a/packages/meteor/dynamics_test.js
+++ b/packages/meteor/dynamics_test.js
@@ -1,32 +1,32 @@
CurrentFoo = new Meteor.DynamicVariable;
-test("environment - dynamic variables", function () {
- assert.equal(CurrentFoo.get(), undefined);
+test("environment - dynamic variables", function (test) {
+ test.equal(CurrentFoo.get(), undefined);
CurrentFoo.withValue(17, function () {
- assert.equal(CurrentFoo.get(), 17);
+ test.equal(CurrentFoo.get(), 17);
CurrentFoo.withValue(22, function () {
- assert.equal(CurrentFoo.get(), 22);
+ test.equal(CurrentFoo.get(), 22);
});
- assert.equal(CurrentFoo.get(), 17);
+ test.equal(CurrentFoo.get(), 17);
});
- assert.equal(CurrentFoo.get(), undefined);
+ test.equal(CurrentFoo.get(), undefined);
});
-test("environment - bindEnvironment", function () {
+test("environment - bindEnvironment", function (test) {
var raised_f;
var f = CurrentFoo.withValue(17, function () {
return Meteor.bindEnvironment(function (flag) {
- assert.equal(CurrentFoo.get(), 17);
+ test.equal(CurrentFoo.get(), 17);
if (flag)
throw "test";
return 12;
}, function (e) {
- assert.equal(CurrentFoo.get(), 17);
+ test.equal(CurrentFoo.get(), 17);
raised_f = e;
});
});
@@ -34,27 +34,27 @@ test("environment - bindEnvironment", function () {
var test_f = function () {
raised_f = null;
- assert.equal(f(false), 12);
- assert.equal(raised_f, null);
+ test.equal(f(false), 12);
+ test.equal(raised_f, null);
- assert.equal(f(true), undefined);
- assert.equal(raised_f, "test");
+ test.equal(f(true), undefined);
+ test.equal(raised_f, "test");
};
// At top level
- assert.equal(CurrentFoo.get(), undefined);
+ test.equal(CurrentFoo.get(), undefined);
test_f();
// Inside a withValue
CurrentFoo.withValue(22, function () {
- assert.equal(CurrentFoo.get(), 22);
+ test.equal(CurrentFoo.get(), 22);
test_f();
- assert.equal(CurrentFoo.get(), 22);
+ test.equal(CurrentFoo.get(), 22);
});
- assert.equal(CurrentFoo.get(), undefined);
+ test.equal(CurrentFoo.get(), undefined);
// Multiple environment-bound functions on the stack (in the nodejs
// implementation, this needs to avoid creating additional fibers)
@@ -63,7 +63,7 @@ test("environment - bindEnvironment", function () {
var g = CurrentFoo.withValue(99, function () {
return Meteor.bindEnvironment(function (flag) {
- assert.equal(CurrentFoo.get(), 99);
+ test.equal(CurrentFoo.get(), 99);
if (flag)
throw "trial";
@@ -71,7 +71,7 @@ test("environment - bindEnvironment", function () {
test_f();
return 88;
}, function (e) {
- assert.equal(CurrentFoo.get(), 99);
+ test.equal(CurrentFoo.get(), 99);
raised_g = e;
});
});
@@ -79,29 +79,29 @@ test("environment - bindEnvironment", function () {
var test_g = function () {
raised_g = null;
- assert.equal(g(false), 88);
- assert.equal(raised_g, null);
+ test.equal(g(false), 88);
+ test.equal(raised_g, null);
- assert.equal(g(true), undefined);
- assert.equal(raised_g, "trial");
+ test.equal(g(true), undefined);
+ test.equal(raised_g, "trial");
};
test_g();
CurrentFoo.withValue(77, function () {
- assert.equal(CurrentFoo.get(), 77);
+ test.equal(CurrentFoo.get(), 77);
test_g();
- assert.equal(CurrentFoo.get(), 77);
+ test.equal(CurrentFoo.get(), 77);
});
- assert.equal(CurrentFoo.get(), undefined);
+ test.equal(CurrentFoo.get(), undefined);
});
-testAsync("environment - bare bindEnvironment", function (onComplete) {
+testAsync("environment - bare bindEnvironment", function (test, onComplete) {
// this will have to create a fiber in nodejs
CurrentFoo.withValue(68, function () {
var f = Meteor.bindEnvironment(function () {
- assert.equal(CurrentFoo.get(), 68);
+ test.equal(CurrentFoo.get(), 68);
onComplete();
}, function () {});
diff --git a/packages/meteor/server_environment_test.js b/packages/meteor/server_environment_test.js
index b116789651..e99906ff38 100644
--- a/packages/meteor/server_environment_test.js
+++ b/packages/meteor/server_environment_test.js
@@ -1,4 +1,4 @@
-test("environment - server basics", function () {
- assert.isFalse(Meteor.is_client);
- assert.isTrue(Meteor.is_server);
+test("environment - server basics", function (test) {
+ test.isFalse(Meteor.is_client);
+ test.isTrue(Meteor.is_server);
});
diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js
index b82e800512..222efa735d 100644
--- a/packages/minimongo/minimongo_tests.js
+++ b/packages/minimongo/minimongo_tests.js
@@ -1,6 +1,6 @@
// assert that f is a strcmp-style comparison function that puts
// 'values' in the provided order
-assert_ordering = function (f, values) {
+assert_ordering = function (test, f, values) {
for (var i = 0; i < values.length; i++) {
var x = f(values[i], values[i]);
if (x !== 0) {
@@ -37,7 +37,7 @@ assert_ordering = function (f, values) {
// XXX test shared structure in all MM entrypoints
-test("minimongo - basics", function () {
+test("minimongo - basics", function (test) {
var c = new LocalCollection();
c.insert({type: "kitten", name: "fluffy"});
@@ -45,62 +45,62 @@ test("minimongo - basics", function () {
c.insert({type: "cryptographer", name: "alice"});
c.insert({type: "cryptographer", name: "bob"});
c.insert({type: "cryptographer", name: "cara"});
- assert.equal(c.find().count(), 5);
- assert.equal(c.find({type: "kitten"}).count(), 2);
- assert.equal(c.find({type: "cryptographer"}).count(), 3);
- assert.length(c.find({type: "kitten"}).fetch(), 2);
- assert.length(c.find({type: "cryptographer"}).fetch(), 3);
+ test.equal(c.find().count(), 5);
+ test.equal(c.find({type: "kitten"}).count(), 2);
+ test.equal(c.find({type: "cryptographer"}).count(), 3);
+ test.length(c.find({type: "kitten"}).fetch(), 2);
+ test.length(c.find({type: "cryptographer"}).fetch(), 3);
c.remove({name: "cara"});
- assert.equal(c.find().count(), 4);
- assert.equal(c.find({type: "kitten"}).count(), 2);
- assert.equal(c.find({type: "cryptographer"}).count(), 2);
- assert.length(c.find({type: "kitten"}).fetch(), 2);
- assert.length(c.find({type: "cryptographer"}).fetch(), 2);
+ test.equal(c.find().count(), 4);
+ test.equal(c.find({type: "kitten"}).count(), 2);
+ test.equal(c.find({type: "cryptographer"}).count(), 2);
+ test.length(c.find({type: "kitten"}).fetch(), 2);
+ test.length(c.find({type: "cryptographer"}).fetch(), 2);
c.update({name: "snookums"}, {$set: {type: "cryptographer"}});
- assert.equal(c.find().count(), 4);
- assert.equal(c.find({type: "kitten"}).count(), 1);
- assert.equal(c.find({type: "cryptographer"}).count(), 3);
- assert.length(c.find({type: "kitten"}).fetch(), 1);
- assert.length(c.find({type: "cryptographer"}).fetch(), 3);
+ test.equal(c.find().count(), 4);
+ test.equal(c.find({type: "kitten"}).count(), 1);
+ test.equal(c.find({type: "cryptographer"}).count(), 3);
+ test.length(c.find({type: "kitten"}).fetch(), 1);
+ test.length(c.find({type: "cryptographer"}).fetch(), 3);
c.remove(null);
c.remove(false);
c.remove(undefined);
- assert.equal(c.find().count(), 4);
+ test.equal(c.find().count(), 4);
c.remove({_id: null});
c.remove({_id: false});
c.remove({_id: undefined});
- assert.equal(c.find().count(), 4);
+ test.equal(c.find().count(), 4);
c.remove();
- assert.equal(0, c.find().count());
+ test.equal(0, c.find().count());
c.insert({_id: 1, name: "strawberry", tags: ["fruit", "red", "squishy"]});
c.insert({_id: 2, name: "apple", tags: ["fruit", "red", "hard"]});
c.insert({_id: 3, name: "rose", tags: ["flower", "red", "squishy"]});
- assert.equal(c.find({tags: "flower"}).count(), 1);
- assert.equal(c.find({tags: "fruit"}).count(), 2);
- assert.equal(c.find({tags: "red"}).count(), 3);
- assert.length(c.find({tags: "flower"}).fetch(), 1);
- assert.length(c.find({tags: "fruit"}).fetch(), 2);
- assert.length(c.find({tags: "red"}).fetch(), 3);
+ test.equal(c.find({tags: "flower"}).count(), 1);
+ test.equal(c.find({tags: "fruit"}).count(), 2);
+ test.equal(c.find({tags: "red"}).count(), 3);
+ test.length(c.find({tags: "flower"}).fetch(), 1);
+ test.length(c.find({tags: "fruit"}).fetch(), 2);
+ test.length(c.find({tags: "red"}).fetch(), 3);
- assert.equal(c.findOne(1).name, "strawberry");
- assert.equal(c.findOne(2).name, "apple");
- assert.equal(c.findOne(3).name, "rose");
- assert.equal(c.findOne(4), undefined);
- assert.equal(c.findOne("abc"), undefined);
- assert.equal(c.findOne(undefined), undefined);
+ test.equal(c.findOne(1).name, "strawberry");
+ test.equal(c.findOne(2).name, "apple");
+ test.equal(c.findOne(3).name, "rose");
+ test.equal(c.findOne(4), undefined);
+ test.equal(c.findOne("abc"), undefined);
+ test.equal(c.findOne(undefined), undefined);
- assert.equal(c.find(1).count(), 1);
- assert.equal(c.find(4).count(), 0);
- assert.equal(c.find("abc").count(), 0);
- assert.equal(c.find(undefined).count(), 0);
- assert.equal(c.find().count(), 3);
+ test.equal(c.find(1).count(), 1);
+ test.equal(c.find(4).count(), 0);
+ test.equal(c.find("abc").count(), 0);
+ test.equal(c.find(undefined).count(), 0);
+ test.equal(c.find().count(), 3);
var ev = "";
var makecb = function (tag) {
@@ -111,7 +111,7 @@ test("minimongo - basics", function () {
};
};
var expect = function (x) {
- assert.equal(ev, x);
+ test.equal(ev, x);
ev = "";
};
c.find({tags: "flower"}).observe(makecb('a'));
@@ -128,7 +128,7 @@ test("minimongo - basics", function () {
expect("aa4_");
});
-test("minimongo - cursors", function () {
+test("minimongo - cursors", function (test) {
var c = new LocalCollection();
var res;
@@ -136,65 +136,65 @@ test("minimongo - cursors", function () {
c.insert({i: i});
var q = c.find();
- assert.equal(q.count(), 20);
+ test.equal(q.count(), 20);
// fetch
res = q.fetch();
- assert.length(res, 20);
+ test.length(res, 20);
for (var i = 0; i < 20; i++)
- assert.equal(res[i].i, i);
+ test.equal(res[i].i, i);
// everything empty
- assert.length(q.fetch(), 0);
+ test.length(q.fetch(), 0);
q.rewind();
// forEach
var count = 0;
q.forEach(function (obj) {
- assert.equal(obj.i, count++);
+ test.equal(obj.i, count++);
});
- assert.equal(count, 20);
+ test.equal(count, 20);
// everything empty
- assert.length(q.fetch(), 0);
+ test.length(q.fetch(), 0);
q.rewind();
// map
res = q.map(function (obj) { return obj.i * 2; });
- assert.length(res, 20);
+ test.length(res, 20);
for (var i = 0; i < 20; i++)
- assert.equal(res[i], i * 2);
+ test.equal(res[i], i * 2);
// everything empty
- assert.length(q.fetch(), 0);
+ test.length(q.fetch(), 0);
// findOne (and no rewind first)
- assert.equal(c.findOne({i: 0}).i, 0);
- assert.equal(c.findOne({i: 1}).i, 1);
+ test.equal(c.findOne({i: 0}).i, 0);
+ test.equal(c.findOne({i: 1}).i, 1);
var id = c.findOne({i: 2})._id;
- assert.equal(c.findOne(id).i, 2);
+ test.equal(c.findOne(id).i, 2);
});
-test("minimongo - misc", function () {
+test("minimongo - misc", function (test) {
// deepcopy
var a = {a: [1, 2, 3], b: "x", c: true, d: {x: 12, y: [12]},
f: null};
var b = LocalCollection._deepcopy(a);
- assert.isTrue(LocalCollection._f._equal(a, b));
+ test.isTrue(LocalCollection._f._equal(a, b));
a.a.push(4);
- assert.length(b.a, 3);
+ test.length(b.a, 3);
a.c = false;
- assert.isTrue(b.c);
+ test.isTrue(b.c);
b.d.z = 15;
a.d.z = 14;
- assert.equal(b.d.z, 15);
+ test.equal(b.d.z, 15);
a.d.y.push(88);
- assert.length(b.d.y, 1);
+ test.length(b.d.y, 1);
a = {x: function () {}};
b = LocalCollection._deepcopy(a);
a.x.a = 14;
- assert.equal(b.x.a, 14); // just to document current behavior
+ test.equal(b.x.a, 14); // just to document current behavior
});
-test("minimongo - selector_compiler", function () {
+test("minimongo - selector_compiler", function (test) {
var matches = function (should_match, selector, doc) {
var does_match = LocalCollection._matches(selector, doc);
if (does_match != should_match) {
@@ -476,10 +476,10 @@ test("minimongo - selector_compiler", function () {
match({a: /a/}, {a: ['dog', 'cat']});
nomatch({a: /a/}, {a: ['dog', 'puppy']});
- assert.throws(function () {
+ test.throws(function () {
match({a: {$regex: /a/, $options: 'x'}}, {a: 'cat'});
});
- assert.throws(function () {
+ test.throws(function () {
match({a: {$regex: /a/, $options: 's'}}, {a: 'cat'});
});
@@ -506,9 +506,9 @@ test("minimongo - selector_compiler", function () {
// - non-scalar arguments to $gt, $lt, etc
});
-test("minimongo - ordering", function () {
+test("minimongo - ordering", function (test) {
// value ordering
- assert_ordering(LocalCollection._f._cmp, [
+ assert_ordering(test, LocalCollection._f._cmp, [
null,
1, 2.2, 3,
"03", "1", "11", "2", "a", "aaa",
@@ -521,7 +521,7 @@ test("minimongo - ordering", function () {
// document ordering under a sort specification
var verify = function (sorts, docs) {
_.each(sorts, function (sort) {
- assert_ordering(LocalCollection._compileSort(sort), docs);
+ assert_ordering(test, LocalCollection._compileSort(sort), docs);
});
};
@@ -538,24 +538,24 @@ test("minimongo - ordering", function () {
[["a", "asc"], ["b", "asc"]]],
[{c: 1}, {a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b: 0}]);
- assert.throws(function () {
+ test.throws(function () {
LocalCollection._compileSort("a");
});
- assert.throws(function () {
+ test.throws(function () {
LocalCollection._compileSort(123);
});
- assert.equal(LocalCollection._compileSort({})({a:1}, {a:2}), 0);
+ test.equal(LocalCollection._compileSort({})({a:1}, {a:2}), 0);
});
-test("minimongo - sort", function () {
+test("minimongo - sort", function (test) {
var c = new LocalCollection();
for (var i = 0; i < 50; i++)
for (var j = 0; j < 2; j++)
c.insert({a: i, b: j, _id: i + "_" + j});
- assert.equal(
+ test.equal(
c.find({a: {$gt: 10}}, {sort: {b: -1, a: 1}, limit: 5}).fetch(), [
{a: 11, b: 1, _id: "11_1"},
{a: 12, b: 1, _id: "12_1"},
@@ -563,7 +563,7 @@ test("minimongo - sort", function () {
{a: 14, b: 1, _id: "14_1"},
{a: 15, b: 1, _id: "15_1"}]);
- assert.equal(
+ test.equal(
c.find({a: {$gt: 10}}, {sort: {b: -1, a: 1}, skip: 3, limit: 5}).fetch(), [
{a: 14, b: 1, _id: "14_1"},
{a: 15, b: 1, _id: "15_1"},
@@ -571,7 +571,7 @@ test("minimongo - sort", function () {
{a: 17, b: 1, _id: "17_1"},
{a: 18, b: 1, _id: "18_1"}]);
- assert.equal(
+ test.equal(
c.find({a: {$gte: 20}}, {sort: {a: 1, b: -1}, skip: 50, limit: 5}).fetch(), [
{a: 45, b: 1, _id: "45_1"},
{a: 45, b: 0, _id: "45_0"},
@@ -580,7 +580,7 @@ test("minimongo - sort", function () {
{a: 47, b: 1, _id: "47_1"}]);
});
-test("minimongo - modify", function () {
+test("minimongo - modify", function (test) {
var modify = function (doc, mod, result) {
var copy = LocalCollection._deepcopy(doc);
LocalCollection._modify(copy, mod);
@@ -598,7 +598,7 @@ test("minimongo - modify", function () {
}
};
var exception = function (doc, mod) {
- assert.throws(function () {
+ test.throws(function () {
LocalCollection._modify(LocalCollection._deepcopy(doc), mod);
});
};
@@ -824,7 +824,7 @@ test("minimongo - modify", function () {
// XXX test update() (selecting docs, multi, upsert..)
-test("minimongo - observe", function () {
+test("minimongo - observe", function (test) {
var operations = [];
var cbs = {
added: function (obj, idx) {
@@ -849,41 +849,41 @@ test("minimongo - observe", function () {
var c = new LocalCollection();
handle = c.find({}, {sort: {a: 1}}).observe(cbs);
- assert.isTrue(handle.collection === c);
+ test.isTrue(handle.collection === c);
c.insert({a:1});
- assert.equal(operations.shift(), ['added', {a:1}, 0]);
+ test.equal(operations.shift(), ['added', {a:1}, 0]);
c.update({a:1}, {$set: {a: 2}});
- assert.equal(operations.shift(), ['changed', {a:2}, 0, {a:1}]);
+ test.equal(operations.shift(), ['changed', {a:2}, 0, {a:1}]);
c.insert({a:10});
- assert.equal(operations.shift(), ['added', {a:10}, 1]);
+ test.equal(operations.shift(), ['added', {a:10}, 1]);
c.update({}, {$inc: {a: 1}}, {multi: true});
- assert.equal(operations.shift(), ['changed', {a:3}, 0, {a:2}]);
- assert.equal(operations.shift(), ['changed', {a:11}, 1, {a:10}]);
+ test.equal(operations.shift(), ['changed', {a:3}, 0, {a:2}]);
+ test.equal(operations.shift(), ['changed', {a:11}, 1, {a:10}]);
c.update({a:11}, {a:1});
- assert.equal(operations.shift(), ['changed', {a:1}, 1, {a:11}]);
- assert.equal(operations.shift(), ['moved', {a:1}, 1, 0]);
+ test.equal(operations.shift(), ['changed', {a:1}, 1, {a:11}]);
+ test.equal(operations.shift(), ['moved', {a:1}, 1, 0]);
c.remove({a:2});
- assert.equal(operations.shift(), undefined);
+ test.equal(operations.shift(), undefined);
var id = c.findOne({a:3})._id;
c.remove({a:3});
- assert.equal(operations.shift(), ['removed', id, 1, {a:3}]);
+ test.equal(operations.shift(), ['removed', id, 1, {a:3}]);
// test stop
handle.stop();
c.insert({a:2});
- assert.equal(operations.shift(), undefined);
+ test.equal(operations.shift(), undefined);
// test initial inserts (and backwards sort)
handle = c.find({}, {sort: {a: -1}}).observe(cbs);
- assert.equal(operations.shift(), ['added', {a:2}, 0]);
- assert.equal(operations.shift(), ['added', {a:1}, 1]);
+ test.equal(operations.shift(), ['added', {a:2}, 0]);
+ test.equal(operations.shift(), ['added', {a:1}, 1]);
handle.stop();
// test _suppress_initial
handle = c.find({}, {sort: {a: -1}}).observe(_.extend(cbs, {_suppress_initial: true}));
- assert.equal(operations.shift(), undefined);
+ test.equal(operations.shift(), undefined);
c.insert({a:100});
- assert.equal(operations.shift(), ['added', {a:100}, 0]);
+ test.equal(operations.shift(), ['added', {a:100}, 0]);
handle.stop();
});
diff --git a/packages/stream/stream_tests.js b/packages/stream/stream_tests.js
index 5632464ac6..4bc0bbd15a 100644
--- a/packages/stream/stream_tests.js
+++ b/packages/stream/stream_tests.js
@@ -1,7 +1,7 @@
-test("stream - status", function () {
+test("stream - status", function (test) {
// Very basic test. Just see that it runs and returns something. Not a
// lot of coverage, but enough that it would have caught a recent bug.
var status = Meteor.status();
- assert.equal(typeof status, "object");
- assert.isTrue(status.status);
+ test.equal(typeof status, "object");
+ test.isTrue(status.status);
});
diff --git a/packages/templating/templating_tests.js b/packages/templating/templating_tests.js
index cba5ee7223..5ab735dd9e 100644
--- a/packages/templating/templating_tests.js
+++ b/packages/templating/templating_tests.js
@@ -1,5 +1,5 @@
-test("template assembly", function () {
+test("template assembly", function (test) {
var minusEmptyComments = function(s) {
return String(s).replace(//g, '');
};
@@ -7,7 +7,7 @@ test("template assembly", function () {
// Test for a bug that made it to production -- after a replacement,
// we need to also check the newly replaced node for replacements
var frag = Template.test_assembly_a0();
- assert.equal(minusEmptyComments(Meteor._fragmentToHtml(frag)), "Hi");
+ test.equal(minusEmptyComments(Meteor._fragmentToHtml(frag)), "Hi");
// Another production bug -- we must use LiveRange to replace the
// placeholder, or risk breaking other LiveRanges
@@ -17,10 +17,10 @@ test("template assembly", function () {
};
var onscreen = DIV({style: "display: none"}, [Template.test_assembly_b0()]);
document.body.appendChild(onscreen);
- assert.equal(minusEmptyComments(onscreen.innerHTML), "xyhi");
+ test.equal(minusEmptyComments(onscreen.innerHTML), "xyhi");
Session.set("stuff", false);
Meteor.flush();
- assert.equal(minusEmptyComments(onscreen.innerHTML), "xhi");
+ test.equal(minusEmptyComments(onscreen.innerHTML), "xhi");
document.body.removeChild(onscreen);
});
@@ -32,7 +32,7 @@ test("template assembly", function () {
-test("template table assembly", function() {
+test("template table assembly", function(test) {
var childWithTag = function(node, tag) {
return _.find(node.childNodes, function(n) {
return n.nodeName === tag;
@@ -46,11 +46,11 @@ test("template table assembly", function() {
// table.rows is a great test, as it fails not only when TR/TD tags are
// stripped due to improper html-to-fragment, but also when they are present
// but don't show up because we didn't create a TBODY for IE.
- assert.equal(table.rows.length, 3);
+ test.equal(table.rows.length, 3);
// this time with an explicit TBODY
table = childWithTag(Template.test_table_b0(), "TABLE");
- assert.equal(table.rows.length, 3);
+ test.equal(table.rows.length, 3);
var c = new LocalCollection();
c.insert({bar:'a'});
@@ -61,12 +61,12 @@ test("template table assembly", function() {
document.body.appendChild(onscreen);
table = childWithTag(onscreen, "TABLE");
- assert.equal(table.rows.length, 3);
+ test.equal(table.rows.length, 3);
var tds = onscreen.getElementsByTagName("TD");
- assert.equal(tds.length, 3);
- assert.equal(tds[0].innerHTML, "a");
- assert.equal(tds[1].innerHTML, "b");
- assert.equal(tds[2].innerHTML, "c");
+ test.equal(tds.length, 3);
+ test.equal(tds[0].innerHTML, "a");
+ test.equal(tds[1].innerHTML, "b");
+ test.equal(tds[2].innerHTML, "c");
document.body.removeChild(onscreen);
diff --git a/packages/test-helpers/try_all_permutations_test.js b/packages/test-helpers/try_all_permutations_test.js
index 005fa9187f..27e842413d 100644
--- a/packages/test-helpers/try_all_permutations_test.js
+++ b/packages/test-helpers/try_all_permutations_test.js
@@ -1,6 +1,6 @@
// XXX SECTION: Meta tests
-test("try_all_permutations", function () {
+test("try_all_permutations", function (test) {
// Have a good test of try_all_permutations, because it would suck
// if try_all_permutations didn't actually run anything and so none
// of our other tests actually did any testing.
@@ -16,7 +16,7 @@ test("try_all_permutations", function () {
function () {out += ".";}
);
- assert.equal(out, ":ABC.:ACB.:BAC.:BCA.:CAB.:CBA.");
+ test.equal(out, ":ABC.:ACB.:BAC.:BCA.:CAB.:CBA.");
out = "";
try_all_permutations(
@@ -36,7 +36,7 @@ test("try_all_permutations", function () {
function () {out += ".";}
);
- assert.equal(out, ":AB.:AC.:BA.:BC.:CA.:CB.");
+ test.equal(out, ":AB.:AC.:BA.:BC.:CA.:CB.");
out = "";
try_all_permutations(
@@ -53,9 +53,9 @@ test("try_all_permutations", function () {
],
function () {out += ".";}
);
- assert.equal(out, "ABXY.ABYX.ACXY.ACYX.ADXY.ADYX.BAXY.BAYX.BCXY.BCYX.BDXY.BDYX.CAXY.CAYX.CBXY.CBYX.CDXY.CDYX.DAXY.DAYX.DBXY.DBYX.DCXY.DCYX.");
+ test.equal(out, "ABXY.ABYX.ACXY.ACYX.ADXY.ADYX.BAXY.BAYX.BCXY.BCYX.BDXY.BDYX.CAXY.CAYX.CBXY.CBYX.CDXY.CDYX.DAXY.DAYX.DBXY.DBYX.DCXY.DCYX.");
- var test = function (n) {
+ var examine = function (n) {
var fs = [];
var seq = "";
var seen = {};
@@ -75,11 +75,11 @@ test("try_all_permutations", function () {
var expected_count = 1;
for (var i = n; i >= 1; i--)
expected_count *= i;
- assert.equal(_.keys(seen).length, expected_count);
+ test.equal(_.keys(seen).length, expected_count);
};
for (var i = 1; i <= 5; i++)
- test(i);
+ examine(i);
try_all_permutations();
});
diff --git a/packages/tinytest/tinytest.js b/packages/tinytest/tinytest.js
index 1ec7c7b10b..5f3159e6d5 100644
--- a/packages/tinytest/tinytest.js
+++ b/packages/tinytest/tinytest.js
@@ -4,7 +4,122 @@
var CurrentTestRun = new Meteor.DynamicVariable;
// XXX namespacing
-// XXX audit for use on server (eg, stupid globals hacks)
+
+/******************************************************************************/
+/* TestResultsReporter */
+/******************************************************************************/
+
+Meteor._TestResultsReporter = function (run) {
+ var self = this;
+ self.run = run;
+};
+
+_.extend(Meteor._TestResultsReporter.prototype, {
+ ok: function (doc) {
+ this.run.ok(doc);
+ },
+
+ expect_fail: function () {
+ this.run.expect_fail();
+ },
+
+ fail: function (doc) {
+ this.run.fail(doc);
+ },
+
+ exception: function (exception) {
+ this.run.exception(exception);
+ },
+
+ // returns a unique ID for this test run, for convenience use by
+ // your tests
+ runId: function () {
+ return this.run.id;
+ },
+
+ // === Following patterned after http://vowsjs.org/#reference ===
+
+ // XXX eliminate 'message' and 'not' arguments
+ equal: function (actual, expected, message, not) {
+ /* If expected is a DOM node, do a literal '===' comparison with
+ * actual. Otherwise compare the JSON stringifications of expected
+ * and actual. (It's no good to stringify a DOM node. Circular
+ * references, to start with..) */
+
+ // XXX WE REALLY SHOULD NOT BE USING
+ // STRINGIFY. stringify([undefined]) === stringify([null]). should use
+ // deep equality instead.
+
+ // XXX remove cruft specific to liverange
+ if (typeof expected === "object" && expected && expected.nodeType) {
+ var matched = expected === actual;
+ expected = "[Node]";
+ actual = "[Unknown]";
+ } else {
+ expected = JSON.stringify(expected);
+ actual = JSON.stringify(actual);
+ var matched = expected === actual;
+ }
+
+ if (matched === !!not) {
+ this.fail({type: "assert_equal", message: message,
+ expected: expected, actual: actual, not: !!not});
+ } else
+ this.ok();
+ },
+
+ notEqual: function (actual, expected, message) {
+ this.equal(actual, expected, message, true);
+ },
+
+ instanceOf: function (obj, klass) {
+ if (obj instanceof klass)
+ this.ok();
+ else
+ this.fail({type: "instanceOf"}); // XXX what other data?
+ },
+
+ // XXX should be length(), but on Chrome, functions always have a
+ // length property that is permanently 0 and can't be assigned to
+ // (it's a noop). How does vows do it??
+ length: function (obj, expected_length) {
+ if (obj.length === expected_length)
+ this.ok();
+ else
+ this.fail({type: "length"}); // XXX what other data?
+ },
+
+ // XXX nodejs assert.throws can take an expected error, as a class,
+ // regular expression, or predicate function..
+ throws: function (f) {
+ var actual;
+
+ try {
+ f();
+ } catch (exception) {
+ actual = exception;
+ }
+
+ if (actual)
+ this.ok({message: actual.message});
+ else
+ this.fail({type: "throws"});
+ },
+
+ isTrue: function (v) {
+ if (v)
+ this.ok();
+ else
+ this.fail({type: "true"});
+ },
+
+ isFalse: function (v) {
+ if (v)
+ this.fail({type: "true"});
+ else
+ this.ok();
+ }
+});
/******************************************************************************/
/* TestCase */
@@ -27,13 +142,14 @@ Meteor._TestCase = function (name, func, async) {
_.extend(Meteor._TestCase.prototype, {
// Run the test asynchronously, then call onComplete() on success,
// or else onException(e) if the test raised an exception.
- run: function (onComplete, onException) {
+ run: function (run, onComplete, onException) {
var self = this;
+ var reporter = new Meteor._TestResultsReporter(run);
_.defer(Meteor.bindEnvironment(function () {
if (self.async)
- self.func(onComplete);
+ self.func(reporter, onComplete);
else {
- self.func();
+ self.func(reporter);
onComplete();
}
}, onException));
@@ -95,12 +211,9 @@ _.extend(Meteor._TestRun.prototype, {
self.current_fail_count = 0;
self.stop_at_offset = stopAtOffset;
- var original_assert = globals.assert;
- globals.assert = test_assert;
var startTime = (+new Date);
var cleanup = function () {
- globals.assert = original_assert;
self.current_test = null;
self.current_fail_count = null;
self.stop_at_offset = null;
@@ -125,7 +238,7 @@ _.extend(Meteor._TestRun.prototype, {
onComplete();
};
- test.run(function () {
+ test.run(self, function () {
/* onComplete */
cleanup();
@@ -228,94 +341,6 @@ _.extend(Meteor._TestRun.prototype, {
}
});
-/******************************************************************************/
-/* Helpers */
-/******************************************************************************/
-
-// Patterned after http://vowsjs.org/#reference
-var test_assert = {
- // XXX eliminate 'message' and 'not' arguments
- equal: function (actual, expected, message, not) {
- /* If expected is a DOM node, do a literal '===' comparison with
- * actual. Otherwise compare the JSON stringifications of expected
- * and actual. (It's no good to stringify a DOM node. Circular
- * references, to start with..) */
-
- // XXX WE REALLY SHOULD NOT BE USING
- // STRINGIFY. stringify([undefined]) === stringify([null]). should use
- // deep equality instead.
-
- // XXX remove cruft specific to liverange
- if (typeof expected === "object" && expected && expected.nodeType) {
- var matched = expected === actual;
- expected = "[Node]";
- actual = "[Unknown]";
- } else {
- expected = JSON.stringify(expected);
- actual = JSON.stringify(actual);
- var matched = expected === actual;
- }
-
- if (matched === !!not) {
- test.fail({type: "assert_equal", message: message,
- expected: expected, actual: actual, not: !!not});
- } else
- test.ok();
- },
-
- notEqual: function (actual, expected, message) {
- test_assert.equal(actual, expected, message, true);
- },
-
- instanceOf: function (obj, klass) {
- if (obj instanceof klass)
- test.ok();
- else
- test.fail({type: "instanceOf"}); // XXX what other data?
- },
-
- // XXX should be length(), but on Chrome, functions always have a
- // length property that is permanently 0 and can't be assigned to
- // (it's a noop). How does vows do it??
- length: function (obj, expected_length) {
- if (obj.length === expected_length)
- test.ok();
- else
- test.fail({type: "length"}); // XXX what other data?
- },
-
- // XXX nodejs assert.throws can take an expected error, as a class,
- // regular expression, or predicate function..
- throws: function (f) {
- var actual;
-
- try {
- f();
- } catch (exception) {
- actual = exception;
- }
-
- if (actual)
- test.ok({message: actual.message});
- else
- test.fail({type: "throws"});
- },
-
- isTrue: function (v) {
- if (v)
- test.ok();
- else
- test.fail({type: "true"});
- },
-
- isFalse: function (v) {
- if (v)
- test.fail({type: "true"});
- else
- test.ok();
- }
-};
-
/******************************************************************************/
/* Public API */
/******************************************************************************/
@@ -331,30 +356,4 @@ globals.testAsync = function (name, func) {
Meteor._TestManager.addCase(new Meteor._TestCase(name, func, true));
};
-
-_.extend(globals.test, {
-
- ok: function (doc) {
- CurrentTestRun.get().ok(doc);
- },
-
- expect_fail: function () {
- CurrentTestRun.get().expect_fail();
- },
-
- fail: function (doc) {
- CurrentTestRun.get().fail(doc);
- },
-
- exception: function (exception) {
- CurrentTestRun.get().exception(exception);
- },
-
- // returns a unique ID for this test run, for convenience use by
- // your tests
- runId: function () {
- return CurrentTestRun.get().id;
- }
-});
-
})();
\ No newline at end of file