61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
configForProfile,
|
|
optimizationProfiles,
|
|
} from "../../src/optimization/profiles";
|
|
|
|
describe("explicit optimization profiles", () => {
|
|
it("exposes three clearly ordered risk levels", () => {
|
|
expect(optimizationProfiles.map((profile) => profile.id)).toEqual([
|
|
"conservative",
|
|
"standard",
|
|
"aggressive",
|
|
]);
|
|
expect(
|
|
optimizationProfiles.every(
|
|
(profile) => profile.description && profile.risk,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("retains IDs and viewBox in every profile", () => {
|
|
for (const name of ["conservative", "standard", "aggressive"] as const) {
|
|
const config = configForProfile(name);
|
|
const preset = config.plugins?.find(
|
|
(plugin) =>
|
|
typeof plugin === "object" && plugin.name === "preset-default",
|
|
);
|
|
expect(preset).toMatchObject({
|
|
params: { overrides: { cleanupIds: false, removeViewBox: false } },
|
|
});
|
|
}
|
|
});
|
|
|
|
it("only enables multipass and structural rewrites in aggressive mode", () => {
|
|
expect(configForProfile("conservative").multipass).toBe(false);
|
|
expect(configForProfile("standard").multipass).toBe(false);
|
|
const aggressive = configForProfile("aggressive");
|
|
expect(aggressive.multipass).toBe(true);
|
|
expect(aggressive.plugins).toEqual(
|
|
expect.arrayContaining(["convertShapeToPath", "collapseGroups"]),
|
|
);
|
|
});
|
|
|
|
it("adds only explicitly allow-listed optional plugins", () => {
|
|
const config = configForProfile("conservative", [
|
|
"removeDimensions",
|
|
"reusePaths",
|
|
"removeDimensions",
|
|
]);
|
|
expect(config.plugins).toEqual(
|
|
expect.arrayContaining(["removeDimensions", "reusePaths"]),
|
|
);
|
|
expect(
|
|
config.plugins?.filter((plugin) => plugin === "removeDimensions"),
|
|
).toHaveLength(1);
|
|
expect(() =>
|
|
configForProfile("standard", ["unknown" as "reusePaths"]),
|
|
).toThrow("Unsupported optional SVGO plugin");
|
|
});
|
|
});
|