Skip to content

Commit 3235eaa

Browse files
committed
fix: skip PDF tool tests on Windows (process.platform check)
hasCommand() now returns false immediately on win32 instead of trying to run 'which' (which doesn't exist on Windows). Also adds pdfinfo to the skip check in pdf-content.test.ts and warns on Linux when tools are missing. Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent df821dc commit 3235eaa

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

tests/pdf-content.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,31 @@ function extractText(doc: any): string {
2626
}
2727
}
2828

29-
function hasPdftotext(): boolean {
29+
/** Check if a command-line tool is available (cross-platform). */
30+
function hasCommand(cmd: string): boolean {
31+
if (process.platform === "win32") return false;
3032
try {
31-
execSync("which pdftotext", { stdio: "ignore" });
33+
execSync(`which ${cmd}`, { stdio: "ignore" });
3234
return true;
3335
} catch {
3436
return false;
3537
}
3638
}
3739

38-
const skip = !hasPdftotext();
40+
const skip = !hasCommand("pdftotext") || !hasCommand("pdfinfo");
41+
42+
if (!skip) {
43+
// Tools available
44+
} else if (process.platform !== "win32") {
45+
const missing = ["pdftotext", "pdfinfo"]
46+
.filter((cmd) => !hasCommand(cmd))
47+
.join(", ");
48+
console.warn(
49+
`\n⚠️ WARNING: missing PDF tools (${missing}) — skipping content extraction tests.` +
50+
"\n Install with: sudo apt-get install poppler-utils\n",
51+
);
52+
}
53+
3954
const itP = skip ? it.skip : it;
4055

4156
describe("PDF content extraction (pdftotext)", () => {

tests/pdf-fonts.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const pdf: any = await import("../builtin-modules/pdf.js");
1515

1616
// ── Tool / Font Availability ─────────────────────────────────────────
1717

18-
/** Check if a command-line tool is available on this system. */
18+
/** Check if a command-line tool is available (cross-platform). */
1919
function hasCommand(cmd: string): boolean {
20+
if (process.platform === "win32") return false;
2021
try {
2122
execSync(`which ${cmd}`, { stdio: "ignore" });
2223
return true;

tests/pdf-visual.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const MAX_DIFF_PIXELS = 50; // fail if more than this many pixels differ
2828

2929
// ── Tool Availability ────────────────────────────────────────────────
3030

31-
/** Check if a command-line tool is available on this system. */
31+
/** Check if a command-line tool is available (cross-platform). */
3232
function hasCommand(cmd: string): boolean {
33+
if (process.platform === "win32") return false;
3334
try {
3435
execSync(`which ${cmd}`, { stdio: "ignore" });
3536
return true;

0 commit comments

Comments
 (0)