Fix code style in tests

Upgrade test dependencies
This commit is contained in:
Martin Endler
2020-01-24 22:31:14 +01:00
parent 9335a6ccc0
commit a43ad505f1
3 changed files with 363 additions and 1202 deletions

View File

@@ -3,6 +3,7 @@
<words> <words>
<w>pcsc</w> <w>pcsc</w>
<w>pcsclite</w> <w>pcsclite</w>
<w>picc</w>
</words> </words>
</dictionary> </dictionary>
</component> </component>

View File

@@ -1,19 +1,27 @@
const { describe, it } = require('mocha');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const pcsc = require('../lib/pcsclite'); const pcsc = require('../lib/pcsclite');
describe('Testing PCSCLite private', function () { describe('Testing PCSCLite private', function () {
describe('#start()', function () { describe('#start()', function () {
it('#start() stub', function (done) { it('#start() stub', function (done) {
var p = pcsc();
const p = pcsc();
try { try {
var stub = sinon.stub(p, 'start').callsFake(function(startCb) {
const stub = sinon.stub(p, 'start').callsFake(function (startCb) {
startCb(undefined, Buffer.from("ACS ACR122U PICC Interface\u0000ACS ACR122U PICC Interface 01\u0000\u0000")); startCb(undefined, Buffer.from("ACS ACR122U PICC Interface\u0000ACS ACR122U PICC Interface 01\u0000\u0000"));
}); });
var readerHit = 0; let readerHit = 0;
p.on('reader', function (reader) { p.on('reader', function (reader) {
reader.close(); reader.close();
switch (++readerHit) { switch (++readerHit) {
@@ -25,19 +33,23 @@ describe('Testing PCSCLite private', function() {
done(); done();
break; break;
} }
}); });
} finally { } finally {
p.close(); p.close();
} }
}); });
}); });
}); });
describe('Testing CardReader private', function () { describe('Testing CardReader private', function () {
var get_reader = function() { const get_reader = function () {
var p = pcsc(); const p = pcsc();
var stub = sinon.stub(p, 'start').callsFake(function(my_cb) { const stub = sinon.stub(p, 'start').callsFake(function (my_cb) {
/* "MyReader\0" */ /* "MyReader\0" */
my_cb(undefined, Buffer.from("MyReader\u0000\u0000")); my_cb(undefined, Buffer.from("MyReader\u0000\u0000"));
}); });
@@ -48,11 +60,9 @@ describe('Testing CardReader private', function() {
describe('#_connect()', function () { describe('#_connect()', function () {
it('#_connect() success', function (done) { it('#_connect() success', function (done) {
var p = get_reader(); const p = get_reader();
p.on('reader', function (reader) { p.on('reader', function (reader) {
var connect_stub = sinon.stub(reader, '_connect').callsFake(function(share_mode, const connect_stub = sinon.stub(reader, '_connect').callsFake(function (share_mode, protocol, connect_cb) {
protocol,
connect_cb) {
connect_cb(undefined, 1); connect_cb(undefined, 1);
}); });
@@ -65,12 +75,10 @@ describe('Testing CardReader private', function() {
}); });
it('#_connect() error', function (done) { it('#_connect() error', function (done) {
var p = get_reader(); const p = get_reader();
p.on('reader', function (reader) { p.on('reader', function (reader) {
var cb = sinon.spy(); const cb = sinon.spy();
var connect_stub = sinon.stub(reader, '_connect').callsFake(function(share_mode, const connect_stub = sinon.stub(reader, '_connect').callsFake(function (share_mode, protocol, connect_cb) {
protocol,
connect_cb) {
connect_cb(""); connect_cb("");
}); });
@@ -81,9 +89,9 @@ describe('Testing CardReader private', function() {
}); });
it('#_connect() already connected', function (done) { it('#_connect() already connected', function (done) {
var p = get_reader(); const p = get_reader();
p.on('reader', function (reader) { p.on('reader', function (reader) {
var cb = sinon.spy(); const cb = sinon.spy();
reader.connected = true; reader.connected = true;
reader.connect(cb); reader.connect(cb);
@@ -99,12 +107,11 @@ describe('Testing CardReader private', function() {
describe('#_disconnect()', function () { describe('#_disconnect()', function () {
it('#_disconnect() success', function (done) { it('#_disconnect() success', function (done) {
var p = get_reader(); const p = get_reader();
p.on('reader', function (reader) { p.on('reader', function (reader) {
reader.connected = true; reader.connected = true;
var cb = sinon.spy(); const cb = sinon.spy();
var connect_stub = sinon.stub(reader, '_disconnect').callsFake(function(disposition, const connect_stub = sinon.stub(reader, '_disconnect').callsFake(function (disposition, disconnect_cb) {
disconnect_cb) {
disconnect_cb(undefined); disconnect_cb(undefined);
}); });
@@ -115,11 +122,11 @@ describe('Testing CardReader private', function() {
}); });
it('#_disconnect() error', function (done) { it('#_disconnect() error', function (done) {
var p = get_reader(); const p = get_reader();
p.on('reader', function (reader) { p.on('reader', function (reader) {
reader.connected = true; reader.connected = true;
var cb = sinon.spy(); const cb = sinon.spy();
var connect_stub = sinon.stub(reader, '_disconnect').callsFake(function(disposition, const connect_stub = sinon.stub(reader, '_disconnect').callsFake(function (disposition,
disconnect_cb) { disconnect_cb) {
disconnect_cb(""); disconnect_cb("");
}); });
@@ -131,11 +138,10 @@ describe('Testing CardReader private', function() {
}); });
it('#_disconnect() already disconnected', function (done) { it('#_disconnect() already disconnected', function (done) {
var p = get_reader(); const p = get_reader();
p.on('reader', function (reader) { p.on('reader', function (reader) {
var cb = sinon.spy(); const cb = sinon.spy();
var connect_stub = sinon.stub(reader, '_disconnect').callsFake(function(disposition, const connect_stub = sinon.stub(reader, '_disconnect').callsFake(function (disposition, disconnect_cb) {
disconnect_cb) {
disconnect_cb(undefined); disconnect_cb(undefined);
}); });
@@ -147,4 +153,5 @@ describe('Testing CardReader private', function() {
}); });
}); });
}); });
}); });

1311
yarn.lock

File diff suppressed because it is too large Load Diff