/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/formatSize.unittest.js
60 строк
2 KB
Alexander Akait
fix: several small correctness fixes (formatSize, data URIs, CSS unescape, RegExp flags) (#21366)
08 июл 2026, 23:21
Не верифицирован
08 июл 2026, 23:21
2d60c44
Код
Авторство
О чём код?
"use strict"; const formatSize = require("../lib/util/formatSize"); describe("SizeFormatHelpers", () => { describe("formatSize", () => { it("should handle zero size", () => { expect(formatSize(0)).toBe("0 bytes"); }); it("should handle negative size", () => { expect(formatSize(-1)).toBe("0 bytes"); }); it("should handle bytes", () => { expect(formatSize(1000)).toBe("1000 bytes"); }); it("should handle integer kibibytes", () => { expect(formatSize(2048)).toBe("2 KiB"); }); it("should handle float kibibytes", () => { expect(formatSize(2560)).toBe("2.5 KiB"); }); it("should handle integer mebibytes", () => { expect(formatSize(10 * 1024 * 1024)).toBe("10 MiB"); }); it("should handle float mebibytes", () => { expect(formatSize(12.5 * 1024 * 1024)).toBe("12.5 MiB"); }); it("should handle integer gibibytes", () => { expect(formatSize(3 * 1024 * 1024 * 1024)).toBe("3 GiB"); }); it("should handle float gibibytes", () => { expect(formatSize(1.2 * 1024 * 1024 * 1024)).toBe("1.2 GiB"); }); it("should handle tebibytes", () => { expect(formatSize(2 * 1024 ** 4)).toBe("2 TiB"); }); it("should handle pebibytes", () => { expect(formatSize(3 * 1024 ** 5)).toBe("3 PiB"); }); it("should clamp sizes beyond the largest unit", () => { expect(formatSize(5 * 1024 ** 6)).toBe("5120 PiB"); }); it("should handle undefined/NaN", () => { expect(formatSize()).toBe("unknown size"); expect(formatSize(Number.NaN)).toBe("unknown size"); }); }); });