forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChunk.unittest.js
166 lines (146 loc) · 4.66 KB
/
Chunk.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* globals describe, it, beforeEach */
"use strict";
const should = require("should");
const sinon = require("sinon");
const Chunk = require("../lib/Chunk");
describe("Chunk", () => {
let ChunkInstance;
beforeEach(() => ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test"));
it("should have debugId more than 999", () => should(ChunkInstance.debugId).be.above(999));
it("returns a string with modules information", () => should(ChunkInstance.toString()).be.exactly("Chunk[]"));
it("should have origins based in constructor information", () =>
should(ChunkInstance.origins[0]).be.eql({
module: "module-test",
loc: "loc-test",
name: "chunk-test"
}));
it("should not be the initial instance", () => should(ChunkInstance.isInitial()).be.false());
describe("entry", () => {
it("returns an error if get entry", () =>
should(() => {
ChunkInstance.entry;
}).throw("Chunk.entry was removed. Use hasRuntime()"));
it("returns an error if set an entry", () =>
should(() => {
ChunkInstance.entry = 10;
}).throw("Chunk.entry was removed. Use hasRuntime()"));
});
describe("initial", () => {
it("returns an error if get initial", () =>
should(() => {
ChunkInstance.initial;
}).throw("Chunk.initial was removed. Use isInitial()"));
it("returns an error if set an initial", () =>
should(() => {
ChunkInstance.initial = 10;
}).throw("Chunk.initial was removed. Use isInitial()"));
});
describe("hasRuntime", () => {
it("returns false", () => should(ChunkInstance.hasRuntime()).be.false());
});
describe("isEmpty", () => {
it("should NOT have any module by default", () => should(ChunkInstance.isEmpty()).be.true());
});
describe("size", () => {
it("should NOT have any module by default", () =>
should(ChunkInstance.size({
chunkOverhead: 10,
entryChunkMultiplicator: 2
})).be.exactly(10));
});
describe("checkConstraints", () => {
it("throws an error", () =>
should(() => {
ChunkInstance.checkConstraints();
}).not.throw(/checkConstraints/));
});
describe("canBeIntegrated", () => {
it("returns `false` if other object is initial", () => {
const other = {
isInitial: () => true
};
should(ChunkInstance.canBeIntegrated(other)).be.false();
});
it("returns `true` if other object and chunk instance are NOT initial", () => {
const other = {
isInitial: () => false
};
should(ChunkInstance.canBeIntegrated(other)).be.true();
});
});
describe("removeModule", function() {
let module;
let removeChunkSpy;
beforeEach(function() {
removeChunkSpy = sinon.spy();
module = {
removeChunk: removeChunkSpy
};
});
describe("and the chunk does not contain this module", function() {
it("returns false", function() {
ChunkInstance.removeModule(module).should.eql(false);
});
});
describe("and the chunk does contain this module", function() {
beforeEach(function() {
ChunkInstance._modules = new Set([module]);
});
it("calls module.removeChunk with itself and returns true", function() {
ChunkInstance.removeModule(module).should.eql(true);
removeChunkSpy.callCount.should.eql(1);
removeChunkSpy.args[0][0].should.eql(ChunkInstance);
});
});
});
describe("removeChunk", function() {
let chunk;
let removeParentSpy;
beforeEach(function() {
removeParentSpy = sinon.spy();
chunk = {
removeParent: removeParentSpy
};
});
describe("and the chunk does not contain this chunk", function() {
it("returns false", function() {
ChunkInstance.removeChunk(chunk).should.eql(false);
});
});
describe("and the chunk does contain this module", function() {
beforeEach(function() {
ChunkInstance.chunks = [chunk];
});
it("calls module.removeChunk with itself and returns true", function() {
ChunkInstance.removeChunk(chunk).should.eql(true);
removeParentSpy.callCount.should.eql(1);
removeParentSpy.args[0][0].should.eql(ChunkInstance);
});
});
});
describe("removeParent", function() {
let chunk;
let removeChunkSpy;
beforeEach(function() {
removeChunkSpy = sinon.spy();
chunk = {
removeChunk: removeChunkSpy
};
});
describe("and the chunk does not contain this chunk", function() {
it("returns false", function() {
ChunkInstance.removeParent(chunk).should.eql(false);
});
});
describe("and the chunk does contain this module", function() {
beforeEach(function() {
ChunkInstance.parents = [chunk];
});
it("calls module.removeChunk with itself and returns true", function() {
ChunkInstance.removeParent(chunk).should.eql(true);
removeChunkSpy.callCount.should.eql(1);
removeChunkSpy.args[0][0].should.eql(ChunkInstance);
});
});
});
});