mirror of
				https://github.com/C4illin/ConvertX.git
				synced 2025-11-04 05:53:45 +00:00 
			
		
		
		
	test: add unit test for libheif.ts
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
import { execFile } from "child_process";
 | 
			
		||||
import { execFile as execFileOriginal } from "child_process";
 | 
			
		||||
import { ExecFileFn } from "./types.ts";
 | 
			
		||||
 | 
			
		||||
export const properties = {
 | 
			
		||||
  from: {
 | 
			
		||||
@@ -14,8 +15,8 @@ export function convert(
 | 
			
		||||
  fileType: string,
 | 
			
		||||
  convertTo: string,
 | 
			
		||||
  targetPath: string,
 | 
			
		||||
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
			
		||||
  options?: unknown,
 | 
			
		||||
  execFile: ExecFileFn = execFileOriginal, // to make it mockable
 | 
			
		||||
): Promise<string> {
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    execFile("heif-convert", [filePath, targetPath], (error, stdout, stderr) => {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								tests/converters/libheif.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/converters/libheif.test.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
import { test } from "bun:test";
 | 
			
		||||
import { convert } from "../../src/converters/libheif.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);
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user