forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotUpdateChunkTemplate.test.js
70 lines (60 loc) · 1.94 KB
/
HotUpdateChunkTemplate.test.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
62
63
64
65
66
67
68
69
70
"use strict";
const should = require("should");
const sinon = require("sinon");
const HotUpdateChunkTemplate = require("../lib/HotUpdateChunkTemplate");
describe("HotUpdateChunkTemplate", () => {
let env;
beforeEach(() => {
env = {
myHotUpdateChunkTemplate: new HotUpdateChunkTemplate({})
};
});
describe("render", () => {
beforeEach(() => {
env.renderContext = {
renderChunkModules: sinon.spy(),
applyPluginsWaterfall: sinon.spy()
};
const renderArguments = [
"id", ["module1", "module2"],
["module3", "module4"],
{},
"moduleTemplate", ["template1"]
];
env.myHotUpdateChunkTemplate.render.apply(env.renderContext, renderArguments);
env.pluginsCall = env.renderContext.applyPluginsWaterfall;
});
it("renders chunk modules", () => {
env.renderContext.renderChunkModules.callCount.should.be.exactly(1);
});
it("applies modules plugins", () => {
env.pluginsCall.callCount.should.be.exactly(2);
env.pluginsCall.firstCall.args[0].should.be.exactly("modules");
});
it("applies render plugins", () => {
env.pluginsCall.callCount.should.be.exactly(2);
env.pluginsCall.secondCall.args[0].should.be.exactly("render");
});
});
describe("updateHash", () => {
beforeEach(() => {
env.hash = {
update: sinon.spy()
};
env.updateHashContext = {
applyPlugins: sinon.spy()
};
env.myHotUpdateChunkTemplate.updateHash.call(env.updateHashContext, env.hash);
});
it("updates hash", () => {
env.hash.update.callCount.should.be.exactly(2);
env.hash.update.firstCall.args[0].should.be.exactly("HotUpdateChunkTemplate");
env.hash.update.secondCall.args[0].should.be.exactly("1");
});
it("applies hash plugin", () => {
env.updateHashContext.applyPlugins.callCount.should.be.exactly(1);
env.updateHashContext.applyPlugins.firstCall.args[0].should.be.exactly("hash");
env.updateHashContext.applyPlugins.firstCall.args[1].should.be.exactly(env.hash);
});
});
});