Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(index): tidy binary path definition #381

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

"use strict";

const { execFile } = require("node:child_process");
const { execFile, spawnSync } = require("node:child_process");
const { promisify } = require("node:util");
const isHtml = require("is-html");
const { gt, lt } = require("semver");
const { joinSafe } = require("upath");
const { joinSafe, normalizeTrim } = require("upath");
const generateCombos = require("../test_resources/utils/gen-combos");

const execFileAsync = promisify(execFile);
Expand All @@ -16,34 +16,26 @@ const { UnRTF } = require("./index");
const testDirectory = `${__dirname}/../test_resources/test_files/`;
const file = `${testDirectory}test-rtf-complex.rtf`;

let testBinaryPath;
switch (process.platform) {
// macOS
case "darwin":
if (process.arch === "arm64") {
testBinaryPath = "/opt/homebrew/bin";
} else {
testBinaryPath = "/usr/local/bin";
}
break;

case "linux":
testBinaryPath = "/usr/bin";
break;

// Windows OS
case "win32":
default:
testBinaryPath = joinSafe(
__dirname,
"lib",
"win32",
"unrtf-0.19.3",
"bin"
);
break;
/**
* @description Returns the path to the UnRTF binary based on the OS.
* @returns {string} The path to the UnRTF binary.
*/
function getTestBinaryPath() {
const { platform } = process;
const which = spawnSync(platform === "win32" ? "where" : "which", [
"unrtf",
]).stdout.toString();
let unrtfPath = /(.+)unrtf/u.exec(which)?.[1];

if (platform === "win32" && !unrtfPath) {
unrtfPath = joinSafe(__dirname, "lib", "win32", "unrtf-0.19.3", "bin");
}

return normalizeTrim(unrtfPath);
}

const testBinaryPath = getTestBinaryPath();

describe("Constructor", () => {
let platform;

Expand Down