Skip to content

Commit b5de17a

Browse files
authored
Merge pull request #184 from kuzzleio/browser-compatibility-fix
Browsers compatibility fix
2 parents e60778e + 8199d21 commit b5de17a

22 files changed

+324
-291
lines changed

.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
"yoda": [2, "never"]
5252
},
5353
"env": {
54-
"node": true,
55-
"mocha": true
54+
"browser": true
5655
},
5756
"parserOptions": {
5857
"ecmaVersion": 5

src/Kuzzle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ function Kuzzle (host, options, cb) {
265265
}
266266

267267
eventProperties.listeners.forEach(function (listener) {
268-
process.nextTick(function () {
268+
setTimeout(function () {
269269
listener.fn.apply(undefined, args);
270-
});
270+
}, 0);
271271
});
272272

273273
// Events without the 'lastEmitted' property can be emitted without minimum time between emissions

test/.eslintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"no-console": 0
88
},
99
"parserOptions": {
10-
"ecmaVersion": 6
10+
"ecmaVersion": 5
11+
},
12+
"env": {
13+
"browser": true,
14+
"mocha": true
1115
}
1216
}

test/Collection/constructor.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Collection constructor', function () {
3131
should(c.headers.someother).be.undefined();
3232
});
3333

34-
it('should promisify the right functions', () => {
34+
it('should promisify the right functions', function () {
3535
var
3636
kuzzle,
3737
dataCollection;

test/Collection/methods.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('Collection methods', function () {
129129
});
130130

131131
describe('#scroll', function () {
132-
beforeEach(() => {
132+
beforeEach(function () {
133133
kuzzle = new Kuzzle('foo', {defaultIndex: 'bar'});
134134
kuzzle.query = queryStub;
135135
emitted = false;
@@ -144,29 +144,29 @@ describe('Collection methods', function () {
144144
};
145145
});
146146

147-
it('should throw an error if no scrollId is set', () => {
147+
it('should throw an error if no scrollId is set', function () {
148148
var collection = kuzzle.collection(expectedQuery.collection);
149-
should(() => { collection.scroll(); }).throw('Collection.scroll: scrollId is required');
149+
should(function () { collection.scroll(); }).throw('Collection.scroll: scrollId is required');
150150
});
151151

152-
it('should throw an error if no scroll is provided', () => {
152+
it('should throw an error if no scroll is provided', function () {
153153
var collection = kuzzle.collection(expectedQuery.collection);
154-
should(() => { collection.scroll('scrollId'); }).throw('Collection.scroll: scroll is required');
154+
should(function () { collection.scroll('scrollId'); }).throw('Collection.scroll: scroll is required');
155155
});
156156

157-
it('should throw an error if no callback is given', () => {
157+
it('should throw an error if no callback is given', function () {
158158
var collection = kuzzle.collection(expectedQuery.collection);
159-
should(() => { collection.scroll('scrollId', {scroll: '1m'}); }).throw('Collection.scroll: a callback argument is required for read queries');
159+
should(function () { collection.scroll('scrollId', {scroll: '1m'}); }).throw('Collection.scroll: a callback argument is required for read queries');
160160
});
161161

162-
it('should parse the given parameters', done => {
162+
it('should parse the given parameters', function (done) {
163163
var
164164
queryScrollStub,
165165
collection = kuzzle.collection(expectedQuery.collection),
166166
scrollId = 'scrollId',
167167
filters = {},
168168
options = {scroll: '30s'},
169-
cb = () => {
169+
cb = function () {
170170
done();
171171
};
172172

@@ -628,7 +628,7 @@ describe('Collection methods', function () {
628628
should(emitted).be.true();
629629
});
630630

631-
it('should handle the from and size options', () => {
631+
it('should handle the from and size options', function () {
632632
var
633633
collection = kuzzle.collection('collection'),
634634
stub = sinon.stub(collection, 'search');
@@ -639,7 +639,7 @@ describe('Collection methods', function () {
639639
stub.restore();
640640
});
641641

642-
it('should handle the scroll options', () => {
642+
it('should handle the scroll options', function () {
643643
var
644644
collection = kuzzle.collection('collection'),
645645
stub = sinon.stub(collection, 'search');
@@ -650,7 +650,7 @@ describe('Collection methods', function () {
650650
stub.restore();
651651
});
652652

653-
it('should transfer error if any', done => {
653+
it('should transfer error if any', function (done) {
654654
var
655655
collection = kuzzle.collection('collection');
656656

test/CollectionMapping/methods.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('CollectionMapping methods', function () {
130130
should(emitted).be.true();
131131

132132
emitted = false;
133-
mapping.apply((err, res) => {
133+
mapping.apply(function (err, res) {
134134
should(emitted).be.true();
135135
should(err).be.exactly('foobar');
136136
should(res).be.undefined();
@@ -200,7 +200,7 @@ describe('CollectionMapping methods', function () {
200200
should(emitted).be.true();
201201

202202
emitted = false;
203-
mapping.refresh((err, res) => {
203+
mapping.refresh(function (err, res) {
204204
should(emitted).be.true();
205205
should(err).be.exactly('foobar');
206206
should(res).be.undefined();
@@ -213,7 +213,7 @@ describe('CollectionMapping methods', function () {
213213

214214
result = { result: {foobar: { mappings: { foo: { properties: { foo: {type: 'date'}}}}}}};
215215

216-
mapping.refresh((err, res) => {
216+
mapping.refresh(function (err, res) {
217217
should(emitted).be.true();
218218
should(err).be.an.Error();
219219
should(err.message).startWith('No mapping found for index');
@@ -227,7 +227,7 @@ describe('CollectionMapping methods', function () {
227227

228228
result = { result: {bar: { mappings: { foobar: { properties: { foo: {type: 'date'}}}}}}};
229229

230-
mapping.refresh((err, res) => {
230+
mapping.refresh(function (err, res) {
231231
should(emitted).be.true();
232232
should(err).be.an.Error();
233233
should(err.message).startWith('No mapping found for collection');
@@ -236,12 +236,12 @@ describe('CollectionMapping methods', function () {
236236
});
237237
});
238238

239-
it('should return an empty mapping if the stored mapping is empty', done => {
239+
it('should return an empty mapping if the stored mapping is empty', function (done) {
240240
var mapping = new CollectionMapping(dataCollection);
241241

242242
result = { result: {bar: { mappings: { foo: {}}}}};
243243

244-
mapping.refresh((err, res) => {
244+
mapping.refresh(function (err, res) {
245245
should(emitted).be.true();
246246
should(err).be.null();
247247
should(res).be.exactly(mapping);

test/MemoryStorage/constructor.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var
66
Kuzzle = rewire('../../src/Kuzzle');
77

88
describe('MemoryStorage constructor', function () {
9-
it('should initialize properties and return a valid MemoryStorage object', () => {
9+
it('should initialize properties and return a valid MemoryStorage object', function () {
1010
var
1111
kuzzle = new Kuzzle('foo'),
1212
ms;
@@ -24,7 +24,7 @@ describe('MemoryStorage constructor', function () {
2424
should(ms.headers.someother).be.undefined();
2525
});
2626

27-
it('should promisify all methods', () => {
27+
it('should promisify all methods', function () {
2828
var
2929
kuzzle,
3030
ms,
@@ -35,9 +35,13 @@ describe('MemoryStorage constructor', function () {
3535
kuzzle = new Kuzzle('foo');
3636
ms = new MemoryStorage(kuzzle);
3737

38-
functions = Object.getOwnPropertyNames(Object.getPrototypeOf(ms)).filter(p => (typeof ms[p] === 'function' && ['constructor', 'setHeaders'].indexOf(p) === -1));
38+
functions = Object.getOwnPropertyNames(Object.getPrototypeOf(ms)).filter(function (p) {
39+
return (typeof ms[p] === 'function' && ['constructor', 'setHeaders'].indexOf(p) === -1);
40+
});
41+
3942
should(functions.length).be.eql(119);
40-
functions.forEach(f => {
43+
44+
functions.forEach(function (f) {
4145
should(ms[f + 'Promise']).be.a.Function();
4246
});
4347

test/MemoryStorage/methods.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ var
33
Kuzzle = require('../stubs/kuzzle.stub'),
44
MemoryStorage = require('../../src/MemoryStorage');
55

6-
describe('MemoryStorage methods', () => {
6+
describe('MemoryStorage methods', function () {
77
var
88
kuzzle = new Kuzzle('foo'),
99
ms = new MemoryStorage(kuzzle);
1010

11-
describe('#regular case', () => {
12-
it('should parse the given arguments (no options)', () => {
13-
ms.append('foo', 'bar', (err, r) => {
11+
describe('#regular case', function () {
12+
it('should parse the given arguments (no options)', function () {
13+
ms.append('foo', 'bar', function (err, r) {
1414
should(r.args).match({
1515
controller: 'ms',
1616
action: 'append'
@@ -23,8 +23,8 @@ describe('MemoryStorage methods', () => {
2323
});
2424
});
2525

26-
it('should parse the given arguments (w options)', () => {
27-
ms.append('foo', 'bar', { queuable: true}, (err, r) => {
26+
it('should parse the given arguments (w options)', function () {
27+
ms.append('foo', 'bar', { queuable: true}, function (err, r) {
2828
should(r.args).match({
2929
controller: 'ms',
3030
action: 'append'
@@ -38,8 +38,8 @@ describe('MemoryStorage methods', () => {
3838
});
3939
});
4040

41-
it('should handle arguments with multiple cardinality', () => {
42-
ms.sinter('foo', (err, r) => {
41+
it('should handle arguments with multiple cardinality', function () {
42+
ms.sinter('foo', function (err, r) {
4343
should(r.args).match({
4444
controller: 'ms',
4545
action: 'sinter'
@@ -50,7 +50,7 @@ describe('MemoryStorage methods', () => {
5050
should.not.exist(r.query.body);
5151
});
5252

53-
ms.sinter(['foo', 'bar'], (err, r) => {
53+
ms.sinter(['foo', 'bar'], function (err, r) {
5454
should(r.args).match({
5555
controller: 'ms',
5656
action: 'sinter'
@@ -62,8 +62,8 @@ describe('MemoryStorage methods', () => {
6262
});
6363
});
6464

65-
describe('#functions with optional parameters', () => {
66-
it('should parse all given arguments', () => {
65+
describe('#functions with optional parameters', function () {
66+
it('should parse all given arguments', function () {
6767
ms.zadd('foo', {
6868
nx: true,
6969
xx: true,
@@ -75,7 +75,7 @@ describe('MemoryStorage methods', () => {
7575
{score: 's1', member: 'm1'},
7676
{score: 's2', member: 'm2'}
7777
]
78-
}, (err, r) => {
78+
}, function (err, r) {
7979
should(r.args).match({
8080
controller: 'ms',
8181
action: 'zadd'

test/Room/methods.test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const
1+
var
42
should = require('should'),
53
rewire = require('rewire'),
64
sinon = require('sinon'),
@@ -9,7 +7,7 @@ const
97
Room = rewire('../../src/Room');
108

119
describe('Room methods', function () {
12-
let
10+
var
1311
expectedQuery,
1412
error,
1513
result,
@@ -198,7 +196,7 @@ describe('Room methods', function () {
198196
it('should start dequeuing if subscribed successfully', function (done) {
199197
room.renew({}, function () {});
200198

201-
setTimeout(() => {
199+
setTimeout(function () {
202200
should(dequeued).be.true();
203201
done();
204202
}, 10);
@@ -221,7 +219,7 @@ describe('Room methods', function () {
221219
it('should register itself to Kuzzle and skip subscription if not connected', function (done) {
222220
kuzzle.state = 'foo';
223221
room.renew({}, function () {});
224-
setTimeout(() => {
222+
setTimeout(function () {
225223
should(dequeued).be.false();
226224
should(emitted).be.false();
227225
should(room.lastRenewal).be.null();
@@ -242,7 +240,7 @@ describe('Room methods', function () {
242240
room.renew({}, function () {});
243241
room.renew({}, function () {});
244242

245-
setTimeout(() => {
243+
setTimeout(function () {
246244
should(renewals).be.eql(1);
247245
should(room.lastRenewal).be.within(before, after);
248246
done();
@@ -321,7 +319,7 @@ describe('Room methods', function () {
321319
should(emitted).be.false();
322320
should(kuzzle.subscriptions.foobar).be.undefined();
323321
kuzzle.subscriptions.pending = {};
324-
setTimeout(() => {
322+
setTimeout(function () {
325323
should(emitted).be.true();
326324
done();
327325
}, 100);
@@ -336,7 +334,7 @@ describe('Room methods', function () {
336334
kuzzle.subscriptions.pending = {};
337335
kuzzle.subscriptions.foobar = {};
338336
kuzzle.subscriptions.foobar.foo = {};
339-
setTimeout(() => {
337+
setTimeout(function () {
340338
should(emitted).be.false();
341339
done();
342340
}, 100);
@@ -381,7 +379,7 @@ describe('Room methods', function () {
381379
});
382380

383381
describe('#notificationCallback', function () {
384-
let
382+
var
385383
notifCB = Room.__get__('notificationCallback'),
386384
room;
387385

@@ -402,7 +400,7 @@ describe('Room methods', function () {
402400
.have.length(1);
403401
});
404402

405-
it('should handle document notifications', () => {
403+
it('should handle document notifications', function () {
406404
notifCB.call(room, {
407405
controller: 'document',
408406
result: {
@@ -429,7 +427,7 @@ describe('Room methods', function () {
429427
.be.an.instanceOf(Document);
430428
});
431429

432-
it('should handle realtime publish notifications', () => {
430+
it('should handle realtime publish notifications', function () {
433431
notifCB.call(room, {
434432
controller: 'realtime',
435433
action: 'publish',
@@ -457,7 +455,7 @@ describe('Room methods', function () {
457455
.be.an.instanceOf(Document);
458456
});
459457

460-
it('should handle user notifications', () => {
458+
it('should handle user notifications', function () {
461459
notifCB.call(room, {
462460
controller: 'realtime',
463461
result: { count: 3 }
@@ -473,7 +471,7 @@ describe('Room methods', function () {
473471
});
474472
});
475473

476-
it('should delete the result from history if emitted by this instance', () => {
474+
it('should delete the result from history if emitted by this instance', function () {
477475
room.subscribeToSelf = true;
478476
kuzzle.requestHistory.bar = {};
479477
notifCB.call(room, {error: null, result: {}, action: 'foo', requestId: 'bar'});
@@ -498,7 +496,7 @@ describe('Room methods', function () {
498496
eventEmitted = null,
499497
context = {
500498
kuzzle: {
501-
emitEvent: event => {
499+
emitEvent: function (event) {
502500
eventEmitted = event;
503501
}
504502
}

0 commit comments

Comments
 (0)