Skip to content

Commit c9c7ee0

Browse files
authored
Merge branch 'develop' into develop-event-queryerror
2 parents 7e0551e + 9e71368 commit c9c7ee0

File tree

7 files changed

+47
-24
lines changed

7 files changed

+47
-24
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ addons:
1111
- g++-4.9
1212
script:
1313
- npm run build && npm test && cat ./coverage/lcov.info | ./node_modules/.bin/codecov
14+
- chmod 755 ${TRAVIS_BUILD_DIR}/deploy.sh && sh -c "${TRAVIS_BUILD_DIR}/deploy.sh"
1415
before_install:
1516
- export CC="gcc-4.9" CXX="g++-4.9"
1617
install:
1718
- npm install
18-
after_success:
19-
- chmod 755 ${TRAVIS_BUILD_DIR}/deploy.sh && sh -c "${TRAVIS_BUILD_DIR}/deploy.sh"
2019
env:
2120
global:
2221
secure: EZ+XXJFDtehmag7wt8JbutqgzpkkJUCzkEWw6W+p7MIxWenLyuGv/RUu7KGqAloOud1cZbmZGSfRx/vsPvxRjo+ZC7aaPqb74qRvfctGdlJTtEffS2jFno1pEppJzCR4n7vocSfMVYtOD6oHP67lXwn/Qnh++WUkZaV137m5+7rqiYgJ+JTeSs5jBRZ6X7VNoNz8tZXejQ+FOymCFQTS2JM/rSZX9NEK+OwUEhEjRcxqWMm2avk6NAQNAL3WQuIBJQH8lxEJxOXkMc0rQZZ09AoLpqJKzsaicaZMInt5JstPo2e9vJfhi+PpRSNhErIff36aCHWRYYDPKl5x6IelZpBfZeTdrs4V2TbRi1y0ELbgMG1FHS4HAw3vTnh4/49g01lAJed4UguFRc6MzwTLAL8uPG/zFe8snm9+kaf4pL7yO89Hf3eltE03+N//tyVv+X/jdSca2dBZ9FMeLE5pJ2jlRiKitCLjXmLUEMMxEwNF7K/IvOrD9wue3JXK0UogOpcXfppk++pNTijsZluU1Yj7k3fGFeS8d6rIU0Yj40y6/VMaJeL4EXlARRsGLigUKVjQL6+/N5xudlsCng+EG+WVIy4wEEPH0QgjUkPTgWx1NrUlTwjskE0cdqDOBu39WkRFJHHECYFPTfTuDJ7xxuuibFTQmUFu2zjbYfYKhPE=
2322
deploy:
2423
provider: npm
24+
skip_cleanup: true
2525
email: support@kuzzle.io
2626
api_key:
2727
secure: 3EACVlwZMonqJEl5OVcr1KnV6xg73Is7mILWzLM2i9ZdECHiv3ViQ7uAX24oSpxlDJEdqJ+1UO5uNMqJmGW3k+DDXGWaTSOf5bIOvPPTytUGQMedNucbhF4y0NytO8bfuMFx1Kr2tNcl1db6iLt7LO6lFl1uGcpMiaf2B8dpi3+f+WBAErMkPg3yNXcOMENSml/rt5iJFmF5pBHFAJ5D3CaoUGdqZXeFXNA/Zdhxt0BCpkOnt83+dYSLfIIIS2XZw1fM3lWXndWVQDiRFZWJZjp6PfSKDFmFyxxXmcYDOkzx/YecZtN2BCBzwsjq6C5mgN2GGW/WCk1munYCWrWCLc95LExoolQRuxsIDB1le22GNUNOzrTlZRPLruuFmwDAJc9Z05EcMnv2O74oHqfsRpYoSlWFDWlJEgtJyGjex2EP8W+jYNyMJumD/ywY/xXY4MDQPfaYt38KZECAHPbWCUA4zDbFDMMcAfdPhayLtkQYzTRE4Q5+aYbxd7bQi0c1AoM26BSDVkK8+W+dncu/5L0+mLQOqL5cJJtxVSQhuYSEV/h7Vgt77NOimZOSBxn2PNhf5AII0XDIN/Y1DLMCxgSATvkRmjEwr6qe1bcAik4vpK76qPkg8TMUQryY5s4J/qSBC4K53JER/PUiGO9JM7eYDktHnLlnKFgnY8YD+8I=

