adds saucelabs integration to unit tests
This commit is contained in:
parent
c8e0d917f7
commit
6a1ab4e39f
6 changed files with 158 additions and 6 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) {
|
||||
|
|
|
|||
|
|
@ -1575,7 +1575,15 @@ function testMithril(mock) {
|
|||
|
||||
}
|
||||
|
||||
//mocks
|
||||
testMithril(mock.window)
|
||||
//test reporting for saucelabs
|
||||
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)});
|
||||
|
|
@ -1,7 +1,34 @@
|
|||
function test(condition) {
|
||||
var duration = 0;
|
||||
var start = 0;
|
||||
var result = true;
|
||||
if (performance.now) {
|
||||
start = performance.now();
|
||||
}
|
||||
try {if (!condition()) throw new Error}
|
||||
catch (e) {console.error(e);test.failures.push(condition)}
|
||||
catch (e) {result = false;console.error(e);test.failures.push(condition)}
|
||||
if (performance.now) {
|
||||
duration = performance.now() - start;
|
||||
}
|
||||
|
||||
test.total++
|
||||
|
||||
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