|
1 | 1 | const lib = require ('.'); |
| 2 | +const Context = require('../'); |
2 | 3 |
|
3 | 4 | describe('Lib', () => { |
4 | 5 | describe('isProduction', () => { |
@@ -32,4 +33,55 @@ describe('Lib', () => { |
32 | 33 | expect(lib.isUndefined(val)).toBeTruthy(); |
33 | 34 | }); |
34 | 35 | }); |
| 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 | + }); |
35 | 87 | }); |
0 commit comments