From 3e1989dba44ef48f7be13816a4eebb2f9b2d1f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emrik=20=C3=96stling?= Date: Fri, 16 Oct 2026 21:14:24 +0200 Subject: [PATCH] test: add converter tests --- tests/integration/converters/ffmpeg.test.ts | 6 +++ tests/integration/converters/golden.ts | 32 +++++++++++++++ .../converters/graphicsmagick.test.ts | 6 +++ .../converters/imagemagick.test.ts | 6 +++ tests/integration/converters/inkscape.test.ts | 6 +++ .../integration/converters/inputs/sample.png | Bin 0 -> 405 bytes .../integration/converters/inputs/sample.svg | 1 + tests/integration/converters/libjxl.test.ts | 6 +++ .../converters/outputs/ffmpeg/sample.jpg | Bin 0 -> 517 bytes .../outputs/graphicsmagick/sample.jpg | Bin 0 -> 409 bytes .../converters/outputs/imagemagick/sample.jpg | Bin 0 -> 568 bytes .../converters/outputs/inkscape/sample.svg | 38 ++++++++++++++++++ .../converters/outputs/libjxl/sample.jxl | Bin 0 -> 329 bytes .../converters/outputs/vips/sample.jpg | Bin 0 -> 915 bytes .../converters/outputs/vtracer/sample.svg | 7 ++++ tests/integration/converters/vips.test.ts | 6 +++ tests/integration/converters/vtracer.test.ts | 6 +++ 17 files changed, 120 insertions(+) create mode 100644 tests/integration/converters/ffmpeg.test.ts create mode 100644 tests/integration/converters/golden.ts create mode 100644 tests/integration/converters/graphicsmagick.test.ts create mode 100644 tests/integration/converters/imagemagick.test.ts create mode 100644 tests/integration/converters/inkscape.test.ts create mode 100644 tests/integration/converters/inputs/sample.png create mode 100644 tests/integration/converters/inputs/sample.svg create mode 100644 tests/integration/converters/libjxl.test.ts create mode 100644 tests/integration/converters/outputs/ffmpeg/sample.jpg create mode 100644 tests/integration/converters/outputs/graphicsmagick/sample.jpg create mode 100644 tests/integration/converters/outputs/imagemagick/sample.jpg create mode 100644 tests/integration/converters/outputs/inkscape/sample.svg create mode 100644 tests/integration/converters/outputs/libjxl/sample.jxl create mode 100644 tests/integration/converters/outputs/vips/sample.jpg create mode 100644 tests/integration/converters/outputs/vtracer/sample.svg create mode 100644 tests/integration/converters/vips.test.ts create mode 100644 tests/integration/converters/vtracer.test.ts diff --git a/tests/integration/converters/ffmpeg.test.ts b/tests/integration/converters/ffmpeg.test.ts new file mode 100644 index 00000000..4314bb10 --- /dev/null +++ b/tests/integration/converters/ffmpeg.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/ffmpeg"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected JPEG bytes", () => + runGoldenConversion("ffmpeg", convert, "jpg")); diff --git a/tests/integration/converters/golden.ts b/tests/integration/converters/golden.ts new file mode 100644 index 00000000..3c0c3b4d --- /dev/null +++ b/tests/integration/converters/golden.ts @@ -0,0 +1,32 @@ +import { expect } from "bun:test"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +type Converter = ( + filePath: string, + fileType: string, + convertTo: string, + targetPath: string, + options?: unknown, +) => Promise; + +export async function runGoldenConversion( + converterName: string, + convert: Converter, + outputExtension: string, +) { + const outputDirectory = await mkdtemp(path.join(tmpdir(), `convertx-${converterName}-`)); + const outputPath = path.join(outputDirectory, `sample.${outputExtension}`); + const inputPath = path.resolve("tests/integration/converters/inputs/sample.png"); + const expectedPath = path.resolve( + `tests/integration/converters/outputs/${converterName}/sample.${outputExtension}`, + ); + + try { + await convert(inputPath, "png", outputExtension, outputPath); + expect(await Bun.file(outputPath).bytes()).toEqual(await Bun.file(expectedPath).bytes()); + } finally { + await rm(outputDirectory, { recursive: true, force: true }); + } +} diff --git a/tests/integration/converters/graphicsmagick.test.ts b/tests/integration/converters/graphicsmagick.test.ts new file mode 100644 index 00000000..286ae46c --- /dev/null +++ b/tests/integration/converters/graphicsmagick.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/graphicsmagick"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected JPEG bytes", () => + runGoldenConversion("graphicsmagick", convert, "jpg")); diff --git a/tests/integration/converters/imagemagick.test.ts b/tests/integration/converters/imagemagick.test.ts new file mode 100644 index 00000000..1d25aed6 --- /dev/null +++ b/tests/integration/converters/imagemagick.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/imagemagick"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected JPEG bytes", () => + runGoldenConversion("imagemagick", convert, "jpg")); diff --git a/tests/integration/converters/inkscape.test.ts b/tests/integration/converters/inkscape.test.ts new file mode 100644 index 00000000..1ccd1597 --- /dev/null +++ b/tests/integration/converters/inkscape.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/inkscape"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected SVG bytes", () => + runGoldenConversion("inkscape", convert, "svg")); diff --git a/tests/integration/converters/inputs/sample.png b/tests/integration/converters/inputs/sample.png new file mode 100644 index 0000000000000000000000000000000000000000..4ef84dab3cb3e10ea586031d92f91765d163d1f0 GIT binary patch literal 405 zcmV;G0c!qMuW>V9|a;z=r44UpFQ%@E%Cg<*Lq55ts(MPLJR8sZot zyT353Eazc(dW{vo0W56)88qyFF7;+1%7^H3QfDL$hScPG7e;Y%7aSg+RhmUD&05&h&dVH2a+2S|D-IJ^gA73z& z9*CvAu?&IrUl}$ua{~=w!*2k{&)mRh{E8HfKmUAT;1m7F@aYW`!|(3|0ufhIMi$4L z4hGJElDdf-u3f!?Gdm-@OjApDLvM3lAV>@V&J*Dg!hjZ700000NkvXXu0mjfx`wR& literal 0 HcmV?d00001 diff --git a/tests/integration/converters/inputs/sample.svg b/tests/integration/converters/inputs/sample.svg new file mode 100644 index 00000000..ff0220a5 --- /dev/null +++ b/tests/integration/converters/inputs/sample.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/integration/converters/libjxl.test.ts b/tests/integration/converters/libjxl.test.ts new file mode 100644 index 00000000..0b134be4 --- /dev/null +++ b/tests/integration/converters/libjxl.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/libjxl"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected JPEG XL bytes", () => + runGoldenConversion("libjxl", convert, "jxl")); diff --git a/tests/integration/converters/outputs/ffmpeg/sample.jpg b/tests/integration/converters/outputs/ffmpeg/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5652e52eaaffa69cbebcefb4a6757306ec1925aa GIT binary patch literal 517 zcmex=S=WL9J_bQDq&W=T{Q`G0^xkb^;hL4cW2h=ECnfmw**|1Aa{pw&!* z%z_N|45$9q%Lgw#^W0tUSIQj2#S6`M9!st}Tl{y@acM(AYi_lpmGR9_X8C;mJJ&DY zcy7)P&2{C+nwqXXmEy5Bz4*ajcF_rsM;epWAJ+9Zd9I!MuVIB-`;hz$)?l&gaW^xSWz|;Qp&NneAALM~0kGwb;A)!P76S zn^*aGUX72MW^NJV_9QDi*4JBSbj!K9}Y> zsbtSu=4bU5@qcv`&2$)cEm#sH_%cdRLdM7P^wl+cwjH~C_{ga%YaQR86X%xJt^a=$ E0AnJf^Z)<= literal 0 HcmV?d00001 diff --git a/tests/integration/converters/outputs/graphicsmagick/sample.jpg b/tests/integration/converters/outputs/graphicsmagick/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a44b580cb33f523104e6e8e4f7ea6903b0e8752e GIT binary patch literal 409 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<esAq z?*dlJh}{zDliB$Fs~DuVN?WE^4;T^r$)JvdBy;f_XJVk-ZK7 zi-%v$bT2Oq^3XClsbZ1%el_cyZG218PxbHFyLWYY)$btxzy%%)uR8Fr;I-PucI5GC N`8~N2e*XV&0s!+NVIKeh literal 0 HcmV?d00001 diff --git a/tests/integration/converters/outputs/imagemagick/sample.jpg b/tests/integration/converters/outputs/imagemagick/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c34b50882f9f8ef3ec39e0c174b63706945d7506 GIT binary patch literal 568 zcmex=>ukC3pCfH06P05XITq?4J21E^7eo0A(TN+S4wfI*Oh zL4ZMknNg5|Nsy6Qkn#T!1~H&hfzCt%EKD3gaXA47plgA0a7jicW>yw9K_PZUL!i7k zND3|o($2`jzyy>~02&VRC_<7^kV%n&nMFj&@L}M`|F;-;m>GfgGYc}GeaO_F z39=S^=ktU=D!8RcVRrY?C|T{z$&3ktVHl7`O*H+!>V3@`f#3Hcd;Ode!JZA0o_1XF_rth}9xcct1 zJ6WGYlf$n`EOd=oERwCeCiq9N_09mPFb3w|e{GW@KJ!UFa!#75 + + + + + + + + + diff --git a/tests/integration/converters/outputs/libjxl/sample.jxl b/tests/integration/converters/outputs/libjxl/sample.jxl new file mode 100644 index 0000000000000000000000000000000000000000..1c4fce82dea39c876bd17c4386b2b49d6793c363 GIT binary patch literal 329 zcmV-P0k;1C3PZq708D@=0Q3a4pCAAL6)K~Q8@!zB`SL@D#k7s<3~jY-VF_ciJr@cF z2?200TZ^Z77XSx<01t5lLJ$+3AB2f9kT7%=Ah3}m8*E9E#;({}Ya`+(bV#pF9J9)^ zGDq(~l(-2fE&$*lfWs^x-L0-f0)(SSA7ay33HW_s0Se#>DUjAy6{&bSQZ02EV-5;^ z0UZ8w!5-K=x`jnK;6e|q85qO???>X+t2v0}r2iXUv;&CZLQHA~Tqp!RJY(8MClv`G zSk%3NCbsIJf&Q!!(k|&Xv}CnXyai`FnBeJ;v%N}ZXn5GR3No|W+B9%65~dPIzrTxK zXdx)>hfIbk6L9qZz%u45J6!|I17I6Q*Q5oapZwBbQci*b<-4a2C&MQxF3~kX3=9lx3_^^|42(b)2um@tg6S|ITN=ua1F|)sYM6j* zVJ3w7%yt&AdZ2+|pfAbD@Pe6v0YKT(FjACJ zG$I-NKfoZ!!63jOz|5$`z$D1XEXer(2!lK@5Lp?)0OVW{0D6^$m5rT)lZzXuV5& zw6?W(baqXeJZ0*%=`&`|TC{k{(q+q6tX#Ee^OmjKw(r=v>(JpNM~@vpaq`rq%U7;m zyME*5t%r{uKY9A>`HPpYK7RWAj7{Xt-7*vlg%eaiojA=nRYmyi+Y>8Is%P)E)~?ij8&xt%cb#4B5}l(P$|l}* w|Ie^~R&3g literal 0 HcmV?d00001 diff --git a/tests/integration/converters/outputs/vtracer/sample.svg b/tests/integration/converters/outputs/vtracer/sample.svg new file mode 100644 index 00000000..c42bca3c --- /dev/null +++ b/tests/integration/converters/outputs/vtracer/sample.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/integration/converters/vips.test.ts b/tests/integration/converters/vips.test.ts new file mode 100644 index 00000000..abc38132 --- /dev/null +++ b/tests/integration/converters/vips.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/vips"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected JPEG bytes", () => + runGoldenConversion("vips", convert, "jpg")); diff --git a/tests/integration/converters/vtracer.test.ts b/tests/integration/converters/vtracer.test.ts new file mode 100644 index 00000000..75873f9b --- /dev/null +++ b/tests/integration/converters/vtracer.test.ts @@ -0,0 +1,6 @@ +import { test } from "bun:test"; +import { convert } from "../../../src/converters/vtracer"; +import { runGoldenConversion } from "./golden"; + +test("converts the sample PNG to the expected SVG bytes", () => + runGoldenConversion("vtracer", convert, "svg"));