Skip to content

Commit

Permalink
make serialport module as optional dependency #221 and fix test case
Browse files Browse the repository at this point in the history
 #
  • Loading branch information
lsongdev committed Aug 22, 2019
1 parent b05089a commit 2faf875
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 66 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_*
node_modules
*.sublime*
psd
thumb


*.log
yarn.lock
package-lock.json

node_modules/
2 changes: 1 addition & 1 deletion adapter/serial.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const util = require('util');
const EventEmitter = require('events');
const SerialPort = require('serialport');

/**
* SerialPort device
Expand All @@ -14,6 +13,7 @@ function Serial(port, options){
baudRate: 9600,
autoOpen: false
};
const SerialPort = require('serialport');
this.device = new SerialPort(port, options);
this.device.on('close', function() {
self.emit('disconnect', self.device);
Expand Down
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "ESC/POS Printer driver for nodejs",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha",
"start": "node server.js"
},
"repository": {
"type": "git",
Expand All @@ -14,11 +15,7 @@
"escpos",
"printer"
],
"author": {
"name": "Lsong",
"email": "[email protected]",
"url": "https://lsong.org"
},
"author": "Lsong <[email protected]> (https://lsong.org)",
"contributors": [
"Jose Vera <[email protected]>",
"Sébastien Vidal <[email protected]>",
Expand All @@ -33,20 +30,25 @@
},
"homepage": "https://github.com/song940/node-escpos#readme",
"dependencies": {
"qr-image": "*",
"get-pixels": "*",
"iconv-lite": "*",
"mutable-buffer": "^2.0.3"
},
"optionalDependencies": {
"get-pixels": "*",
"serialport": "*",
"qr-image": "*",
"usb": "*",
"serialport": "*",
"node-bluetooth": "*"
},
"devDependencies": {
"mocha": "*"
},
"engines": {
"node": ">=8.x"
},
"directories": {
"doc": "docs",
"example": "examples",
"test": "test"
}
}
54 changes: 3 additions & 51 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,15 @@ describe('ESC/POS printing test', function() {
assert.equal(data.length, 3);
done();
});
device.write(new Buffer(3));
device.write(Buffer.alloc(3));
})

it('printer#print', function(done){
var device = new escpos.Console(function(data){
assert.deepEqual(data, new Buffer('hello world'));
assert.deepEqual(data, Buffer.from('hello world'));
done();
});
var printer = new escpos.Printer(device);
printer.print('hello world').flush();
})

it('printer#print2', function(done){

const networkDevice = new escpos.Network('192.168.1.87', 9100);


const options = { encoding: "windows1254" /* default */ }
// encoding is optional

const printer = new escpos.Printer(networkDevice, options);



networkDevice.open(function(){
printer.tableCustom([ // Prints table with custom settings (text, align, width, cols,)
{ text:"Left", align:"LEFT", width:0.33 },
{ text:"Large Message for New Line ", align:"LEFT", width:0.33 },
{ text:"Right", align:"RIGHT", width:0.33 }
]);
printer.tableCustom([ // Prints table with custom settings (text, align, width, cols)
{ text:"Left", align:"LEFT", width:0.13 },
{ text:"Left", align:"LEFT", width:0.10 },
{ text:"Center", align:"CENTER", width:0.33 },
{ text:"Right", align:"RIGHT", width:0.33 }
]);
printer.drawLine();
printer.tableCustom([ // Prints table with custom settings (text, align, width, cols)
{ text:"Left", align:"LEFT", width:0.33 },
{ text:"Center", align:"CENTER", width:0.33},
{ text:"Right", align:"RIGHT", width:0.33 }
]);
printer.tableCustom([ // Prints table with custom settings (text, align, width, cols)
{ text:"Left", align:"LEFT", width:0.33 },
{ text:"Center", align:"CENTER", width:0.33 },
{ text:"Right", align:"RIGHT", width:0.33 }
]);
printer.newLine();
printer.newLine();
printer.newLine();
printer.newLine();
printer.cut();
printer.close();
printer.beep();

done();
});
})

});
});

0 comments on commit 2faf875

Please sign in to comment.