Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
printer specs, fix restart lpq watcher when it exit
Browse files Browse the repository at this point in the history
  • Loading branch information
alepee committed Jul 8, 2015
1 parent 5e60abe commit bf70ef4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
6 changes: 1 addition & 5 deletions job.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ function Job(lp) {
});
}

Job.prototype.setStatus = function(status) {
Job.prototype.update = function(status) {
this.status = status;
this.emit('updated', status);
};

Job.prototype.getStatus = function() {
return this.status;
};

Job.prototype.unqueue = function() {
if (this.status.rank === 'active') {
this.status.rank = 'completed';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-printer",
"description": "Tool to send data to printer using CUPS. All lp options are supported.",
"description": "Create and manage one or multiple printers (w/ CUPS), send file path or node buffer with support for all lp options. Get feedback on jobs you sent.",
"version": "1.0.0",
"homepage": "http://github.com/alepee/node-printer",
"keywords": [
Expand Down
22 changes: 12 additions & 10 deletions printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,13 @@ var parseStdout = function(data) {

function Printer(name) {
var self = this;
if (!Printer.match(name))
throw new TypeError(name + ' printer does not exist ; installed printers are ' + Printer.list());
if (!Printer.match(name)) {
console.error(
name + ' printer does not exist ; installed printers are ' + Printer.list()
);
}
self.name = name;
self.jobs = [];

self.on('watched', function() {
self.watch();
});
self.watch();
}

Expand Down Expand Up @@ -320,12 +319,15 @@ Printer.prototype.watch = function() {
})[0];

if (status) {
job.setStatus(status);
} else {
job.update(status);
} else if (job.status.rank === 'active') {
job.unqueue();
}
});
self.emit('watched');
});

lpq.on('exit', function() {
self.watch();
});
};

Expand Down Expand Up @@ -363,7 +365,7 @@ Printer.prototype.printFile = function(filePath, options) {
var job = new Job(lp);
job.on('sent', function() {
self.jobs.push(job);
})
});

return job;
};
Expand Down
4 changes: 1 addition & 3 deletions spec/printer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ var Printer = require('../printer.js');

describe('get list of installed printers', function() {
var list = Printer.list();
if (!list.length) return;

it('should return a list of printers name', function() {
expect(list.length > 0).toBe(true);
expect(list.constructor).toBe(Array);
});

it('should verify printer existance', function() {
expect(Printer.match(list[0])).toBe(true);
expect(Printer.match('fakePrinterName')).toBe(false);
});
});

0 comments on commit bf70ef4

Please sign in to comment.