-
Notifications
You must be signed in to change notification settings - Fork 13
/
adapter.js
59 lines (52 loc) · 1.54 KB
/
adapter.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
var createStartFn = function(tc, env) {
var numResults = 0;
var res = [];
var startTime = new Date().getTime();
var parse_stream = tapParser(function(results) {
tc.info({ total: numResults });
for (var i = 0, len = res.length; i < len; i++) {
tc.result(res[i]);
}
tc.complete({
coverage: window.__coverage__
});
}).on('assert', function(assertion) {
numResults++;
res.push({
description: assertion.name,
success: assertion.ok,
log: [],
suite: [],
time: new Date().getTime() - startTime
});
});
// this part lifted from zuul
// https://github.com/defunctzombie/zuul/blob/master/frameworks/tape/client.js
var originalLog = console.log;
console.log = function (msg) {
if (!parse_stream.writable) return;
var index = 1;
var args = arguments;
if (typeof msg === 'string') {
msg = msg.replace(/(^|[^%])%[sd]/g, function (_, s) {
return s + args[index++];
});
}
for (var i = index; i < args.length; i++) {
msg += ' ' + args[i];
}
parse_stream.write(msg + '\n');
if (/^# fail\s*\d+$/.test(msg) || /^# ok/.test(msg)) {
// reset console.log to make sure this stream doesn't get a write error.
console.log = originalLog;
parse_stream.end();
}
if (typeof originalLog === 'function') {
return originalLog.apply(this, arguments);
}
else if (originalLog) return originalLog(arguments[0]);
};
return function(config) {
};
};
window.__karma__.start = createStartFn(window.__karma__);