mirror of
https://github.com/versia-pub/server.git
synced 2026-04-28 05:09:16 +02:00
refactor: ✅ Refactor tests to not use module mocks, so bun test can be used
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
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
This commit is contained in:
parent
ec506241f0
commit
7112a66e4c
10 changed files with 71 additions and 527 deletions
|
|
@ -1,27 +1,8 @@
|
|||
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import sharp from "sharp";
|
||||
import type { config } from "~/config.ts";
|
||||
import { convertImage } from "./image-conversion.ts";
|
||||
|
||||
describe("ImageConversionPreprocessor", () => {
|
||||
let mockConfig: typeof config;
|
||||
|
||||
beforeEach(() => {
|
||||
mockConfig = {
|
||||
media: {
|
||||
conversion: {
|
||||
convert_images: true,
|
||||
convert_to: "image/webp",
|
||||
convert_vector: false,
|
||||
},
|
||||
},
|
||||
} as unknown as typeof config;
|
||||
|
||||
mock.module("~/config.ts", () => ({
|
||||
config: mockConfig,
|
||||
}));
|
||||
});
|
||||
|
||||
it("should convert a JPEG image to WebP", async () => {
|
||||
const inputBuffer = await sharp({
|
||||
create: {
|
||||
|
|
@ -37,7 +18,7 @@ describe("ImageConversionPreprocessor", () => {
|
|||
const inputFile = new File([inputBuffer], "test.jpg", {
|
||||
type: "image/jpeg",
|
||||
});
|
||||
const result = await convertImage(inputFile);
|
||||
const result = await convertImage(inputFile, "image/webp");
|
||||
|
||||
expect(result.type).toBe("image/webp");
|
||||
expect(result.name).toBe("test.webp");
|
||||
|
|
@ -53,20 +34,20 @@ describe("ImageConversionPreprocessor", () => {
|
|||
const inputFile = new File([svgContent], "test.svg", {
|
||||
type: "image/svg+xml",
|
||||
});
|
||||
const result = await convertImage(inputFile);
|
||||
const result = await convertImage(inputFile, "image/webp");
|
||||
|
||||
expect(result).toBe(inputFile);
|
||||
});
|
||||
|
||||
it("should convert SVG when convert_vector is true", async () => {
|
||||
mockConfig.media.conversion.convert_vectors = true;
|
||||
|
||||
const svgContent =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg"><rect width="100" height="100" fill="red"/></svg>';
|
||||
const inputFile = new File([svgContent], "test.svg", {
|
||||
type: "image/svg+xml",
|
||||
});
|
||||
const result = await convertImage(inputFile);
|
||||
const result = await convertImage(inputFile, "image/webp", {
|
||||
convertVectors: true,
|
||||
});
|
||||
|
||||
expect(result.type).toBe("image/webp");
|
||||
expect(result.name).toBe("test.webp");
|
||||
|
|
@ -76,14 +57,12 @@ describe("ImageConversionPreprocessor", () => {
|
|||
const inputFile = new File(["test content"], "test.txt", {
|
||||
type: "text/plain",
|
||||
});
|
||||
const result = await convertImage(inputFile);
|
||||
const result = await convertImage(inputFile, "image/webp");
|
||||
|
||||
expect(result).toBe(inputFile);
|
||||
});
|
||||
|
||||
it("should throw an error for unsupported output format", async () => {
|
||||
mockConfig.media.conversion.convert_to = "image/bmp";
|
||||
|
||||
const inputBuffer = await sharp({
|
||||
create: {
|
||||
width: 100,
|
||||
|
|
@ -99,7 +78,7 @@ describe("ImageConversionPreprocessor", () => {
|
|||
type: "image/png",
|
||||
});
|
||||
|
||||
await expect(convertImage(inputFile)).rejects.toThrow(
|
||||
await expect(convertImage(inputFile, "image/bmp")).rejects.toThrow(
|
||||
"Unsupported output format: image/bmp",
|
||||
);
|
||||
});
|
||||
|
|
@ -120,7 +99,7 @@ describe("ImageConversionPreprocessor", () => {
|
|||
const inputFile = new File([inputBuffer], "animated.gif", {
|
||||
type: "image/gif",
|
||||
});
|
||||
const result = await convertImage(inputFile);
|
||||
const result = await convertImage(inputFile, "image/webp");
|
||||
|
||||
expect(result.type).toBe("image/webp");
|
||||
expect(result.name).toBe("animated.webp");
|
||||
|
|
@ -147,7 +126,7 @@ describe("ImageConversionPreprocessor", () => {
|
|||
"test image with spaces.png",
|
||||
{ type: "image/png" },
|
||||
);
|
||||
const result = await convertImage(inputFile);
|
||||
const result = await convertImage(inputFile, "image/webp");
|
||||
|
||||
expect(result.type).toBe("image/webp");
|
||||
expect(result.name).toBe("test image with spaces.webp");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue