mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 45s
Build Docker Images / lint (push) Successful in 27s
Build Docker Images / check (push) Successful in 1m7s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 12s
Mirror to Codeberg / Mirror (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Nix Build / check (push) Failing after 32m31s
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import sharp from "sharp";
|
|
import { mockModule } from "~/tests/utils.ts";
|
|
import { calculateBlurhash } from "./blurhash.ts";
|
|
|
|
describe("BlurhashPreprocessor", () => {
|
|
it("should calculate blurhash for a valid image", async () => {
|
|
const inputBuffer = await sharp({
|
|
create: {
|
|
width: 100,
|
|
height: 100,
|
|
channels: 3,
|
|
background: { r: 255, g: 0, b: 0 },
|
|
},
|
|
})
|
|
.png()
|
|
.toBuffer();
|
|
|
|
const inputFile = new File([inputBuffer], "test.png", {
|
|
type: "image/png",
|
|
});
|
|
const result = await calculateBlurhash(inputFile);
|
|
|
|
expect(result).toBeTypeOf("string");
|
|
expect(result).not.toBe("");
|
|
});
|
|
|
|
it("should return null blurhash for an invalid image", async () => {
|
|
const invalidFile = new File(["invalid image data"], "invalid.png", {
|
|
type: "image/png",
|
|
});
|
|
const result = await calculateBlurhash(invalidFile);
|
|
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("should handle errors during blurhash calculation", async () => {
|
|
const inputBuffer = await sharp({
|
|
create: {
|
|
width: 100,
|
|
height: 100,
|
|
channels: 3,
|
|
background: { r: 255, g: 0, b: 0 },
|
|
},
|
|
})
|
|
.png()
|
|
.toBuffer();
|
|
|
|
const inputFile = new File([inputBuffer], "test.png", {
|
|
type: "image/png",
|
|
});
|
|
|
|
using __ = await mockModule("blurhash", () => ({
|
|
encode: (): void => {
|
|
throw new Error("Test error");
|
|
},
|
|
}));
|
|
|
|
const result = await calculateBlurhash(inputFile);
|
|
|
|
expect(result).toBeNull();
|
|
});
|
|
});
|