2025-06-10 22:18:43 +08:00
|
|
|
"use strict";
|
|
|
|
|
2025-07-26 19:03:53 +08:00
|
|
|
const { _getDirectories } = require("../lib/CleanPlugin");
|
2025-06-10 22:18:43 +08:00
|
|
|
|
|
|
|
describe("CleanPlugin", () => {
|
|
|
|
describe("_getDirectories", () => {
|
|
|
|
it("should return empty set when assets map is empty", () => {
|
|
|
|
const assets = new Map();
|
|
|
|
const result = _getDirectories(assets);
|
|
|
|
expect(result).toBeInstanceOf(Set);
|
|
|
|
expect(result.size).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should extract root directory from single file path", () => {
|
|
|
|
const assets = new Map([["./static.js", 0]]);
|
|
|
|
const result = _getDirectories(assets);
|
2025-07-03 17:06:45 +08:00
|
|
|
expect([...result]).toEqual(["."]);
|
2025-06-10 22:18:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should extract all parent directories from deep nested path", () => {
|
|
|
|
const assets = new Map([["this/dir/should/not/be/removed/file.ext", 0]]);
|
|
|
|
const result = _getDirectories(assets);
|
2025-07-03 17:06:45 +08:00
|
|
|
expect([...result]).toEqual([
|
2025-06-10 22:18:43 +08:00
|
|
|
"this/dir/should/not/be/removed",
|
|
|
|
"this/dir/should/not/be",
|
|
|
|
"this/dir/should/not",
|
|
|
|
"this/dir/should",
|
|
|
|
"this/dir",
|
|
|
|
"this",
|
|
|
|
"."
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should extract root and first level directories", () => {
|
|
|
|
const assets = new Map([
|
|
|
|
["./main.js", 0],
|
|
|
|
["./js/main.js", 0]
|
|
|
|
]);
|
|
|
|
const result = _getDirectories(assets);
|
2025-07-03 17:06:45 +08:00
|
|
|
expect([...result]).toEqual([".", "./js"]);
|
2025-06-10 22:18:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should extract all nested directory levels", () => {
|
|
|
|
const assets = new Map([
|
|
|
|
["./main.js", 0],
|
|
|
|
["./js/main.js", 0],
|
|
|
|
["./static/js/main.js", 0]
|
|
|
|
]);
|
|
|
|
const result = _getDirectories(assets);
|
2025-07-03 17:06:45 +08:00
|
|
|
expect([...result]).toEqual([".", "./js", "./static/js", "./static"]);
|
2025-06-10 22:18:43 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|