-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspawn.test.js
103 lines (87 loc) · 3.4 KB
/
spawn.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
const debugFabAPI = require('../lib');
const origDebug = debugFabAPI();
origDebug.save('root*');
origDebug.enable(origDebug.load());
const debug = debugFabAPI.spawnable('root', origDebug);
describe('spawn', () => {
describe('namespaces same level identical', () => {
it('2 off', () => {
const child1 = debug.spawn('child1');
const child2 = debug.spawn('child1');
expect(child1).toEqual(child2);
expect(child1.namespace).toEqual(child2.namespace);
expect(child1.namespace).toEqual('root:child1');
});
it('grandchildren', () => {
const child1 = debug.spawn('child1').spawn('grand');
const child2 = debug.spawn('child1').spawn('grand');
expect(child1).toEqual(child2);
expect(child1.namespace).toEqual(child2.namespace);
expect(child1.namespace).toEqual('root:child1:grand');
});
it('great', () => {
const child1 = debug
.spawn('child1')
.spawn('grand')
.spawn('great');
const child2 = debug
.spawn('child1')
.spawn('grand')
.spawn('great');
expect(child1).toEqual(child2);
expect(child1.namespace).toEqual(child2.namespace);
expect(child1.namespace).toEqual('root:child1:grand:great');
});
});
describe('namespaces are unique', () => {
it('1 off', () => {
const child = debug.spawn('child1');
expect(child.namespace).not.toEqual(debug.namespace);
expect(debug.namespace).toEqual('root');
expect(child.namespace).toEqual('root:child1');
});
it('2 off', () => {
const child1 = debug.spawn('child1');
const child2 = debug.spawn('child2');
expect(child1).not.toEqual(child2);
expect(child1.namespace).not.toEqual(child2.namespace);
expect(child1.namespace).toEqual('root:child1');
expect(child2.namespace).toEqual('root:child2');
});
it('grandchildren', () => {
const child1 = debug.spawn('child1').spawn('grand');
const child2 = debug.spawn('child2').spawn('grand');
// resolved by noop scope level to be new on each spawn
expect(child1).not.toEqual(child2);
expect(child1.namespace).not.toEqual(child2.namespace);
// resolved by not memoizeing spawn as `grand`
// above matches for both child1 and child2 and memoizee has child1 cached
expect(child1.namespace).toEqual('root:child1:grand');
expect(child2.namespace).toEqual('root:child2:grand');
});
it('grandchildren', () => {
const child1 = debug.spawn('child1').spawn('grand');
const child2 = debug.spawn('child2').spawn('grand1');
expect(child1).not.toEqual(child2);
expect(child1.namespace).not.toEqual(child2.namespace);
// resolved by not memoizeing spawn as `grand`
// above matches for both child1 and child2 and memoizee has child1 cached
expect(child1.namespace).toEqual('root:child1:grand');
expect(child2.namespace).toEqual('root:child2:grand1');
});
it('great grandchildren', () => {
const child1 = debug
.spawn('child1')
.spawn('grand')
.spawn('great');
const child2 = debug
.spawn('child2')
.spawn('grand')
.spawn('great');
expect(child1).not.toEqual(child2);
expect(child1.namespace).not.toEqual(child2.namespace);
expect(child1.namespace).toEqual('root:child1:grand:great');
expect(child2.namespace).toEqual('root:child2:grand:great');
});
});
});