Skip to content

Commit

Permalink
Merge pull request #156 from Fdawgs/fix/message
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Nov 30, 2021
2 parents fc420c9 + 996d3a4 commit aec11c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/index.js
Expand Up @@ -75,15 +75,18 @@ class UnRTF {
constructor(binPath) {
if (binPath) {
this.unrtfPath = path.normalizeTrim(binPath);
} else {
// If not set, expect user to be using Win32
} else if (process.platform === "win32") {
this.unrtfPath = path.joinSafe(
__dirname,
"lib",
"win32",
"unrtf-0.19.3",
"bin"
);
} else {
throw new Error(
`${process.platform} UnRTF binaries are not provided, please pass the installation directory as a parameter to the UnRTF instance.`
);
}
}

Expand Down
28 changes: 20 additions & 8 deletions src/index.test.js
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable security/detect-child-process */
/* eslint-disable security/detect-non-literal-fs-filename */
const isHtml = require("is-html");
const os = require("os");
const path = require("upath");
const semver = require("semver");
const { execFile } = require("child_process");
Expand All @@ -15,8 +14,7 @@ const testDirectory = `${__dirname}/../test_files/`;
const file = `${testDirectory}test-rtf-complex.rtf`;

let testBinaryPath;
const platform = os.platform();
switch (platform) {
switch (process.platform) {
// macOS
case "darwin":
testBinaryPath = "/usr/local/bin";
Expand All @@ -39,9 +37,9 @@ switch (platform) {
break;
}

if (platform === "win32") {
describe("Constructor", () => {
test("Should convert RTF file to HTML without binary set, and use included Windows binary", async () => {
describe("Constructor", () => {
if (process.platform === "win32") {
test("Should convert RTF file to HTML without binary set on win32, and use included binary", async () => {
const unRtf = new UnRTF();
const options = {
noPictures: true,
Expand All @@ -53,8 +51,22 @@ if (platform === "win32") {
expect(typeof res).toBe("string");
expect(res.substring(0, 6)).toBe("<html>");
});
});
}
}

if (process.platform !== "win32") {
test(`Should return an Error object if binary path unset on ${process.platform}`, async () => {
expect.assertions(1);
try {
// eslint-disable-next-line no-unused-vars
const unRtf = new UnRTF();
} catch (err) {
expect(err.message).toBe(
`${process.platform} UnRTF binaries are not provided, please pass the installation directory as a parameter to the UnRTF instance.`
);
}
});
}
});

describe("Convert Function", () => {
let version;
Expand Down

0 comments on commit aec11c3

Please sign in to comment.