Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
"yoda": [2, "never"]
},
"env": {
"node": true,
"mocha": true
"browser": true
},
"parserOptions": {
"ecmaVersion": 5
Expand Down
4 changes: 2 additions & 2 deletions src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ function Kuzzle (host, options, cb) {
}

eventProperties.listeners.forEach(function (listener) {
process.nextTick(function () {
setTimeout(function () {
listener.fn.apply(undefined, args);
});
}, 0);
});

// Events without the 'lastEmitted' property can be emitted without minimum time between emissions
Expand Down
6 changes: 5 additions & 1 deletion test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"no-console": 0
},
"parserOptions": {
"ecmaVersion": 6
"ecmaVersion": 5
},
"env": {
"browser": true,
"mocha": true
}
}
2 changes: 1 addition & 1 deletion test/Collection/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Collection constructor', function () {
should(c.headers.someother).be.undefined();
});

it('should promisify the right functions', () => {
it('should promisify the right functions', function () {
var
kuzzle,
dataCollection;
Expand Down
24 changes: 12 additions & 12 deletions test/Collection/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Collection methods', function () {
});

describe('#scroll', function () {
beforeEach(() => {
beforeEach(function () {
kuzzle = new Kuzzle('foo', {defaultIndex: 'bar'});
kuzzle.query = queryStub;
emitted = false;
Expand All @@ -144,29 +144,29 @@ describe('Collection methods', function () {
};
});

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

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

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

it('should parse the given parameters', done => {
it('should parse the given parameters', function (done) {
var
queryScrollStub,
collection = kuzzle.collection(expectedQuery.collection),
scrollId = 'scrollId',
filters = {},
options = {scroll: '30s'},
cb = () => {
cb = function () {
done();
};

Expand Down Expand Up @@ -628,7 +628,7 @@ describe('Collection methods', function () {
should(emitted).be.true();
});

it('should handle the from and size options', () => {
it('should handle the from and size options', function () {
var
collection = kuzzle.collection('collection'),
stub = sinon.stub(collection, 'search');
Expand All @@ -639,7 +639,7 @@ describe('Collection methods', function () {
stub.restore();
});

it('should handle the scroll options', () => {
it('should handle the scroll options', function () {
var
collection = kuzzle.collection('collection'),
stub = sinon.stub(collection, 'search');
Expand All @@ -650,7 +650,7 @@ describe('Collection methods', function () {
stub.restore();
});

it('should transfer error if any', done => {
it('should transfer error if any', function (done) {
var
collection = kuzzle.collection('collection');

Expand Down
12 changes: 6 additions & 6 deletions test/CollectionMapping/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('CollectionMapping methods', function () {
should(emitted).be.true();

emitted = false;
mapping.apply((err, res) => {
mapping.apply(function (err, res) {
should(emitted).be.true();
should(err).be.exactly('foobar');
should(res).be.undefined();
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('CollectionMapping methods', function () {
should(emitted).be.true();

emitted = false;
mapping.refresh((err, res) => {
mapping.refresh(function (err, res) {
should(emitted).be.true();
should(err).be.exactly('foobar');
should(res).be.undefined();
Expand All @@ -213,7 +213,7 @@ describe('CollectionMapping methods', function () {

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

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

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

mapping.refresh((err, res) => {
mapping.refresh(function (err, res) {
should(emitted).be.true();
should(err).be.an.Error();
should(err.message).startWith('No mapping found for collection');
Expand All @@ -236,12 +236,12 @@ describe('CollectionMapping methods', function () {
});
});

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

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

mapping.refresh((err, res) => {
mapping.refresh(function (err, res) {
should(emitted).be.true();
should(err).be.null();
should(res).be.exactly(mapping);
Expand Down
12 changes: 8 additions & 4 deletions test/MemoryStorage/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var
Kuzzle = rewire('../../src/Kuzzle');

describe('MemoryStorage constructor', function () {
it('should initialize properties and return a valid MemoryStorage object', () => {
it('should initialize properties and return a valid MemoryStorage object', function () {
var
kuzzle = new Kuzzle('foo'),
ms;
Expand All @@ -24,7 +24,7 @@ describe('MemoryStorage constructor', function () {
should(ms.headers.someother).be.undefined();
});

it('should promisify all methods', () => {
it('should promisify all methods', function () {
var
kuzzle,
ms,
Expand All @@ -35,9 +35,13 @@ describe('MemoryStorage constructor', function () {
kuzzle = new Kuzzle('foo');
ms = new MemoryStorage(kuzzle);

functions = Object.getOwnPropertyNames(Object.getPrototypeOf(ms)).filter(p => (typeof ms[p] === 'function' && ['constructor', 'setHeaders'].indexOf(p) === -1));
functions = Object.getOwnPropertyNames(Object.getPrototypeOf(ms)).filter(function (p) {
return (typeof ms[p] === 'function' && ['constructor', 'setHeaders'].indexOf(p) === -1);
});

should(functions.length).be.eql(119);
functions.forEach(f => {

functions.forEach(function (f) {
should(ms[f + 'Promise']).be.a.Function();
});

Expand Down
24 changes: 12 additions & 12 deletions test/MemoryStorage/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ var
Kuzzle = require('../stubs/kuzzle.stub'),
MemoryStorage = require('../../src/MemoryStorage');

describe('MemoryStorage methods', () => {
describe('MemoryStorage methods', function () {
var
kuzzle = new Kuzzle('foo'),
ms = new MemoryStorage(kuzzle);

describe('#regular case', () => {
it('should parse the given arguments (no options)', () => {
ms.append('foo', 'bar', (err, r) => {
describe('#regular case', function () {
it('should parse the given arguments (no options)', function () {
ms.append('foo', 'bar', function (err, r) {
should(r.args).match({
controller: 'ms',
action: 'append'
Expand All @@ -23,8 +23,8 @@ describe('MemoryStorage methods', () => {
});
});

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

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

ms.sinter(['foo', 'bar'], (err, r) => {
ms.sinter(['foo', 'bar'], function (err, r) {
should(r.args).match({
controller: 'ms',
action: 'sinter'
Expand All @@ -62,8 +62,8 @@ describe('MemoryStorage methods', () => {
});
});

describe('#functions with optional parameters', () => {
it('should parse all given arguments', () => {
describe('#functions with optional parameters', function () {
it('should parse all given arguments', function () {
ms.zadd('foo', {
nx: true,
xx: true,
Expand All @@ -75,7 +75,7 @@ describe('MemoryStorage methods', () => {
{score: 's1', member: 'm1'},
{score: 's2', member: 'm2'}
]
}, (err, r) => {
}, function (err, r) {
should(r.args).match({
controller: 'ms',
action: 'zadd'
Expand Down
28 changes: 13 additions & 15 deletions test/Room/methods.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const
var
should = require('should'),
rewire = require('rewire'),
sinon = require('sinon'),
Expand All @@ -9,7 +7,7 @@ const
Room = rewire('../../src/Room');

describe('Room methods', function () {
let
var
expectedQuery,
error,
result,
Expand Down Expand Up @@ -198,7 +196,7 @@ describe('Room methods', function () {
it('should start dequeuing if subscribed successfully', function (done) {
room.renew({}, function () {});

setTimeout(() => {
setTimeout(function () {
should(dequeued).be.true();
done();
}, 10);
Expand All @@ -221,7 +219,7 @@ describe('Room methods', function () {
it('should register itself to Kuzzle and skip subscription if not connected', function (done) {
kuzzle.state = 'foo';
room.renew({}, function () {});
setTimeout(() => {
setTimeout(function () {
should(dequeued).be.false();
should(emitted).be.false();
should(room.lastRenewal).be.null();
Expand All @@ -242,7 +240,7 @@ describe('Room methods', function () {
room.renew({}, function () {});
room.renew({}, function () {});

setTimeout(() => {
setTimeout(function () {
should(renewals).be.eql(1);
should(room.lastRenewal).be.within(before, after);
done();
Expand Down Expand Up @@ -321,7 +319,7 @@ describe('Room methods', function () {
should(emitted).be.false();
should(kuzzle.subscriptions.foobar).be.undefined();
kuzzle.subscriptions.pending = {};
setTimeout(() => {
setTimeout(function () {
should(emitted).be.true();
done();
}, 100);
Expand All @@ -336,7 +334,7 @@ describe('Room methods', function () {
kuzzle.subscriptions.pending = {};
kuzzle.subscriptions.foobar = {};
kuzzle.subscriptions.foobar.foo = {};
setTimeout(() => {
setTimeout(function () {
should(emitted).be.false();
done();
}, 100);
Expand Down Expand Up @@ -381,7 +379,7 @@ describe('Room methods', function () {
});

describe('#notificationCallback', function () {
let
var
notifCB = Room.__get__('notificationCallback'),
room;

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

it('should handle document notifications', () => {
it('should handle document notifications', function () {
notifCB.call(room, {
controller: 'document',
result: {
Expand All @@ -429,7 +427,7 @@ describe('Room methods', function () {
.be.an.instanceOf(Document);
});

it('should handle realtime publish notifications', () => {
it('should handle realtime publish notifications', function () {
notifCB.call(room, {
controller: 'realtime',
action: 'publish',
Expand Down Expand Up @@ -457,7 +455,7 @@ describe('Room methods', function () {
.be.an.instanceOf(Document);
});

it('should handle user notifications', () => {
it('should handle user notifications', function () {
notifCB.call(room, {
controller: 'realtime',
result: { count: 3 }
Expand All @@ -473,7 +471,7 @@ describe('Room methods', function () {
});
});

it('should delete the result from history if emitted by this instance', () => {
it('should delete the result from history if emitted by this instance', function () {
room.subscribeToSelf = true;
kuzzle.requestHistory.bar = {};
notifCB.call(room, {error: null, result: {}, action: 'foo', requestId: 'bar'});
Expand All @@ -498,7 +496,7 @@ describe('Room methods', function () {
eventEmitted = null,
context = {
kuzzle: {
emitEvent: event => {
emitEvent: function (event) {
eventEmitted = event;
}
}
Expand Down
Loading