Add local background removal and mask tools

This commit is contained in:
achraf
2026-06-07 23:32:26 +02:00
parent f5364bf7a8
commit e29dc6fd6d
23 changed files with 2508 additions and 21 deletions

View File

@@ -0,0 +1,37 @@
import { describe, it, expect, vi } from "vitest";
import { backgroundRemoverPlugin } from "./index";
import { runBackgroundRemover } from "./run";
import type { BackgroundRemoverOptions } from "./remove";
import type { ToolContext } from "../../core/plugins/plugin-types";
const mockContext: ToolContext = {
signal: new AbortController().signal,
reportProgress: vi.fn(),
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
};
const options: BackgroundRemoverOptions = { quality: "small", useGpu: true };
describe("Background Remover Plugin", () => {
it("should have correct manifest", () => {
expect(backgroundRemoverPlugin.manifest.id).toBe("background-remover");
expect(backgroundRemoverPlugin.manifest.category).toBe("image");
expect(backgroundRemoverPlugin.manifest.input.type).toBe("files");
expect(backgroundRemoverPlugin.manifest.output.type).toBe("files");
});
it("should run in a worker with wasm capability", () => {
expect(backgroundRemoverPlugin.capabilities?.worker).toBe(true);
expect(backgroundRemoverPlugin.capabilities?.persistentWorker).toBe(true);
expect(backgroundRemoverPlugin.capabilities?.wasm).toBe(true);
expect(backgroundRemoverPlugin.capabilities?.customUi).toBe(true);
expect(backgroundRemoverPlugin.worker).toBeDefined();
expect(backgroundRemoverPlugin.customUi).toBeDefined();
});
it("should throw if no image is provided", async () => {
await expect(
runBackgroundRemover({ files: [] }, options, mockContext)
).rejects.toThrow("No image provided.");
});
});