test: extract duplicate code into another helper
This commit is contained in:
parent
c6006b58d2
commit
c0105889ab
13 changed files with 58 additions and 244 deletions
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/assimp.ts";
|
import { convert } from "../../src/converters/assimp.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/calibre.ts";
|
import { convert } from "../../src/converters/calibre.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
|
||||||
import { beforeEach, expect, test } from "bun:test";
|
import { beforeEach, expect, test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/dvisvgm.ts";
|
import { convert } from "../../src/converters/dvisvgm.ts";
|
||||||
import { ExecFileFn } from "../../src/converters/types.ts";
|
import { ExecFileFn } from "../../src/converters/types.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
let calls: string[][] = [];
|
let calls: string[][] = [];
|
||||||
|
|
||||||
|
|
@ -15,21 +10,7 @@ beforeEach(() => {
|
||||||
calls = [];
|
calls = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert respects eps filetype", async () => {
|
test("convert respects eps filetype", async () => {
|
||||||
const originalConsoleLog = console.log;
|
const originalConsoleLog = console.log;
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/graphicsmagick.ts";
|
import { convert } from "../../src/converters/graphicsmagick.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
26
tests/converters/helpers/commonTests.ts
Normal file
26
tests/converters/helpers/commonTests.ts
Normal 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
|
||||||
import { beforeEach, expect, test } from "bun:test";
|
import { beforeEach, expect, test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/imagemagick.ts";
|
import { convert } from "../../src/converters/imagemagick.ts";
|
||||||
import { ExecFileFn } from "../../src/converters/types.ts";
|
import { ExecFileFn } from "../../src/converters/types.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
let calls: string[][] = [];
|
let calls: string[][] = [];
|
||||||
|
|
||||||
|
|
@ -15,21 +10,7 @@ beforeEach(() => {
|
||||||
calls = [];
|
calls = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert respects ico conversion target type", async () => {
|
test("convert respects ico conversion target type", async () => {
|
||||||
const originalConsoleLog = console.log;
|
const originalConsoleLog = console.log;
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/inkscape.ts";
|
import { convert } from "../../src/converters/inkscape.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/libheif.ts";
|
import { convert } from "../../src/converters/libheif.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
|
||||||
import { beforeEach, expect, test } from "bun:test";
|
import { beforeEach, expect, test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/libjxl.ts";
|
import { convert } from "../../src/converters/libjxl.ts";
|
||||||
import { ExecFileFn } from "../../src/converters/types.ts";
|
import { ExecFileFn } from "../../src/converters/types.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
let command: string = "";
|
let command: string = "";
|
||||||
|
|
||||||
|
|
@ -15,21 +10,7 @@ beforeEach(() => {
|
||||||
command = "";
|
command = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert uses djxl with input filetype being jxl", async () => {
|
test("convert uses djxl with input filetype being jxl", async () => {
|
||||||
const originalConsoleLog = console.log;
|
const originalConsoleLog = console.log;
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/potrace.ts";
|
import { convert } from "../../src/converters/potrace.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/resvg.ts";
|
import { convert } from "../../src/converters/resvg.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@ import type { ExecFileException } from "node:child_process";
|
||||||
import { beforeEach, expect, test } from "bun:test";
|
import { beforeEach, expect, test } from "bun:test";
|
||||||
import { ExecFileFn } from "../../src/converters/types.ts";
|
import { ExecFileFn } from "../../src/converters/types.ts";
|
||||||
import { convert } from "../../src/converters/vips.ts";
|
import { convert } from "../../src/converters/vips.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
let calls: string[][] = [];
|
let calls: string[][] = [];
|
||||||
|
|
||||||
|
|
@ -15,21 +10,7 @@ beforeEach(() => {
|
||||||
calls = [];
|
calls = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert uses action pdfload with filetype being pdf", async () => {
|
test("convert uses action pdfload with filetype being pdf", async () => {
|
||||||
const originalConsoleLog = console.log;
|
const originalConsoleLog = console.log;
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
import { test } from "bun:test";
|
import { test } from "bun:test";
|
||||||
import { convert } from "../../src/converters/xelatex.ts";
|
import { convert } from "../../src/converters/xelatex.ts";
|
||||||
import {
|
import { runCommonTests } from "./helpers/commonTests.ts";
|
||||||
runConvertFailTest,
|
|
||||||
runConvertLogsStderror,
|
|
||||||
runConvertLogsStderrorAndStdout,
|
|
||||||
runConvertSuccessTest,
|
|
||||||
} from "./helpers/converters.ts";
|
|
||||||
|
|
||||||
test("convert resolves when execFile succeeds", async () => {
|
runCommonTests(convert);
|
||||||
await runConvertSuccessTest(convert);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("convert rejects when execFile fails", async () => {
|
test.skip("dummy - required to trigger test detection", () => {});
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue