Merge branch 'next' into promises
Conflicts: mithril.js
This commit is contained in:
commit
7639444aa1
280 changed files with 12495 additions and 1568 deletions
|
|
@ -1,3 +1,31 @@
|
|||
//saucelabs reporting; see https://github.com/axemclion/grunt-saucelabs#test-result-details-with-qunit
|
||||
var log = [];
|
||||
var testName;
|
||||
QUnit.done(function (test_results) {
|
||||
var tests = [];
|
||||
for(var i = 0, len = log.length; i < len; i++) {
|
||||
var details = log[i];
|
||||
tests.push({
|
||||
name: details.name,
|
||||
result: details.result,
|
||||
expected: details.expected,
|
||||
actual: details.actual,
|
||||
source: details.source
|
||||
});
|
||||
}
|
||||
test_results.tests = tests;
|
||||
|
||||
window.global_test_results = test_results;
|
||||
});
|
||||
QUnit.testStart(function(testDetails){
|
||||
QUnit.log(function(details){
|
||||
if (!details.result) {
|
||||
details.name = testDetails.name;
|
||||
log.push(details);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//qunit doesn't support Function.prototype.bind...
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function (oThis) {
|
||||
|
|
|
|||
|
|
@ -685,6 +685,27 @@ function testMithril(mock) {
|
|||
m.render(root, m("ul", [m("li", {key: 0}), m("li", {key: 1}), m("li", {key: 2}), m("li", {key: 3}), m("li", {key: 4}), m("li", {key: 5})]))
|
||||
return root.childNodes[0].childNodes.map(function(n) {return n.key}).join("") == "012345"
|
||||
})
|
||||
test(function() {
|
||||
//https://github.com/lhorie/mithril.js/issues/157
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("input", {value: "a"}))
|
||||
m.render(root, m("input", {value: "aa"}))
|
||||
return root.childNodes[0].childNodes.length == 0
|
||||
})
|
||||
test(function() {
|
||||
//https://github.com/lhorie/mithril.js/issues/157
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("br", {class: "a"}))
|
||||
m.render(root, m("br", {class: "aa"}))
|
||||
return root.childNodes[0].childNodes.length == 0
|
||||
})
|
||||
test(function() {
|
||||
//https://github.com/lhorie/mithril.js/issues/194
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li", {key: 0}), m("li", {key: 1}), m("li", {key: 2}), m("li", {key: 3}), m("li", {key: 4}), m("li", {key: 5})]))
|
||||
m.render(root, m("ul", [m("li", {key: 0}), m("li", {key: 1}), m("li", {key: 2}), m("li", {key: 4}), m("li", {key: 5})]))
|
||||
return root.childNodes[0].childNodes.map(function(n) {return n.key}).join("") == "01245"
|
||||
})
|
||||
//end m.render
|
||||
|
||||
//m.redraw
|
||||
|
|
@ -714,12 +735,13 @@ function testMithril(mock) {
|
|||
}
|
||||
})
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
m.redraw()
|
||||
m.redraw()
|
||||
m.redraw() //should run synchronously
|
||||
|
||||
m.redraw() //rest should run asynchronously since they're spamming
|
||||
m.redraw()
|
||||
m.redraw()
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return count === 2
|
||||
return count === 3
|
||||
})
|
||||
|
||||
//m.route
|
||||
|
|
@ -1276,6 +1298,101 @@ function testMithril(mock) {
|
|||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return unloaded == 1
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
var strategy
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/foo1", {
|
||||
"/foo1": {
|
||||
controller: function() {
|
||||
strategy = m.redraw.strategy()
|
||||
m.redraw.strategy("none")
|
||||
},
|
||||
view: function() {
|
||||
return m("div");
|
||||
}
|
||||
}
|
||||
})
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return strategy == "all" && root.childNodes.length == 0
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
var strategy, count = 0
|
||||
var config = function(el, init) {if (!init) count++}
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/foo1", {
|
||||
"/foo1": {
|
||||
controller: function() {},
|
||||
view: function() {
|
||||
return m("div", {config: config});
|
||||
}
|
||||
},
|
||||
"/bar1": {
|
||||
controller: function() {
|
||||
strategy = m.redraw.strategy()
|
||||
m.redraw.strategy("redraw")
|
||||
},
|
||||
view: function() {
|
||||
return m("div", {config: config});
|
||||
}
|
||||
},
|
||||
})
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
m.route("/bar1")
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return strategy == "all" && count == 1
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
var strategy
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/foo1", {
|
||||
"/foo1": {
|
||||
controller: function() {this.number = 1},
|
||||
view: function(ctrl) {
|
||||
return m("div", {onclick: function() {
|
||||
strategy = m.redraw.strategy()
|
||||
ctrl.number++
|
||||
m.redraw.strategy("none")
|
||||
}}, ctrl.number);
|
||||
}
|
||||
}
|
||||
})
|
||||
root.childNodes[0].onclick({})
|
||||
return strategy == "diff" && root.childNodes[0].childNodes[0].nodeValue == "1"
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
var count = 0
|
||||
var config = function(el, init ) {if (!init) count++}
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/foo1", {
|
||||
"/foo1": {
|
||||
controller: function() {},
|
||||
view: function(ctrl) {
|
||||
return m("div", {config: config, onclick: function() {
|
||||
m.redraw.strategy("all")
|
||||
}});
|
||||
}
|
||||
}
|
||||
})
|
||||
root.childNodes[0].onclick({})
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return count == 2
|
||||
})
|
||||
//end m.route
|
||||
|
||||
//m.prop
|
||||
|
|
@ -1516,6 +1633,11 @@ function testMithril(mock) {
|
|||
deferred1.resolve("test")
|
||||
return value[0] === "test" && value[1] === "foo"
|
||||
})
|
||||
test(function() {
|
||||
var value = 1
|
||||
m.sync([]).then(function() {value = 2})
|
||||
return value == 2
|
||||
})
|
||||
|
||||
//m.startComputation/m.endComputation
|
||||
test(function() {
|
||||
|
|
@ -1574,7 +1696,17 @@ function testMithril(mock) {
|
|||
|
||||
}
|
||||
|
||||
//mocks
|
||||
testMithril(mock.window)
|
||||
//test reporting for saucelabs
|
||||
if (typeof window != "undefined") {
|
||||
window.global_test_results = {
|
||||
tests: [],
|
||||
duration: 0,
|
||||
passed: 0,
|
||||
failed: 0
|
||||
};
|
||||
}
|
||||
|
||||
test.print(console.log)
|
||||
//mock
|
||||
testMithril(mock.window);
|
||||
|
||||
test.print(function(value) {console.log(value)})
|
||||
|
|
|
|||
|
|
@ -72,7 +72,11 @@ mock.window = new function() {
|
|||
}
|
||||
window.scrollTo = function() {}
|
||||
window.cancelAnimationFrame = function() {}
|
||||
window.requestAnimationFrame = function(callback) {window.requestAnimationFrame.$callback = callback}
|
||||
window.requestAnimationFrame = function(callback) {
|
||||
window.requestAnimationFrame.$callback = callback
|
||||
return window.requestAnimationFrame.$id++
|
||||
}
|
||||
window.requestAnimationFrame.$id = 1
|
||||
window.requestAnimationFrame.$resolve = function() {
|
||||
if (window.requestAnimationFrame.$callback) window.requestAnimationFrame.$callback()
|
||||
window.requestAnimationFrame.$callback = null
|
||||
|
|
|
|||
|
|
@ -1,7 +1,37 @@
|
|||
function test(condition) {
|
||||
try {if (!condition()) throw new Error}
|
||||
catch (e) {console.error(e);test.failures.push(condition)}
|
||||
var duration = 0;
|
||||
var start = 0;
|
||||
var result = true;
|
||||
test.total++
|
||||
|
||||
if (typeof window != "undefined") {
|
||||
if (typeof performance != "undefined") {
|
||||
start = performance.now();
|
||||
}
|
||||
try {if (!condition()) throw new Error}
|
||||
catch (e) {result = false;console.error(e);test.failures.push(condition)}
|
||||
if (typeof performance != "undefined") {
|
||||
duration = performance.now() - start;
|
||||
}
|
||||
|
||||
|
||||
test_obj = {
|
||||
name: "" + test.total,
|
||||
result: result,
|
||||
duration: duration
|
||||
}
|
||||
if (!result) {
|
||||
message: "failed: " + condition,
|
||||
window.global_test_results.tests.push(test_obj)
|
||||
}
|
||||
|
||||
window.global_test_results.duration += duration;
|
||||
if (result) {
|
||||
window.global_test_results.passed++;
|
||||
} else {
|
||||
window.global_test_results.failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
test.total = 0
|
||||
test.failures = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue