This repository has been archived by the owner on Oct 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
report.js
76 lines (72 loc) · 1.99 KB
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
if (! window.jscoverage_report) {
window.jscoverage_report = function jscoverage_report(dir) {
var createRequest = function () {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
};
var pad = function (s) {
return '0000'.substr(s.length) + s;
};
var quote = function (s) {
return '"' + s.replace(/[\u0000-\u001f"\\\u007f-\uffff]/g, function (c) {
switch (c) {
case '\b':
return '\\b';
case '\f':
return '\\f';
case '\n':
return '\\n';
case '\r':
return '\\r';
case '\t':
return '\\t';
// IE doesn't support this
/*
case '\v':
return '\\v';
*/
case '"':
return '\\"';
case '\\':
return '\\\\';
default:
return '\\u' + pad(c.charCodeAt(0).toString(16));
}
}) + '"';
};
var json = [];
for (var file in top._$jscoverage) {
var coverage = top._$jscoverage[file];
var array = [];
var length = coverage.length;
for (var line = 0; line < length; line++) {
var value = coverage[line];
if (value === undefined || value === null) {
value = 'null';
}
array.push(value);
}
json.push(quote(file) + ':[' + array.join(',') + ']');
}
json = '{' + json.join(',') + '}';
var request = createRequest();
var url = '/jscoverage-store';
if (dir) {
url += '/' + encodeURIComponent(dir);
}
request.open('POST', url, false);
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Content-Length', json.length.toString());
request.send(json);
if (request.status === 200 || request.status === 201 || request.status === 204) {
return request.responseText;
}
else {
throw request.status;
}
};
}