UNPKG

3.1 kBJavaScriptView Raw
1var fu = require('../lib/fileUtil'),
2 WatchManager = require('../lib/watch-manager'),
3 watcher = require('../lib/util/watcher');
4
5describe('watch-manager', function() {
6 var watch;
7 beforeEach(function() {
8 watch = new WatchManager();
9 this.stub(watch, '_exec');
10 watch.queue.should.be.empty;
11 });
12
13 describe('#pushChange', function() {
14 it('should track changes', function() {
15 watch.queue.should.be.empty;
16 watch.pushChange({'foo': 'bar'});
17 watch.pushChange({'bar': 'bar'});
18 watch.queue.should.eql([{'foo': 'bar'}, {'bar': 'bar'}]);
19 });
20
21 it('should reset on config changes', function() {
22 watch.pushChange({'foo': 'bar'});
23 watch.pushChange({'config': true});
24 watch.queue.should.eql([{'config': true}]);
25 });
26
27 it('should ignore changes when config is pending', function() {
28 watch.pushChange({'config': true});
29 watch.pushChange({'foo': 'bar'});
30 watch.queue.should.eql([{'config': true}]);
31 });
32 it('should ignore changes when on the same file', function() {
33 watch.pushChange({'fileName': 'foo'});
34 watch.pushChange({'fileName': 'foo'});
35 watch.queue.should.eql([{'fileName': 'foo'}]);
36 });
37
38 describe('fileCache', function() {
39 beforeEach(function() {
40 this.stub(fu, 'resetCache');
41 });
42
43 it('should reset fileCache on change', function() {
44 watch.pushChange({sourceChange: 'foo'});
45 fu.resetCache.callCount.should.equal(1);
46 fu.resetCache.calledWithExactly('foo').should.be.true;
47 });
48 it('should reset entire fileCache on config change', function() {
49 watch.pushChange({config: true});
50 fu.resetCache.callCount.should.equal(1);
51 fu.resetCache.calledWithExactly(undefined).should.be.true;
52 });
53 it('should reset parent fileCache on remove', function() {
54 watch.pushChange({sourceChange: 'foo/bar', type: 'remove'});
55 fu.resetCache.callCount.should.equal(2);
56 fu.resetCache.calledWithExactly('foo/bar').should.be.true;
57 fu.resetCache.calledWithExactly('foo').should.be.true;
58 });
59 it('should reset the file cache on ignored changes', function() {
60 watch.pushChange({'config': true});
61 watch.pushChange({sourceChange: 'bar'});
62 fu.resetCache.callCount.should.equal(2);
63 fu.resetCache.calledWithExactly(undefined).should.be.true;
64 fu.resetCache.calledWithExactly('bar').should.be.true;
65 });
66 });
67
68 it('should reset on config changes', function() {
69 this.stub(watch, 'reset');
70 watch.pushChange({config: true});
71 watch.reset.callCount.should.equal(1);
72 });
73 it('should begin exec', function() {
74 watch.pushChange({'config': true});
75 watch._exec.callCount.should.equal(1);
76 });
77 });
78
79 describe('#flushQueue', function() {
80 it('should execute callbacks on flushQueue', function() {
81 var stub = this.stub();
82 watch.pushChange({callback: stub});
83 watch.pushChange({callback: stub});
84 watch.flushQueue();
85 stub.callCount.should.equal(2);
86 });
87 });
88});