test: extract duplicate code into another helper

This commit is contained in:
Jörg Krzeslak
2025-07-24 21:08:10 +02:00
parent c6006b58d2
commit c0105889ab
13 changed files with 58 additions and 244 deletions

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/assimp.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/calibre.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
import { beforeEach, expect, test } from "bun:test";
import { convert } from "../../src/converters/dvisvgm.ts";
import { ExecFileFn } from "../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
let calls: string[][] = [];
@@ -15,21 +10,7 @@ beforeEach(() => {
calls = [];
});
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);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
runCommonTests(convert);
test("convert respects eps filetype", async () => {
const originalConsoleLog = console.log;

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/graphicsmagick.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -0,0 +1,26 @@
import { test } from "bun:test";
import { ConvertFnWithExecFile } from "../../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./converters.ts";
export function runCommonTests(convert: ConvertFnWithExecFile) {
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);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
}

View File

@@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
import { beforeEach, expect, test } from "bun:test";
import { convert } from "../../src/converters/imagemagick.ts";
import { ExecFileFn } from "../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
let calls: string[][] = [];
@@ -15,21 +10,7 @@ beforeEach(() => {
calls = [];
});
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);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
runCommonTests(convert);
test("convert respects ico conversion target type", async () => {
const originalConsoleLog = console.log;

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/inkscape.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/libheif.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
import { beforeEach, expect, test } from "bun:test";
import { convert } from "../../src/converters/libjxl.ts";
import { ExecFileFn } from "../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
let command: string = "";
@@ -15,21 +10,7 @@ beforeEach(() => {
command = "";
});
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);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
runCommonTests(convert);
test("convert uses djxl with input filetype being jxl", async () => {
const originalConsoleLog = console.log;

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/potrace.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/resvg.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});

View File

@@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
import { beforeEach, expect, test } from "bun:test";
import { ExecFileFn } from "../../src/converters/types.ts";
import { convert } from "../../src/converters/vips.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
let calls: string[][] = [];
@@ -15,21 +10,7 @@ beforeEach(() => {
calls = [];
});
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);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
runCommonTests(convert);
test("convert uses action pdfload with filetype being pdf", async () => {
const originalConsoleLog = console.log;

View File

@@ -1,24 +1,7 @@
import { test } from "bun:test";
import { convert } from "../../src/converters/xelatex.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
import { runCommonTests } from "./helpers/commonTests.ts";
test("convert resolves when execFile succeeds", async () => {
await runConvertSuccessTest(convert);
});
runCommonTests(convert);
test("convert rejects when execFile fails", async () => {
await runConvertFailTest(convert);
});
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});
test.skip("dummy - required to trigger test detection", () => {});