test: add converter tests
@@ -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"));
|
||||
@@ -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<string>;
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
@@ -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"));
|
||||
@@ -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"));
|
||||
|
After Width: | Height: | Size: 405 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="512" height="512" style="cursor:default" viewBox="0 0 96.983 132.292"><g transform="translate(-56.568 -82.29)"><path d="M124.878 83.82h-60.91a5.86 5.86 0 0 0-5.87 5.87v117.496a5.855 5.855 0 0 0 5.87 5.866h82.182a5.855 5.855 0 0 0 5.87-5.866v-92.55z" style="display:inline;fill:#111827;stroke:#aeb9d0;stroke-width:3.06006;stroke-dasharray:none;stroke-opacity:1"/><circle cx="84.331" cy="128.904" r="6.653" style="fill:#84cc16;fill-opacity:1;stroke-width:2.13082"/><circle cx="105.059" cy="128.904" r="6.653" style="fill:#fff;fill-opacity:1;stroke-width:2.13082"/><circle cx="125.786" cy="128.904" r="6.653" style="fill:#84cc16;fill-opacity:1;stroke-width:2.13082"/><circle cx="84.331" cy="148.438" r="6.653" style="fill:#fff;fill-opacity:1;stroke-width:2.13082"/><circle cx="105.059" cy="148.438" r="6.653" style="display:inline;fill:#84cc16;fill-opacity:1;stroke-width:2.13082"/><circle cx="125.786" cy="148.438" r="6.653" style="fill:#fff;fill-opacity:1;stroke-width:2.13082"/><circle cx="84.331" cy="167.971" r="6.653" style="fill:#84cc16;fill-opacity:1;stroke-width:2.13082"/><circle cx="105.059" cy="167.971" r="6.653" style="fill:#fff;fill-opacity:1;stroke-width:2.13082"/><circle cx="125.786" cy="167.971" r="6.653" style="fill:#84cc16;fill-opacity:1;stroke-width:2.13082"/><path d="M119.124 161.326h13.287v13.287h-13.287z" style="fill:#84cc16;fill-opacity:1;stroke:none;stroke-width:3.04496;stroke-opacity:1"/></g></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -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"));
|
||||
|
After Width: | Height: | Size: 517 B |
|
After Width: | Height: | Size: 409 B |
|
After Width: | Height: | Size: 568 B |
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
sodipodi:docname="sample.png"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1" />
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1" />
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
inkscape:label="Image"
|
||||
id="g1">
|
||||
<image
|
||||
width="16"
|
||||
height="16"
|
||||
preserveAspectRatio="none"
|
||||
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABXElEQVQ4T2NkgILS2knrr1677A/j o9Py8go3HN0CbMI8tN8hyzHCOMEx+Xf37dmhhMsARkZGhujYxCNGmmauiYmOP2DqiDYApIGVlY0h JS17NdvfFxENDQ3/QGIkGQDSwMPDy5CWkddbWxJXgtMAHuF/DF/eMgEVc4Nd+uXLVwaYGIjv5Op+ d+3iSSpYDZDW+s0Q3vmFYXkpD8OUhkVgA3Ia4hgiu78wrCznYXh6jRW/ASxs/xk07H8xXD/AxmCk bwg24NzF8wyaDr8YbhxkY/jzixG/AQrysgwTe1sYcgurGKRt74ANeHpYhWFyfxtDfnENw4OHj2ls ADYv3Hp8lkHZ4jfD3ZOsDB9fMJMeiKW9sQyB9V8ZNjRzAw1hw28AyM/cwGj8ihSNP/98YeAT/cfw 6Q0Tw+/vBAIRV1JGFsebDgbOgJK6iRuuXb2CMzsju0xTS3dDb3NeIEgMAM4T4RHCgBZYAAAAAElF TkSuQmCC "
|
||||
id="image1" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 915 B |
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generator: visioncortex VTracer 0.6.4 -->
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
||||
<path d="M0 0 C1.61 -0.04 3.22 -0.08 4.88 -0.12 C5.78 -0.15 6.68 -0.17 7.62 -0.2 C10 -0 10 -0 12 2 C12.2 5.26 12.2 5.26 12.12 9.12 C12.11 10.41 12.09 11.69 12.07 13.01 C12.05 14 12.02 14.98 12 16 C8.04 16 4.08 16 0 16 C0 10.72 0 5.44 0 0 Z " fill="#37414C" transform="translate(2,0)"/>
|
||||
<path d="M0 0 C0.33 0 0.66 0 1 0 C1 2.97 1 5.94 1 9 C-2.3 9 -5.6 9 -9 9 C-9 7.35 -9 5.7 -9 4 C-6.03 4.33 -3.06 4.66 0 5 C0 3.35 0 1.7 0 0 Z " fill="#121927" transform="translate(12,6)"/>
|
||||
<path d="M0 0 C1.32 0 2.64 0 4 0 C4 0.66 4 1.32 4 2 C4.99 2 5.98 2 7 2 C7 3.32 7 4.64 7 6 C4.69 6 2.38 6 0 6 C0 4.02 0 2.04 0 0 Z " fill="#5A6E50" transform="translate(5,5)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 820 B |
@@ -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"));
|
||||
@@ -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"));
|
||||