-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlazyEval.test.js
149 lines (128 loc) · 3.14 KB
/
lazyEval.test.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const hook = require('hook-std');
const config = require('config');
const watchLeaks = require('./helpers/watchLeaks');
const debugFact = require('../lib')();
/* eslint-disable no-console */
const heapDiff = watchLeaks();
describe('lazyEval', () => {
let debug, unhook, date;
beforeEach(() => {
date = Date.now();
});
afterAll(() => {
const hde = heapDiff.end();
const { change } = hde;
change.details = null;
console.log(
JSON.stringify(
{
before: hde.before,
after: hde.after,
change,
},
null,
2
)
);
console.log(`lazyEval.test.js Total time: ${Date.now() - date}`);
});
describe('enabled', () => {
beforeEach(() => {
debugFact.save('enabled');
debugFact.enable(debugFact.load());
debug = debugFact('enabled');
// console.log(debug);
});
it('handles functions', (done) => {
unhook = hook.stderr((str) => {
expect(str.match(/crap/)).toBeTruthy();
expect(str.match(/enabled/)).toBeTruthy();
done();
});
debug(() => {
return 'crap';
});
unhook();
});
it('leak', () => {
// memory leak attempt
for (let i = 0; i < config.get('tests.leak.iterations'); i++) {
debug = debugFact('enabled');
leakTest(`leak${i}`);
}
function leakTest(name) {
debug(() => {
return name;
});
}
});
describe('normal', () => {
it('basic', (done) => {
unhook = hook.stderr((str) => {
expect(str).toMatch(/crap/);
expect(str).toMatch(/enabled/);
done();
});
debug('crap');
unhook();
});
it('formatter / multi arg', (done) => {
unhook = hook.stderr((str) => {
expect(str).toMatch(/test hi/);
expect(str).toMatch(/enabled/);
done();
});
debug('test %s', 'hi');
unhook();
});
});
describe('lazy', () => {
it('basic', (done) => {
unhook = hook.stderr((str) => {
expect(str).toMatch(/crap/);
expect(str).toMatch(/enabled/);
done();
});
debug(() => 'crap');
unhook();
});
it('formatter / multi arg', (done) => {
unhook = hook.stderr((str) => {
expect(str).toMatch(/test hi/);
expect(str).toMatch(/enabled/);
done();
});
debug(() => ['test %s', 'hi']);
unhook();
});
});
});
describe('disabled', () => {
beforeEach(() => {
debugFact.save(null);
debugFact.enable(debugFact.load());
debug = debugFact('disabled');
});
it('handles functions', () => {
let called = false;
unhook = hook.stderr(() => {
called = true;
});
debug(() => {
called = true;
return 'crap';
});
unhook();
expect(called).toEqual(false);
});
it('normal', () => {
let called = false;
unhook = hook.stderr(() => {
called = true;
});
debug('crap');
unhook();
expect(called).toEqual(false);
});
});
});