Skip to content

Commit 814937b

Browse files
committed
Specing up.
1 parent 8b4f2ff commit 814937b

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

src/hooks/spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Context / Hooks', () => {
6060
it('Register sub process as ref entry under root process', () => {
6161
expect(executionMap.size).toEqual(2);
6262

63-
expect(executionMap.get(childAsyncId)).toEqual({
63+
expect(executionMap.get(childAsyncId)).toMatchObject({
6464
ref: triggerAsyncId
6565
});
6666
});
@@ -76,7 +76,7 @@ describe('Context / Hooks', () => {
7676
const nestedChildAsyncId = await spawn(childAsyncId);
7777

7878
expect(executionMap.size).toEqual(3);
79-
expect(executionMap.get(nestedChildAsyncId)).toEqual({
79+
expect(executionMap.get(nestedChildAsyncId)).toMatchObject({
8080
ref: triggerAsyncId
8181
});
8282

src/lib/spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const lib = require ('.');
2+
const Context = require('../');
23

34
describe('Lib', () => {
45
describe('isProduction', () => {
@@ -32,4 +33,55 @@ describe('Lib', () => {
3233
expect(lib.isUndefined(val)).toBeTruthy();
3334
});
3435
});
36+
37+
describe('monitorMap', () => {
38+
describe('When no context is open', () => {
39+
let report;
40+
beforeEach(() => {
41+
report = Context.monitor();
42+
});
43+
it('Returns empty usage', () => {
44+
expect(report.size).toEqual(0);
45+
});
46+
47+
it('Return empty array entries', () => {
48+
expect(Array.isArray(report.entries)).toBeTruthy();
49+
expect(report.entries).toHaveLength(0);
50+
});
51+
});
52+
53+
describe('When context is created', () => {
54+
const contextAware = (fn) => {
55+
Context.create({ value: true });
56+
fn();
57+
};
58+
59+
const spwan = () => new Promise((resolve) => setTimeout(resolve, 100));
60+
61+
describe('When a single process is present', () => {
62+
it('Reports with empty usage', () => {
63+
contextAware(() => {
64+
const report = Context.monitor();
65+
66+
expect(report.size).toEqual(1);
67+
expect(report.entries).toHaveLength(1);
68+
expect(report.entries[0].children).toHaveLength(0);
69+
});
70+
});
71+
});
72+
73+
describe('When sub process is present', () => {
74+
it('Reports root context entries', (done) => {
75+
contextAware(() => {
76+
spwan();
77+
const report = Context.monitor();
78+
79+
expect(report.size > 0).toBeTruthy();
80+
expect(report.entries.length > 0).toBeTruthy();
81+
done()
82+
});
83+
});
84+
});
85+
});
86+
});
3587
});

src/spec.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,4 @@ describe('Context', () => {
189189
});
190190
});
191191
});
192-
193-
describe('Monitor', () => {
194-
describe('When no context is open', () => {
195-
it('Returns empty usage', (done) => {
196-
console.log(Context.monitor())
197-
198-
setTimeout(() => console.log(Context.monitor()), 1000)
199-
setTimeout(() => console.log(Context.monitor()), 3000)
200-
setTimeout(() => {
201-
console.log(Context.monitor())
202-
done();
203-
}, 5000)
204-
205-
});
206-
});
207-
});
208192
});

0 commit comments

Comments
 (0)