forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiWatching.unittest.js
61 lines (50 loc) · 1.45 KB
/
MultiWatching.unittest.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
"use strict";
const Tapable = require("tapable");
const should = require("should");
const sinon = require("sinon");
const MultiWatching = require("../lib/MultiWatching");
const createWatching = function() {
return {
invalidate: sinon.spy(),
close: sinon.spy()
};
};
const createCompiler = () => {
const compiler = {
_plugins: {}
};
Tapable.mixin(compiler);
return compiler;
};
describe("MultiWatching", () => {
let watchings, compiler, myMultiWatching;
beforeEach(() => {
watchings = [createWatching(), createWatching()];
compiler = createCompiler();
myMultiWatching = new MultiWatching(watchings, compiler);
});
describe("invalidate", () => {
beforeEach(() => myMultiWatching.invalidate());
it("invalidates each watching", () => {
watchings[0].invalidate.callCount.should.be.exactly(1);
watchings[1].invalidate.callCount.should.be.exactly(1);
});
});
describe("close", () => {
let callback;
const callClosedFinishedCallback = (watching) => watching.close.getCall(0).args[0]();
beforeEach(() => {
callback = sinon.spy();
myMultiWatching.close(callback);
});
it("closes each watching", () => {
watchings[0].close.callCount.should.be.exactly(1);
watchings[1].close.callCount.should.be.exactly(1);
});
it("calls callback after each watching has closed", () => {
callClosedFinishedCallback(watchings[0]);
callClosedFinishedCallback(watchings[1]);
callback.callCount.should.be.exactly(1);
});
});
});