test: add unit test for resvg.ts
This commit is contained in:
parent
b1f70ec36c
commit
d8cbc0aaee
3 changed files with 23 additions and 3 deletions
|
|
@ -28,7 +28,7 @@ export function convert(
|
||||||
convertTo: string,
|
convertTo: string,
|
||||||
targetPath: string,
|
targetPath: string,
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
execFile: ExecFileFn = execFileOriginal,
|
execFile: ExecFileFn = execFileOriginal, // to make it mockable
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
execFile("potrace", [filePath, "-o", targetPath, "-b", convertTo], (error, stdout, stderr) => {
|
execFile("potrace", [filePath, "-o", targetPath, "-b", convertTo], (error, stdout, stderr) => {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { execFile } from "node:child_process";
|
import { execFile as execFileOriginal } from "node:child_process";
|
||||||
|
import { ExecFileFn } from "./types.ts";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -14,8 +15,8 @@ export function convert(
|
||||||
fileType: string,
|
fileType: string,
|
||||||
convertTo: string,
|
convertTo: string,
|
||||||
targetPath: string,
|
targetPath: string,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
|
execFile: ExecFileFn = execFileOriginal, // to make it mockable
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
execFile("resvg", [filePath, targetPath], (error, stdout, stderr) => {
|
execFile("resvg", [filePath, targetPath], (error, stdout, stderr) => {
|
||||||
|
|
|
||||||
19
tests/converters/resvg.test.ts
Normal file
19
tests/converters/resvg.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { test } from "bun:test";
|
||||||
|
import { convert } from "../../src/converters/resvg.ts";
|
||||||
|
import {
|
||||||
|
runConvertFailTest,
|
||||||
|
runConvertLogsStderror,
|
||||||
|
runConvertSuccessTest,
|
||||||
|
} from "./helpers/converters.ts";
|
||||||
|
|
||||||
|
test("convert resolves when execFile succeeds", async () => {
|
||||||
|
await runConvertSuccessTest(convert);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("convert rejects when execFile fails", async () => {
|
||||||
|
await runConvertFailTest(convert);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("convert logs stderr when present", async () => {
|
||||||
|
await runConvertLogsStderror(convert);
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue