Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Set for ModuleReason chunk rewriting
- Loading branch information
1 parent
3ae782d
commit 8a30188
Showing
3 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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]); | ||
}); | ||
}); | ||
}); |