From 6925374c2f5de7e9d6993d7b6430b24af6cf3969 Mon Sep 17 00:00:00 2001 From: artiebits Date: Fri, 21 May 2021 12:49:33 +0200 Subject: [PATCH] fix print --- src/unix/print.js | 2 +- src/unix/print.test.js | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/unix/print.js b/src/unix/print.js index b637cea..828999b 100644 --- a/src/unix/print.js +++ b/src/unix/print.js @@ -25,7 +25,7 @@ const print = (pdf, options = {}) => { .forEach((arg) => args.push(arg)); } - return execAsync("lp", args); + return execAsync(`lp ${args.join(" ")}`); }; module.exports = print; diff --git a/src/unix/print.test.js b/src/unix/print.test.js index 3477b1c..93c336e 100644 --- a/src/unix/print.test.js +++ b/src/unix/print.test.js @@ -39,7 +39,7 @@ test("throws if PDF doesn't exist", () => { test("sends the PDF file to the default printer", () => { const filename = "assets/pdf-sample.pdf"; return print(filename).then(() => { - expect(execAsync).toHaveBeenCalledWith("lp", [filename]); + expect(execAsync).toHaveBeenCalledWith(`lp ${filename}`); }); }); @@ -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}`); }); }); @@ -59,7 +59,7 @@ test("sends PDF file to the specific printer with a space in its name", () => { const printer = "Brother HL-L2340WD"; const options = { printer }; return print(filename, options).then(() => { - expect(execAsync).toHaveBeenCalledWith("lp", [filename, "-d", printer]); + expect(execAsync).toHaveBeenCalledWith(`lp ${filename} -d ${printer}`); }); }); @@ -68,13 +68,9 @@ test("allows users to pass OS specific options", () => { const printer = "Zebra"; const options = { printer, unix: ["-o sides=one-sided"] }; return print(filename, options).then(() => { - expect(execAsync).toHaveBeenCalledWith("lp", [ - filename, - "-d", - printer, - "-o", - "sides=one-sided", - ]); + expect(execAsync).toHaveBeenCalledWith( + `lp ${filename} -d ${printer} -o sides=one-sided` + ); }); });