feat: introduce local-first SVG workbench
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user