This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
instrumentation_header.js
63 lines (58 loc) · 2.71 KB
/
instrumentation_header.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
// Instrumentation Header
{
var _fs = require('fs');
var <%= instrumented.names.statement %>, <%= instrumented.names.expression %>, <%= instrumented.names.block %>;
var store = require('<%= coverageStorePath %>');
<%= instrumented.names.statement %> = function(i) {
var fd = store.register('<%= filename %>');
_fs.writeSync(fd, '{"statement": {"node": ' + i + '}},\n');
};
<%= instrumented.names.expression %> = function(i) {
var fd = store.register('<%= filename %>');
_fs.writeSync(fd, '{"expression": {"node": ' + i + '}},\n');
};
<%= instrumented.names.block %> = function(i) {
var fd = store.register('<%= filename %>');
_fs.writeSync(fd, '{"block": ' + i + '},\n');
};
<%= instrumented.names.intro %> = function(id, obj) {
// console.log('__intro: ', id, ', obj.__instrumented_miss: ', obj.__instrumented_miss, ', obj.length: ', obj.length);
(typeof obj === 'object' || typeof obj === 'function') &&
Object.defineProperty && Object.defineProperty(obj, '__instrumented_miss', {enumerable: false, writable: true});
obj.__instrumented_miss = obj.__instrumented_miss || [];
if ('undefined' !== typeof obj && null !== obj && 'undefined' !== typeof obj.__instrumented_miss) {
if (obj.length === 0) {
// console.log('interim miss: ', id);
obj.__instrumented_miss[id] = true;
} else {
obj.__instrumented_miss[id] = false;
}
}
return obj;
};
function isProbablyChainable(obj, id) {
return obj &&
obj.__instrumented_miss[id] !== undefined &&
'number' === typeof obj.length;
}
<%= instrumented.names.extro %> = function(id, obj) {
var fd = store.register('<%= filename %>');
// console.log('__extro: ', id, ', obj.__instrumented_miss: ', obj.__instrumented_miss, ', obj.length: ', obj.length);
if ('undefined' !== typeof obj && null !== obj && 'undefined' !== typeof obj.__instrumented_miss) {
if (isProbablyChainable(obj, id) && obj.length === 0 && obj.__instrumented_miss[id]) {
// if the call was not a "constructor" - i.e. it did not add things to the chainable
// and it did not return anything from the chainable, it is a miss
// console.log('miss: ', id);
} else {
_fs.writeSync(fd, '{"chain": {"node": ' + id + '}},\n');
}
obj.__instrumented_miss[id] = undefined;
} else {
_fs.writeSync(fd, '{"chain": {"node": ' + id + '}},\n');
}
return obj;
};
};
////////////////////////
// Instrumented Code
<%= source %>