Fix code style in tests
Upgrade test dependencies
This commit is contained in:
1
.idea/dictionaries/pokusew.xml
generated
1
.idea/dictionaries/pokusew.xml
generated
@@ -3,6 +3,7 @@
|
||||
<words>
|
||||
<w>pcsc</w>
|
||||
<w>pcsclite</w>
|
||||
<w>picc</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
253
test/test.js
253
test/test.js
@@ -1,150 +1,157 @@
|
||||
const { describe, it } = require('mocha');
|
||||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
|
||||
const pcsc = require('../lib/pcsclite');
|
||||
|
||||
describe('Testing PCSCLite private', function() {
|
||||
describe('#start()', function() {
|
||||
it('#start() stub', function(done) {
|
||||
var p = pcsc();
|
||||
|
||||
try {
|
||||
var stub = sinon.stub(p, 'start').callsFake(function(startCb) {
|
||||
startCb(undefined, Buffer.from("ACS ACR122U PICC Interface\u0000ACS ACR122U PICC Interface 01\u0000\u0000"));
|
||||
});
|
||||
describe('Testing PCSCLite private', function () {
|
||||
|
||||
var readerHit = 0;
|
||||
p.on('reader', function(reader) {
|
||||
reader.close();
|
||||
describe('#start()', function () {
|
||||
it('#start() stub', function (done) {
|
||||
|
||||
const p = pcsc();
|
||||
|
||||
try {
|
||||
|
||||
const stub = sinon.stub(p, 'start').callsFake(function (startCb) {
|
||||
startCb(undefined, Buffer.from("ACS ACR122U PICC Interface\u0000ACS ACR122U PICC Interface 01\u0000\u0000"));
|
||||
});
|
||||
|
||||
let readerHit = 0;
|
||||
|
||||
p.on('reader', function (reader) {
|
||||
|
||||
reader.close();
|
||||
|
||||
switch (++readerHit) {
|
||||
case 1:
|
||||
reader.name.should.equal("ACS ACR122U PICC Interface");
|
||||
break;
|
||||
case 2:
|
||||
reader.name.should.equal("ACS ACR122U PICC Interface 01");
|
||||
done();
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
} finally {
|
||||
p.close();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
switch (++readerHit) {
|
||||
case 1:
|
||||
reader.name.should.equal("ACS ACR122U PICC Interface");
|
||||
break;
|
||||
case 2:
|
||||
reader.name.should.equal("ACS ACR122U PICC Interface 01");
|
||||
done();
|
||||
break;
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
p.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Testing CardReader private', function() {
|
||||
describe('Testing CardReader private', function () {
|
||||
|
||||
var get_reader = function() {
|
||||
var p = pcsc();
|
||||
var stub = sinon.stub(p, 'start').callsFake(function(my_cb) {
|
||||
/* "MyReader\0" */
|
||||
my_cb(undefined, Buffer.from("MyReader\u0000\u0000"));
|
||||
});
|
||||
const get_reader = function () {
|
||||
const p = pcsc();
|
||||
const stub = sinon.stub(p, 'start').callsFake(function (my_cb) {
|
||||
/* "MyReader\0" */
|
||||
my_cb(undefined, Buffer.from("MyReader\u0000\u0000"));
|
||||
});
|
||||
|
||||
return p;
|
||||
};
|
||||
return p;
|
||||
};
|
||||
|
||||
describe('#_connect()', function() {
|
||||
describe('#_connect()', function () {
|
||||
|
||||
it('#_connect() success', function(done) {
|
||||
var p = get_reader();
|
||||
p.on('reader', function(reader) {
|
||||
var connect_stub = sinon.stub(reader, '_connect').callsFake(function(share_mode,
|
||||
protocol,
|
||||
connect_cb) {
|
||||
connect_cb(undefined, 1);
|
||||
});
|
||||
it('#_connect() success', function (done) {
|
||||
const p = get_reader();
|
||||
p.on('reader', function (reader) {
|
||||
const connect_stub = sinon.stub(reader, '_connect').callsFake(function (share_mode, protocol, connect_cb) {
|
||||
connect_cb(undefined, 1);
|
||||
});
|
||||
|
||||
reader.connect(function(err, protocol) {
|
||||
should.not.exist(err);
|
||||
protocol.should.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
reader.connect(function (err, protocol) {
|
||||
should.not.exist(err);
|
||||
protocol.should.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('#_connect() error', function(done) {
|
||||
var p = get_reader();
|
||||
p.on('reader', function(reader) {
|
||||
var cb = sinon.spy();
|
||||
var connect_stub = sinon.stub(reader, '_connect').callsFake(function(share_mode,
|
||||
protocol,
|
||||
connect_cb) {
|
||||
connect_cb("");
|
||||
});
|
||||
it('#_connect() error', function (done) {
|
||||
const p = get_reader();
|
||||
p.on('reader', function (reader) {
|
||||
const cb = sinon.spy();
|
||||
const connect_stub = sinon.stub(reader, '_connect').callsFake(function (share_mode, protocol, connect_cb) {
|
||||
connect_cb("");
|
||||
});
|
||||
|
||||
reader.connect(cb);
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
reader.connect(cb);
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#_connect() already connected', function(done) {
|
||||
var p = get_reader();
|
||||
p.on('reader', function(reader) {
|
||||
var cb = sinon.spy();
|
||||
reader.connected = true;
|
||||
it('#_connect() already connected', function (done) {
|
||||
const p = get_reader();
|
||||
p.on('reader', function (reader) {
|
||||
const cb = sinon.spy();
|
||||
reader.connected = true;
|
||||
|
||||
reader.connect(cb);
|
||||
process.nextTick(function () {
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
reader.connect(cb);
|
||||
process.nextTick(function () {
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('#_disconnect()', function() {
|
||||
describe('#_disconnect()', function () {
|
||||
|
||||
it('#_disconnect() success', function(done) {
|
||||
var p = get_reader();
|
||||
p.on('reader', function(reader) {
|
||||
reader.connected = true;
|
||||
var cb = sinon.spy();
|
||||
var connect_stub = sinon.stub(reader, '_disconnect').callsFake(function(disposition,
|
||||
disconnect_cb) {
|
||||
disconnect_cb(undefined);
|
||||
});
|
||||
it('#_disconnect() success', function (done) {
|
||||
const p = get_reader();
|
||||
p.on('reader', function (reader) {
|
||||
reader.connected = true;
|
||||
const cb = sinon.spy();
|
||||
const connect_stub = sinon.stub(reader, '_disconnect').callsFake(function (disposition, disconnect_cb) {
|
||||
disconnect_cb(undefined);
|
||||
});
|
||||
|
||||
reader.disconnect(cb);
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
reader.disconnect(cb);
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#_disconnect() error', function(done) {
|
||||
var p = get_reader();
|
||||
p.on('reader', function(reader) {
|
||||
reader.connected = true;
|
||||
var cb = sinon.spy();
|
||||
var connect_stub = sinon.stub(reader, '_disconnect').callsFake(function(disposition,
|
||||
disconnect_cb) {
|
||||
disconnect_cb("");
|
||||
});
|
||||
it('#_disconnect() error', function (done) {
|
||||
const p = get_reader();
|
||||
p.on('reader', function (reader) {
|
||||
reader.connected = true;
|
||||
const cb = sinon.spy();
|
||||
const connect_stub = sinon.stub(reader, '_disconnect').callsFake(function (disposition,
|
||||
disconnect_cb) {
|
||||
disconnect_cb("");
|
||||
});
|
||||
|
||||
reader.disconnect(cb);
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
reader.disconnect(cb);
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#_disconnect() already disconnected', function(done) {
|
||||
var p = get_reader();
|
||||
p.on('reader', function(reader) {
|
||||
var cb = sinon.spy();
|
||||
var connect_stub = sinon.stub(reader, '_disconnect').callsFake(function(disposition,
|
||||
disconnect_cb) {
|
||||
disconnect_cb(undefined);
|
||||
});
|
||||
it('#_disconnect() already disconnected', function (done) {
|
||||
const p = get_reader();
|
||||
p.on('reader', function (reader) {
|
||||
const cb = sinon.spy();
|
||||
const connect_stub = sinon.stub(reader, '_disconnect').callsFake(function (disposition, disconnect_cb) {
|
||||
disconnect_cb(undefined);
|
||||
});
|
||||
|
||||
reader.disconnect(cb);
|
||||
process.nextTick(function () {
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
reader.disconnect(cb);
|
||||
process.nextTick(function () {
|
||||
sinon.assert.calledOnce(cb);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user