UNPKG

2.65 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22'use strict';
23
24var TestReporter = function TestReporter(browser, appPath) {
25 function send(action, json, cb) {
26 var r = new XMLHttpRequest();
27 r.open('POST', action, true);
28 r.setRequestHeader('Content-Type', 'application/json');
29 r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
30 if (r.readyState === 4) {
31 if (r.status !== 200) {
32 send(action, json, cb);
33 } else {
34 if (cb) {
35 cb();
36 }
37 }
38 }
39 };
40 json['browser'] = browser;
41 r.send(JSON.stringify(json));
42 }
43 function sendInfo(message) {
44 send('/info', { message: message });
45 }
46 function sendResult(status, description, error) {
47 var message = {
48 status: status,
49 description: description
50 };
51 if (typeof error !== 'undefined') {
52 message['error'] = error;
53 }
54 send('/submit_task_results', message);
55 }
56 function sendQuitRequest() {
57 send('/tellMeToQuit?path=' + escape(appPath), {});
58 }
59 this.now = function () {
60 return new Date().getTime();
61 };
62 this.jasmineStarted = function (suiteInfo) {
63 this.runnerStartTime = this.now();
64 sendInfo('Started unit tests for ' + browser + '.');
65 };
66 this.suiteStarted = function (result) {};
67 this.specStarted = function (result) {};
68 this.specDone = function (result) {
69 if (result.failedExpectations.length === 0) {
70 sendResult('TEST-PASSED', result.description);
71 } else {
72 var failedMessages = '';
73 var items = result.failedExpectations;
74 for (var i = 0, ii = items.length; i < ii; i++) {
75 failedMessages += items[i].message + ' ';
76 }
77 sendResult('TEST-UNEXPECTED-FAIL', result.description, failedMessages);
78 }
79 };
80 this.suiteDone = function (result) {};
81 this.jasmineDone = function () {
82 setTimeout(sendQuitRequest, 500);
83 };
84};
\No newline at end of file