1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | var 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 |