Skip to content

Commit 554edf5

Browse files
authored
Merge pull request #373 from Laertes87/AddUnitTests
test: add unit tests for converters
2 parents 6fca398 + d994c38 commit 554edf5

34 files changed

+921
-33
lines changed

src/converters/assimp.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -116,8 +117,8 @@ export async function convert(
116117
fileType: string,
117118
convertTo: string,
118119
targetPath: string,
119-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
120120
options?: unknown,
121+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
121122
): Promise<string> {
122123
return new Promise((resolve, reject) => {
123124
execFile("assimp", ["export", filePath, targetPath], (error, stdout, stderr) => {

src/converters/calibre.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -62,8 +63,8 @@ export async function convert(
6263
fileType: string,
6364
convertTo: string,
6465
targetPath: string,
65-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6666
options?: unknown,
67+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
6768
): Promise<string> {
6869
return new Promise((resolve, reject) => {
6970
execFile("ebook-convert", [filePath, targetPath], (error, stdout, stderr) => {

src/converters/dvisvgm.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -14,8 +15,8 @@ export function convert(
1415
fileType: string,
1516
convertTo: string,
1617
targetPath: string,
17-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1818
options?: unknown,
19+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
1920
): Promise<string> {
2021
const inputArgs: string[] = [];
2122
if (fileType === "eps") {

src/converters/ffmpeg.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
// This could be done dynamically by running `ffmpeg -formats` and parsing the output
45
export const properties = {
@@ -691,8 +692,8 @@ export async function convert(
691692
fileType: string,
692693
convertTo: string,
693694
targetPath: string,
694-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
695695
options?: unknown,
696+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
696697
): Promise<string> {
697698
let extraArgs: string[] = [];
698699
let message = "Done";

src/converters/graphicsmagick.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -313,8 +314,8 @@ export function convert(
313314
fileType: string,
314315
convertTo: string,
315316
targetPath: string,
316-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
317317
options?: unknown,
318+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
318319
): Promise<string> {
319320
return new Promise((resolve, reject) => {
320321
execFile("gm", ["convert", filePath, targetPath], (error, stdout, stderr) => {

src/converters/imagemagick.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
// declare possible conversions
45
export const properties = {
@@ -445,8 +446,8 @@ export function convert(
445446
fileType: string,
446447
convertTo: string,
447448
targetPath: string,
448-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
449449
options?: unknown,
450+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
450451
): Promise<string> {
451452
let outputArgs: string[] = [];
452453
let inputArgs: string[] = [];

src/converters/inkscape.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -32,8 +33,8 @@ export function convert(
3233
fileType: string,
3334
convertTo: string,
3435
targetPath: string,
35-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3636
options?: unknown,
37+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
3738
): Promise<string> {
3839
return new Promise((resolve, reject) => {
3940
execFile("inkscape", [filePath, "-o", targetPath], (error, stdout, stderr) => {

src/converters/libheif.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "child_process";
1+
import { execFile as execFileOriginal } from "child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -14,8 +15,8 @@ export function convert(
1415
fileType: string,
1516
convertTo: string,
1617
targetPath: string,
17-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1818
options?: unknown,
19+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
1920
): Promise<string> {
2021
return new Promise((resolve, reject) => {
2122
execFile("heif-convert", [filePath, targetPath], (error, stdout, stderr) => {

src/converters/libjxl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
// declare possible conversions
45
export const properties = {
@@ -17,8 +18,8 @@ export function convert(
1718
fileType: string,
1819
convertTo: string,
1920
targetPath: string,
20-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2121
options?: unknown,
22+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
2223
): Promise<string> {
2324
let tool = "";
2425
if (fileType === "jxl") {

src/converters/libreoffice.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { execFile } from "node:child_process";
1+
import { execFile as execFileOriginal } from "node:child_process";
2+
import { ExecFileFn } from "./types";
23

34
export const properties = {
45
from: {
@@ -136,8 +137,8 @@ export function convert(
136137
fileType: string,
137138
convertTo: string,
138139
targetPath: string,
139-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
140140
options?: unknown,
141+
execFile: ExecFileFn = execFileOriginal,
141142
): Promise<string> {
142143
const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "") ?? targetPath;
143144

0 commit comments

Comments
 (0)