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,150 +1,157 @@
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('#start()', function() {
it('#start() stub', function(done) {
var p = pcsc();
try { describe('Testing PCSCLite private', function () {
var stub = sinon.stub(p, 'start').callsFake(function(startCb) {
startCb(undefined, Buffer.from("ACS ACR122U PICC Interface\u0000ACS ACR122U PICC Interface 01\u0000\u0000"));
});
var readerHit = 0; describe('#start()', function () {
p.on('reader', function(reader) { it('#start() stub', function (done) {
reader.close();
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() { 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"));
}); });
return p; return p;
}; };
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(undefined, 1);
connect_cb) { });
connect_cb(undefined, 1);
});
reader.connect(function(err, protocol) { reader.connect(function (err, protocol) {
should.not.exist(err); should.not.exist(err);
protocol.should.equal(1); protocol.should.equal(1);
done(); done();
}); });
}); });
}); });
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("");
});
reader.connect(cb); reader.connect(cb);
sinon.assert.calledOnce(cb); sinon.assert.calledOnce(cb);
done(); done();
}); });
}); });
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);
process.nextTick(function () { process.nextTick(function () {
sinon.assert.calledOnce(cb); sinon.assert.calledOnce(cb);
done(); done();
}); });
}); });
}); });
}); });
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); });
});
reader.disconnect(cb); reader.disconnect(cb);
sinon.assert.calledOnce(cb); sinon.assert.calledOnce(cb);
done(); done();
}); });
}); });
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("");
}); });
reader.disconnect(cb); reader.disconnect(cb);
sinon.assert.calledOnce(cb); sinon.assert.calledOnce(cb);
done(); done();
}); });
}); });
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); });
});
reader.disconnect(cb);
process.nextTick(function () {
sinon.assert.calledOnce(cb);
done();
});
});
});
});
reader.disconnect(cb);
process.nextTick(function () {
sinon.assert.calledOnce(cb);
done();
});
});
});
});
}); });

1311
yarn.lock

File diff suppressed because it is too large Load Diff