Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Fix printing method (#72)
Browse files Browse the repository at this point in the history
* fix printing

* 1.1.1-beta.0

* fix options

* Revert "1.1.1-beta.0"

This reverts commit f454ca5.
  • Loading branch information
artiebits authored Nov 24, 2019
1 parent 6fccd7d commit c32ed24
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions __test__/unix/print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test("sends PDF file to the specific printer", () => {
printer
};
return print(filename, options).then(() => {
expect(execAsync).toHaveBeenCalledWith("lp", [filename, `-d ${printer}`]);
expect(execAsync).toHaveBeenCalledWith("lp", [filename, "-d", printer]);
});
});

Expand All @@ -61,8 +61,10 @@ test("allows users to pass OS specific options", () => {
return print(filename, options).then(() => {
expect(execAsync).toHaveBeenCalledWith("lp", [
filename,
`-d ${printer}`,
"-o sides=one-sided"
"-d",
printer,
"-o",
"sides=one-sided"
]);
});
});
Expand Down
3 changes: 2 additions & 1 deletion __test__/win32/print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ test("allows users to pass OS specific options", () => {
expect(execAsync).toHaveBeenCalledWith("mocked_path_SumatraPDF.exe", [
"-print-to",
printer,
'-print-settings "1,2,fit"',
"-print-settings",
'"1,2,fit"',
"-silent",
filename
]);
Expand Down
4 changes: 2 additions & 2 deletions src/unix/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const print = (pdf, options = {}) => {
const { printer, unix } = options;

if (printer) {
args.push(`-d ${printer}`);
args.push("-d", printer);
}

if (unix) {
if (!Array.isArray(unix)) throw "options.unix should be an array";
unix.map(unixArg => args.push(unixArg));
unix.map(unixArg => args.push(...unixArg.split(" ")));
}

return execAsync("lp", args);
Expand Down
3 changes: 2 additions & 1 deletion src/win32/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const print = (pdf, options = {}) => {
} else {
args.push("-print-to-default");
}

if (win32) {
if (!Array.isArray(win32)) throw "options.win32 should be an array";
win32.map(win32Arg => args.push(win32Arg));
win32.map(win32Arg => args.push(...win32Arg.split(" ")));
}

args.push("-silent", pdf);
Expand Down

0 comments on commit c32ed24

Please sign in to comment.