|
| 1 | +var expect = require('chai').expect; |
| 2 | +var debugFabAPI = require('../..'); |
| 3 | + |
| 4 | +var origDebug = debugFabAPI(); |
| 5 | +origDebug.save('root*'); |
| 6 | +origDebug.enable(origDebug.load()); |
| 7 | + |
| 8 | +var debug = debugFabAPI.spawnable('root', origDebug); |
| 9 | + |
| 10 | +describe('spawn', function() { |
| 11 | + describe('namespaces are unique', function() { |
| 12 | + it('1 off', function() { |
| 13 | + var child = debug.spawn('child1'); |
| 14 | + expect(child.namespace).to.not.eql(debug.namespace); |
| 15 | + expect(debug.namespace).to.eql('root'); |
| 16 | + expect(child.namespace).to.eql('root:child1'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('2 off', function() { |
| 20 | + var child1 = debug.spawn('child1'); |
| 21 | + var child2 = debug.spawn('child2'); |
| 22 | + |
| 23 | + expect(child1).to.not.eql(child2); |
| 24 | + expect(child1.namespace).to.not.eql(child2.namespace); |
| 25 | + expect(child1.namespace).to.eql('root:child1'); |
| 26 | + expect(child2.namespace).to.eql('root:child2'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('grandchildren', function() { |
| 30 | + var child1 = debug.spawn('child1').spawn('grand'); |
| 31 | + var child2 = debug.spawn('child2').spawn('grand'); |
| 32 | + |
| 33 | + expect(child1).to.not.eql(child2); // resolved by noop scope level to be new on each spawn |
| 34 | + expect(child1.namespace).to.not.eql(child2.namespace); |
| 35 | + // resolved by not memoizeing spawn as `grand` |
| 36 | + // above matches for both child1 and child2 and memoizee has child1 cached |
| 37 | + expect(child1.namespace).to.eql('root:child1:grand'); |
| 38 | + expect(child2.namespace).to.eql('root:child2:grand'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('grandchildren', function() { |
| 42 | + var child1 = debug.spawn('child1').spawn('grand'); |
| 43 | + var child2 = debug.spawn('child2').spawn('grand1'); |
| 44 | + |
| 45 | + expect(child1).to.not.eql(child2); |
| 46 | + expect(child1.namespace).to.not.eql(child2.namespace); |
| 47 | + // resolved by not memoizeing spawn as `grand` |
| 48 | + // above matches for both child1 and child2 and memoizee has child1 cached |
| 49 | + expect(child1.namespace).to.eql('root:child1:grand'); |
| 50 | + expect(child2.namespace).to.eql('root:child2:grand1'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('great grandchildren', function() { |
| 54 | + var child1 = debug.spawn('child1').spawn('grand').spawn('great'); |
| 55 | + var child2 = debug.spawn('child2').spawn('grand').spawn('great');; |
| 56 | + |
| 57 | + expect(child1).to.not.eql(child2); |
| 58 | + expect(child1.namespace).to.not.eql(child2.namespace); |
| 59 | + expect(child1.namespace).to.eql('root:child1:grand:great'); |
| 60 | + expect(child2.namespace).to.eql('root:child2:grand:great'); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments