webpack/test/Chunk.unittest.js

101 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-02-14 18:28:32 +08:00
/* globals describe, it, beforeEach */
2017-01-17 23:40:00 +08:00
"use strict";
2017-01-17 23:40:00 +08:00
const should = require("should");
2017-02-14 18:28:32 +08:00
const sinon = require("sinon");
2017-01-17 23:40:00 +08:00
const Chunk = require("../lib/Chunk");
2017-01-17 23:40:00 +08:00
describe("Chunk", () => {
let ChunkInstance;
2017-01-17 23:40:00 +08:00
beforeEach(() => ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test"));
it("should have debugId more than 999", () => should(ChunkInstance.debugId).be.above(999));
2017-01-17 23:40:00 +08:00
it("returns a string with modules information", () => should(ChunkInstance.toString()).be.exactly("Chunk[]"));
it("should not be the initial instance", () => should(ChunkInstance.canBeInitial()).be.false());
2017-01-17 23:40:00 +08:00
describe("entry", () => {
it("returns an error if get entry", () =>
should(() => {
2017-02-14 18:28:32 +08:00
ChunkInstance.entry;
2017-01-17 23:40:00 +08:00
}).throw("Chunk.entry was removed. Use hasRuntime()"));
2017-01-17 23:40:00 +08:00
it("returns an error if set an entry", () =>
should(() => {
ChunkInstance.entry = 10;
2017-01-17 23:40:00 +08:00
}).throw("Chunk.entry was removed. Use hasRuntime()"));
});
2017-01-17 23:40:00 +08:00
describe("initial", () => {
it("returns an error if get initial", () =>
should(() => {
2017-02-14 18:28:32 +08:00
ChunkInstance.initial;
}).throw("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()"));
2017-01-17 23:40:00 +08:00
it("returns an error if set an initial", () =>
should(() => {
ChunkInstance.initial = 10;
}).throw("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()"));
});
2017-01-17 23:40:00 +08:00
describe("hasRuntime", () => {
it("returns false", () => should(ChunkInstance.hasRuntime()).be.false());
});
2017-01-17 23:40:00 +08:00
describe("isEmpty", () => {
it("should NOT have any module by default", () => should(ChunkInstance.isEmpty()).be.true());
});
2017-01-17 23:40:00 +08:00
describe("size", () => {
it("should NOT have any module by default", () =>
should(ChunkInstance.size({
chunkOverhead: 10,
entryChunkMultiplicator: 2
2017-01-17 23:40:00 +08:00
})).be.exactly(10));
});
2017-02-14 18:28:32 +08:00
describe("removeModule", function() {
let module;
let removeChunkSpy;
2017-02-14 18:28:32 +08:00
beforeEach(function() {
removeChunkSpy = sinon.spy();
2017-02-14 18:28:32 +08:00
module = {
removeChunk: removeChunkSpy
};
});
2017-02-14 18:28:32 +08:00
describe("and the chunk does not contain this module", function() {
it("returns false", function() {
ChunkInstance.removeModule(module).should.eql(false);
});
});
2017-02-14 18:28:32 +08:00
describe("and the chunk does contain this module", function() {
beforeEach(function() {
2017-04-21 16:05:56 +08:00
ChunkInstance._modules = new Set([module]);
2017-02-14 18:28:32 +08:00
});
2017-02-14 18:28:32 +08:00
it("calls module.removeChunk with itself and returns true", function() {
ChunkInstance.removeModule(module).should.eql(true);
2017-02-14 18:28:32 +08:00
removeChunkSpy.callCount.should.eql(1);
removeChunkSpy.args[0][0].should.eql(ChunkInstance);
});
});
describe("getNumberOfGroups", function() {
beforeEach(function() {
ChunkInstance._groups = new Set();
});
it("should return the number of chunk groups contained by the chunk", function() {
ChunkInstance.getNumberOfGroups().should.eql(0);
});
});
2017-02-14 18:28:32 +08:00
});
});