fixes non-browser-based tests

This commit is contained in:
Jim Witschey 2014-07-28 14:06:14 -04:00
parent 6a1ab4e39f
commit 3160e696df
3 changed files with 79 additions and 34 deletions

View file

@ -674,9 +674,39 @@ if (typeof define == "function" && define.amd) define(function() {return m})
;;; ;;;
function test(condition) { function test(condition) {
try {if (!condition()) throw new Error} var duration = 0;
catch (e) {console.error(e);test.failures.push(condition)} var start = 0;
var result = true;
test.total++ 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.total = 0
test.failures = [] test.failures = []
@ -2381,7 +2411,17 @@ function testMithril(mock) {
} }
//mocks //test reporting for saucelabs
testMithril(mock.window) 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)});

View file

@ -1576,12 +1576,14 @@ function testMithril(mock) {
} }
//test reporting for saucelabs //test reporting for saucelabs
window.global_test_results = { if (typeof window != "undefined") {
tests: [], window.global_test_results = {
duration: 0, tests: [],
passed: 0, duration: 0,
failed: 0 passed: 0,
}; failed: 0
};
}
//mock //mock
testMithril(mock.window); testMithril(mock.window);

View file

@ -2,32 +2,35 @@ function test(condition) {
var duration = 0; var duration = 0;
var start = 0; var start = 0;
var result = true; var result = true;
if (performance.now) {
start = performance.now();
}
try {if (!condition()) throw new Error}
catch (e) {result = false;console.error(e);test.failures.push(condition)}
if (performance.now) {
duration = performance.now() - start;
}
test.total++ test.total++
test_obj = { if (typeof window != "undefined") {
name: "" + test.total, if (typeof performance != "undefined") {
result: result, start = performance.now();
duration: duration }
} try {if (!condition()) throw new Error}
if (!result) { catch (e) {result = false;console.error(e);test.failures.push(condition)}
message: "failed: " + condition, if (typeof performance != "undefined") {
window.global_test_results.tests.push(test_obj) duration = performance.now() - start;
} }
window.global_test_results.duration += duration;
if (result) { test_obj = {
window.global_test_results.passed++; name: "" + test.total,
} else { result: result,
window.global_test_results.failed++; 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.total = 0