webpack/test/Chunk.unittest.js

117 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 Chunk = require("../lib/Chunk");
2017-01-17 23:40:00 +08:00
describe("Chunk", () => {
let ChunkInstance;
2018-01-24 20:17:21 +08:00
beforeEach(() => {
ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test");
});
2018-01-24 20:17:21 +08:00
it("should have debugId more than 999", () => {
expect(ChunkInstance.debugId).toBeGreaterThan(999);
});
2018-01-24 20:17:21 +08:00
it("returns a string with modules information", () => {
expect(ChunkInstance.toString()).toBe("Chunk[]");
});
2017-01-17 23:40:00 +08:00
2018-01-24 20:17:21 +08:00
it("should not be the initial instance", () => {
expect(ChunkInstance.canBeInitial()).toBe(false);
});
2017-01-17 23:40:00 +08:00
describe("entry", () => {
2018-01-24 20:17:21 +08:00
it("returns an error if get entry", () => {
expect(() => {
2017-02-14 18:28:32 +08:00
ChunkInstance.entry;
2018-01-24 20:17:21 +08:00
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
});
2018-01-24 20:17:21 +08:00
it("returns an error if set an entry", () => {
expect(() => {
ChunkInstance.entry = 10;
2018-01-24 20:17:21 +08:00
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
});
});
2017-01-17 23:40:00 +08:00
describe("initial", () => {
2018-01-24 20:17:21 +08:00
it("returns an error if get initial", () => {
expect(() => {
2017-02-14 18:28:32 +08:00
ChunkInstance.initial;
2018-01-24 20:17:21 +08:00
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
});
2018-01-24 20:17:21 +08:00
it("returns an error if set an initial", () => {
expect(() => {
ChunkInstance.initial = 10;
2018-01-24 20:17:21 +08:00
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
});
});
2017-01-17 23:40:00 +08:00
describe("hasRuntime", () => {
2018-01-24 20:17:21 +08:00
it("returns false", () => {
expect(ChunkInstance.hasRuntime()).toBe(false);
});
});
2017-01-17 23:40:00 +08:00
describe("isEmpty", () => {
2018-01-24 20:17:21 +08:00
it("should NOT have any module by default", () => {
expect(ChunkInstance.isEmpty()).toBe(true);
});
});
2017-01-17 23:40:00 +08:00
describe("size", () => {
2018-01-24 20:17:21 +08:00
it("should NOT have any module by default", () => {
2018-02-25 18:46:17 +08:00
expect(
ChunkInstance.size({
chunkOverhead: 10,
entryChunkMultiplicator: 2
})
).toBe(10);
2018-01-24 20:17:21 +08:00
});
});
2018-01-24 20:17:21 +08:00
describe("removeModule", () => {
2017-02-14 18:28:32 +08:00
let module;
let removeChunkSpy;
2018-01-24 20:17:21 +08:00
beforeEach(() => {
2018-05-07 21:26:04 +08:00
removeChunkSpy = jest.fn();
2017-02-14 18:28:32 +08:00
module = {
removeChunk: removeChunkSpy
};
});
2018-01-24 20:17:21 +08:00
describe("and the chunk does not contain this module", () => {
it("returns false", () => {
expect(ChunkInstance.removeModule(module)).toBe(false);
2017-02-14 18:28:32 +08:00
});
});
2018-01-24 20:17:21 +08:00
describe("and the chunk does contain this module", () => {
beforeEach(() => {
2017-04-21 16:05:56 +08:00
ChunkInstance._modules = new Set([module]);
2017-02-14 18:28:32 +08:00
});
2018-01-24 20:17:21 +08:00
it("calls module.removeChunk with itself and returns true", () => {
expect(ChunkInstance.removeModule(module)).toBe(true);
2018-05-07 21:26:04 +08:00
expect(removeChunkSpy.mock.calls.length).toBe(1);
expect(removeChunkSpy.mock.calls[0][0]).toBe(ChunkInstance);
2017-02-14 18:28:32 +08:00
});
});
2018-01-24 20:17:21 +08:00
describe("getNumberOfGroups", () => {
beforeEach(() => {
ChunkInstance._groups = new Set();
});
2018-01-24 20:17:21 +08:00
it("should return the number of chunk groups contained by the chunk", () => {
expect(ChunkInstance.getNumberOfGroups()).toBe(0);
});
});
2017-02-14 18:28:32 +08:00
});
});