test: add test if stderror and stdout get logged if both are present

This commit is contained in:
Jörg Krzeslak
2025-07-24 18:47:20 +02:00
parent 08a833f1cf
commit 4b42a5fbda
13 changed files with 91 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/assimp.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/calibre.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -5,6 +5,7 @@ import { ExecFileFn } from "../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -26,6 +27,10 @@ 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 () => {
const originalConsoleLog = console.log;

View File

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/graphicsmagick.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -65,3 +65,34 @@ export async function runConvertLogsStderror(convertFn: ConvertFnWithExecFile) {
expect(loggedMessage).toBe("stderr: Fake stderr");
}
export async function runConvertLogsStderrorAndStdout(convertFn: ConvertFnWithExecFile) {
const originalConsoleError = console.error;
const originalConsoleLog = console.log;
let loggedError = "";
let loggedMessage = "";
console.error = (msg) => {
loggedError = msg;
};
console.log = (msg) => {
loggedMessage = msg;
};
const mockExecFile = (
_cmd: string,
_args: string[],
options: unknown,
callback: (err: Error | null, stdout: string, stderr: string) => void,
) => {
callback(null, "Fake stdout", "Fake stderr");
};
await convertFn("file.obj", "obj", "stl", "out.stl", undefined, mockExecFile);
console.error = originalConsoleError;
console.log = originalConsoleLog;
expect(loggedError).toBe("stderr: Fake stderr");
expect(loggedMessage).toBe("stdout: Fake stdout");
}

View File

@@ -5,6 +5,7 @@ import { ExecFileFn } from "../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -26,6 +27,10 @@ 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 () => {
const originalConsoleLog = console.log;

View File

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/inkscape.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/libheif.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -5,6 +5,7 @@ import { ExecFileFn } from "../../src/converters/types.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -26,6 +27,10 @@ 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 () => {
const originalConsoleLog = console.log;

View File

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/potrace.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/resvg.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
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

@@ -5,6 +5,7 @@ import { convert } from "../../src/converters/vips.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -26,6 +27,10 @@ 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 () => {
const originalConsoleLog = console.log;

View File

@@ -3,6 +3,7 @@ import { convert } from "../../src/converters/xelatex.ts";
import {
runConvertFailTest,
runConvertLogsStderror,
runConvertLogsStderrorAndStdout,
runConvertSuccessTest,
} from "./helpers/converters.ts";
@@ -17,3 +18,7 @@ test("convert rejects when execFile fails", async () => {
test("convert logs stderr when present", async () => {
await runConvertLogsStderror(convert);
});
test("convert logs both stderr and stdout when present", async () => {
await runConvertLogsStderrorAndStdout(convert);
});