mirror of
				https://github.com/C4illin/ConvertX.git
				synced 2025-11-04 05:53:45 +00:00 
			
		
		
		
	test: extract duplicate code into another helper
This commit is contained in:
		@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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 { 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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", () => {});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user