dist/kuzzle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kuzzle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "2.1.0",
3+
"version": "2.1.2",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/kuzzle.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@ module.exports = Kuzzle = function (host, options, cb) {
110110
},
111111
host: {
112112
value: host,
113+
writable: true,
113114
enumerable: true
114115
},
115116
wsPort: {
116117
value: (options && typeof options.wsPort === 'number') ? options.wsPort : 7513,
117-
enumerable: true
118+
enumerable: true,
119+
writable: true
118120
},
119121
ioPort: {
120122
value: (options && typeof options.ioPort === 'number') ? options.ioPort : 7512,
121-
enumerable: true
123+
enumerable: true,
124+
writable: true
122125
},
123126
sslConnection: {
124127
value: (options && typeof options.sslConnection === 'boolean') ? options.sslConnection : false,
@@ -315,10 +318,12 @@ module.exports = Kuzzle = function (host, options, cb) {
315318
Kuzzle.prototype.connect = function () {
316319
var self = this;
317320

318-
if (!self.network) {
319-
self.network = networkWrapper(self.host, self.wsPort, self.ioPort, self.sslConnection);
321+
if (self.network) {
322+
self.disconnect();
320323
}
321324

325+
self.network = networkWrapper(self.host, self.wsPort, self.ioPort, self.sslConnection);
326+
322327
if (['initializing', 'ready', 'disconnected', 'error', 'offline'].indexOf(this.state) === -1) {
323328
if (self.connectCB) {
324329
self.connectCB(null, self);
@@ -1005,6 +1010,7 @@ Kuzzle.prototype.disconnect = function () {
10051010

10061011
this.state = 'disconnected';
10071012
this.network.close();
1013+
this.network = null;
10081014

10091015
for (collection in this.collections) {
10101016
if (this.collections.hasOwnProperty(collection)) {

test/kuzzle/constructor.test.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ describe('Kuzzle constructor', () => {
6969
should(kuzzle).have.propertyWithDescriptor('reconnectionDelay', { enumerable: true, writable: false, configurable: false });
7070
should(kuzzle).have.propertyWithDescriptor('jwtToken', { enumerable: true, writable: true, configurable: false });
7171
should(kuzzle).have.propertyWithDescriptor('offlineQueueLoader', { enumerable: true, writable: true, configurable: false });
72-
should(kuzzle).have.propertyWithDescriptor('wsPort', { enumerable: true, writable: false, configurable: false });
73-
should(kuzzle).have.propertyWithDescriptor('ioPort', { enumerable: true, writable: false, configurable: false });
72+
should(kuzzle).have.propertyWithDescriptor('wsPort', { enumerable: true, writable: true, configurable: false });
73+
should(kuzzle).have.propertyWithDescriptor('ioPort', { enumerable: true, writable: true, configurable: false });
7474
should(kuzzle).have.propertyWithDescriptor('sslConnection', { enumerable: true, writable: false, configurable: false });
7575
});
7676

@@ -291,6 +291,20 @@ describe('Kuzzle constructor', () => {
291291
}, 10);
292292
});
293293

294+
it('should first disconnect if it was connected', function () {
295+
var
296+
kuzzle = new Kuzzle('nowhere', {connect: 'manual'}),
297+
disconnectStub = sinon.stub();
298+
299+
kuzzle.disconnect = disconnectStub;
300+
kuzzle.connect();
301+
302+
should(kuzzle.disconnect.called).be.false();
303+
304+
kuzzle.connect();
305+
should(kuzzle.disconnect.called).be.true();
306+
});
307+
294308
describe('=> on connection error', () => {
295309
beforeEach(function () {
296310
networkStub.onConnectError = function (cb) {
@@ -382,22 +396,25 @@ describe('Kuzzle constructor', () => {
382396

383397
it('should dequeue requests automatically on a connection success', function (done) {
384398
var
385-
dequeued = false,
386-
kuzzle,
387-
KuzzleRewired = rewire(kuzzleSource),
388-
revert = KuzzleRewired.__set__('dequeue', function () { dequeued = true; });
399+
dequeueStub = sinon.stub(),
400+
kuzzle;
389401

390402
this.timeout(500);
391403

392-
kuzzle = new KuzzleRewired('nowhere', {connect: 'manual', autoReplay: false, autoQueue: false}, () => {
393-
should(kuzzle.state).be.exactly('connected');
394-
should(dequeued).be.true();
395-
revert();
396-
done();
397-
});
404+
kuzzle = new Kuzzle('nowhere', {connect: 'manual', autoReplay: false, autoQueue: false});
398405

399-
kuzzle.network = networkStub;
406+
kuzzle.queuing = true;
407+
kuzzle.offlineQueue.push({query: 'foo'});
408+
kuzzle.addListener('offlineQueuePop', dequeueStub);
400409
kuzzle.connect();
410+
411+
setTimeout(function () {
412+
should(dequeueStub.called).be.true();
413+
should(kuzzle.state).be.exactly('connected');
414+
should(kuzzle.queuing).be.false();
415+
should(kuzzle.offlineQueue).be.empty();
416+
done();
417+
}, 20);
401418
});
402419
});
403420

test/kuzzle/methods.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ describe('Kuzzle methods', function () {
399399
kuzzle.collections = { foo: {}, bar: {}, baz: {} };
400400
kuzzle.disconnect();
401401

402-
should(kuzzle.network.close.called).be.true();
402+
should(kuzzle.network).be.null();
403403
should(kuzzle.collections).be.empty();
404404
should(function () { kuzzle.isValid(); }).throw(Error);
405405
});

0 commit comments

Comments
 (0)