-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreporter.js
47 lines (39 loc) · 1.21 KB
/
reporter.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
/* global window */
// copied from browser-run
// changed xhr-write-stream to socket.io
require('source-map-support').install();
// delay window.close
var close = window.close;
// ['c' + 'lose'] is to bypass IE11 SCRIPT5045:
// Assignment to read-only properties is not allowed in strict mode
window['c' + 'lose'] = function () {
setTimeout(function () {
close.call(window);
}, 1000);
};
window.onerror = function (msg, file, line, column, err) {
if (err && msg.indexOf(err.stack) > -1) {
err.stack = err.stack + '\n at ' + file + ':' + line + ':' + column;
}
console.error(err && err.stack || err);
};
var io = require('socket.io-client')();
var console = window.console || {};
function patch(method) {
var old = console[method];
console[method] = function() {
const message = Array.prototype.slice.call(arguments, 0).join(' ');
if (message) io.emit(method, message);
if (old) old.apply(console, arguments);
};
}
var methods = ['log', 'error', 'warn', 'dir', 'debug', 'info', 'trace'];
var i;
for (i = 0; i < methods.length; i++) {
patch(methods[i]);
}
io.on('ask-coverage', function() {
if (window.__coverage__) {
io.emit('coverage', JSON.stringify(window.__coverage__));
}
});