forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleReason.test.js
77 lines (61 loc) · 2.34 KB
/
ModuleReason.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
71
72
73
74
75
76
77
"use strict";
const Module = require("../lib/Module");
const Chunk = require("../lib/Chunk");
const Dependency = require("../lib/Dependency");
const ModuleReason = require("../lib/ModuleReason");
const should = require("should");
describe("ModuleReason", () => {
let myModule;
let myDependency;
let myModuleReason;
let myChunk;
let myChunk2;
beforeEach(() => {
myModule = new Module();
myDependency = new Dependency();
myChunk = new Chunk("chunk-test", "module-test", "loc-test");
myChunk2 = new Chunk("chunk-test", "module-test", "loc-test");
myModuleReason = new ModuleReason(myModule, myDependency);
});
describe("hasChunk", () => {
it("returns false when chunk is not present", () => should(myModuleReason.hasChunk(myChunk)).be.false());
it("returns true when chunk is present", () => {
myModuleReason.module.addChunk(myChunk);
should(myModuleReason.hasChunk(myChunk)).be.true();
});
});
describe("rewriteChunks", () => {
it("if old chunk is present, it is replaced with new chunks", () => {
myModuleReason.module.addChunk(myChunk);
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
should(myModuleReason.hasChunk(myChunk)).be.false();
should(myModuleReason.hasChunk(myChunk2)).be.true();
});
it("if old chunk is not present, new chunks are not added", () => {
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
should(myModuleReason.hasChunk(myChunk)).be.false();
should(myModuleReason.hasChunk(myChunk2)).be.false();
});
it("if already rewritten chunk is present, it is replaced with new chunks", () => {
myModuleReason.module.addChunk(myChunk);
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
myModuleReason.rewriteChunks(myChunk2, [myChunk]);
should(myModuleReason.hasChunk(myChunk)).be.true();
should(myModuleReason.hasChunk(myChunk2)).be.false();
});
});
describe(".chunks", () => {
it("is null if no rewrites happen first", () => {
should(myModuleReason.chunks).be.Null();
});
it("is null if only invalid rewrites happen first", () => {
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
should(myModuleReason.chunks).be.Null();
});
it("is an array of chunks if a valid rewrite happens", () => {
myModuleReason.module.addChunk(myChunk);
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
should(myModuleReason.chunks).be.eql([myChunk2]);
});
});
});