-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
_boot.ts
77 lines (66 loc) · 2.24 KB
/
_boot.ts
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
const ex = require('@excalibur');
ex.Flags.enable('suppress-obsolete-message');
const testsContext = require.context('.', true, /Spec$/);
testsContext.keys().forEach(testsContext);
// ensure consistent toEqualImage() resolution when running on hidpi displays
window.devicePixelRatio = 1;
const MemoryReporter = {
previousMemory: (window.performance as any).memory,
largeMemory: [],
jasmineStarted: function(suiteInfo) {
this.previousMemory = (window.performance as any).memory;
},
specDone: function(result) {
const currentMemory = (window.performance as any).memory;
const megabytes = (currentMemory.usedJSHeapSize - this.previousMemory.usedJSHeapSize) * 0.000001;
if (megabytes > 1) {
const message = `Spec ${result.fullName} MB: ${megabytes}`;
this.largeMemory.push({size: megabytes, message});
}
this.previousMemory = currentMemory;
},
jasmineDone: function(result) {
this.largeMemory.sort((a, b) => {
return b.size - a.size;
});
for (const test of this.largeMemory.slice(0, 20)){
console.log(test.message); // eslint-disable-line
}
}
};
const EngineReporter = {
currentEngines: ex.Engine.InstanceCount,
leaks: [],
specDone: function(result) {
if (this.currentEngines < ex.Engine.InstanceCount) {
// const message = `Spec ${result.fullName} Engine increased: ${ex.Engine.InstanceCount}`;
// console.log(message);
this.leaks.push(result.fullName);
}
this.currentEngines = ex.Engine.InstanceCount;
},
jasmineDone: function(result) {
let leakString = '============ Engine leaks ==================\n';
for (const leak of this.leaks){
leakString += leak + '\n';
}
console.log(leakString); // eslint-disable-line
}
};
const TimeoutSpecReporter = {
specs: {},
specStarted: function(result) {
this.specs[result.fullName] = Date.now();
setTimeout(() => {
if (this.specs[result.fullName]) {
console.log('Possible timeout:' + result.fullName); // eslint-disable-line
}
}, 5000);
},
specDone: function(result) {
delete this.specs[result.fullName];
}
};
// jasmine.getEnv().addReporter(MemoryReporter);
jasmine.getEnv().addReporter(TimeoutSpecReporter);
jasmine.getEnv().addReporter(EngineReporter);