pdf.js/test/unit/testreporter.js

78 lines
2.0 KiB
JavaScript
Raw Normal View History

2014-07-19 23:41:07 +09:00
'use strict';
// eslint-disable-next-line no-unused-vars
2014-07-19 23:41:07 +09:00
var TestReporter = function(browser, appPath) {
2014-04-12 03:02:41 +09:00
function send(action, json, cb) {
2012-04-20 04:32:24 +09:00
var r = new XMLHttpRequest();
// (The POST URI is ignored atm.)
r.open('POST', action, true);
r.setRequestHeader('Content-Type', 'application/json');
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
if (r.readyState === 4) {
2012-04-20 04:32:24 +09:00
// Retry until successful
if (r.status !== 200) {
2014-04-12 03:02:41 +09:00
send(action, json, cb);
} else {
if (cb) {
cb();
}
}
2012-04-20 04:32:24 +09:00
}
};
json['browser'] = browser;
r.send(JSON.stringify(json));
}
function sendInfo(message) {
send('/info', {message: message});
}
function sendResult(status, description, error) {
var message = {
status: status,
description: description
};
if (typeof error !== 'undefined') {
2012-04-20 04:32:24 +09:00
message['error'] = error;
}
2012-04-20 04:32:24 +09:00
send('/submit_task_results', message);
}
function sendQuitRequest() {
2015-04-04 03:17:20 +09:00
send('/tellMeToQuit?path=' + escape(appPath), {});
2012-04-20 04:32:24 +09:00
}
this.now = function() {
return new Date().getTime();
};
2016-03-29 23:34:13 +09:00
this.jasmineStarted = function(suiteInfo) {
2012-04-20 04:32:24 +09:00
this.runnerStartTime = this.now();
sendInfo('Started unit tests for ' + browser + '.');
};
2016-03-29 23:34:13 +09:00
this.suiteStarted = function(result) { };
2012-04-20 04:32:24 +09:00
2016-03-29 23:34:13 +09:00
this.specStarted = function(result) { };
this.specDone = function(result) {
if (result.failedExpectations.length === 0) {
sendResult('TEST-PASSED', result.description);
2012-04-20 04:32:24 +09:00
} else {
var failedMessages = '';
2016-03-29 23:34:13 +09:00
var items = result.failedExpectations;
for (var i = 0, ii = items.length; i < ii; i++) {
2016-03-29 23:34:13 +09:00
failedMessages += items[i].message + ' ';
}
2016-03-29 23:34:13 +09:00
sendResult('TEST-UNEXPECTED-FAIL', result.description, failedMessages);
2012-04-20 04:32:24 +09:00
}
};
2016-03-29 23:34:13 +09:00
this.suiteDone = function(result) { };
2012-04-20 04:32:24 +09:00
2016-03-29 23:34:13 +09:00
this.jasmineDone = function() {
2012-04-20 06:19:08 +09:00
// Give the test.py some time process any queued up requests
setTimeout(sendQuitRequest, 500);
2012-04-20 04:32:24 +09:00
};
};