mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-06-28 06:55:48 +00:00
test: add test if stderror and stdout get logged if both are present
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user