mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Merge branch 'test-fixups' into devel
This commit is contained in:
@@ -12,7 +12,7 @@ require('../../packages/handlebars/parse.js'); // XXX lame!!
|
||||
Package.on_use(function (api) {
|
||||
// XXX should only be sent if we have handlebars templates in the app..
|
||||
api.add_files('evaluate.js', 'client');
|
||||
api.use('underscore', 'client')
|
||||
api.use('underscore', 'client');
|
||||
});
|
||||
|
||||
// XXX lots more to do here .. registering this a templating engine,
|
||||
|
||||
@@ -76,7 +76,7 @@ Tinytest.add("minimongo - basics", function (test) {
|
||||
test.equal(c.find().count(), 4);
|
||||
|
||||
c.remove();
|
||||
test.equal(0, c.find().count());
|
||||
test.equal(c.find().count(), 0);
|
||||
|
||||
c.insert({_id: 1, name: "strawberry", tags: ["fruit", "red", "squishy"]});
|
||||
c.insert({_id: 2, name: "apple", tags: ["fruit", "red", "hard"]});
|
||||
|
||||
@@ -8,6 +8,7 @@ Package.on_use(function (api, where) {
|
||||
|
||||
api.add_files('try_all_permutations.js', where);
|
||||
api.add_files('async_multi.js', where);
|
||||
api.add_files('simulate_event.js', where);
|
||||
});
|
||||
|
||||
Package.on_test(function (api) {
|
||||
|
||||
14
packages/test-helpers/simulate_event.js
Normal file
14
packages/test-helpers/simulate_event.js
Normal file
@@ -0,0 +1,14 @@
|
||||
var simulateEvent = function (node, event, args) {
|
||||
node = (node instanceof $ ? node[0] : node);
|
||||
|
||||
if (document.createEvent) {
|
||||
var e = document.createEvent("Event");
|
||||
e.initEvent(event, true, true);
|
||||
_.extend(e, args);
|
||||
node.dispatchEvent(e);
|
||||
} else {
|
||||
var e = document.createEventObject();
|
||||
_.extend(e, args);
|
||||
node.fireEvent("on" + event, e);
|
||||
}
|
||||
};
|
||||
@@ -17,6 +17,11 @@
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.header .time {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.test_table {
|
||||
font-family: Arial, sans-serif;
|
||||
width: 500px;
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
<div class="header in-progress">Testing in progress ...</div>
|
||||
{{else}}
|
||||
{{#if passed}}
|
||||
<div class="header pass">All tests pass!</div>
|
||||
<div class="header pass">All tests pass!
|
||||
<span class="time">{{total_test_time}} ms</span>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="header fail">There are failures.</div>
|
||||
<div class="header fail">There are failures.
|
||||
<span class="time">{{total_test_time}} ms</span>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
@@ -74,7 +78,7 @@
|
||||
{{/if}}
|
||||
{{/with}}
|
||||
{{#if is_debuggable}}
|
||||
<span class="debug">[Debug]</a>
|
||||
<span class="debug">[Debug]</span>
|
||||
{{/if}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -47,6 +47,33 @@ Template.test_table.passed = function() {
|
||||
return walk(resultTree);
|
||||
};
|
||||
|
||||
|
||||
Template.test_table.total_test_time = function() {
|
||||
var cx = Meteor.deps.Context.current;
|
||||
if (cx) {
|
||||
resultDeps.push(cx);
|
||||
}
|
||||
|
||||
// walk whole tree to get all tests
|
||||
var walk = function (groups) {
|
||||
var total = 0;
|
||||
|
||||
_.each(groups || [], function (group) {
|
||||
_.each(group.tests || [], function (t) {
|
||||
total += _testTime(t);
|
||||
});
|
||||
|
||||
total += walk(group.groups);
|
||||
});
|
||||
|
||||
return total;
|
||||
};
|
||||
|
||||
return walk(resultTree);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Template.test_table.data = function() {
|
||||
var cx = Meteor.deps.Context.current;
|
||||
if (cx) {
|
||||
|
||||
@@ -22,6 +22,7 @@ _.extend(TestCaseResults.prototype, {
|
||||
if (doc)
|
||||
ok.details = doc;
|
||||
if (self.expecting_failure) {
|
||||
ok.details = ok.details || {};
|
||||
ok.details["was_expecting_failure"] = true;
|
||||
self.expecting_failure = false;
|
||||
}
|
||||
@@ -82,23 +83,19 @@ _.extend(TestCaseResults.prototype, {
|
||||
// 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.
|
||||
* actual. Otherwise do a deep comparison, as implemented by _.isEqual.
|
||||
*/
|
||||
|
||||
var matched;
|
||||
// XXX remove cruft specific to liverange
|
||||
if (typeof expected === "object" && expected && expected.nodeType) {
|
||||
var matched = expected === actual;
|
||||
matched = expected === actual;
|
||||
expected = "[Node]";
|
||||
actual = "[Unknown]";
|
||||
} else {
|
||||
matched = _.isEqual(expected, actual);
|
||||
expected = JSON.stringify(expected);
|
||||
actual = JSON.stringify(actual);
|
||||
var matched = expected === actual;
|
||||
}
|
||||
|
||||
if (matched === !!not) {
|
||||
@@ -203,7 +200,8 @@ _.extend(TestCaseResults.prototype, {
|
||||
if (obj.length === expected_length)
|
||||
this.ok();
|
||||
else
|
||||
this.fail({type: "length"}); // XXX what other data?
|
||||
this.fail({type: "length", expected: expected_length,
|
||||
actual: obj.length});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -99,7 +99,7 @@ Meteor._Alea = function () {
|
||||
return random;
|
||||
|
||||
} (Array.prototype.slice.call(arguments)));
|
||||
}
|
||||
};
|
||||
|
||||
// instantiate RNG. use the default seed, which is current time.
|
||||
Meteor.random = new Meteor._Alea();
|
||||
|
||||
Reference in New Issue
Block a user