Skip to content

Commit

Permalink
refactor eventstream tests to make them less fragile
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Feb 14, 2021
1 parent 432c793 commit 0dfba93
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/suppl.bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ describe('supplementary functions', function() {
});

it('eventstream', function (done) {
this.timeout(8000);
let stream = new bot.stream('recentchange');
function messageHandler(data) {
expect(data).to.be.an('object');
expect(data).to.have.property('wiki').that.is.a('string');
}
let spy = sinon.spy(messageHandler);
stream.addListener({}, spy);
setTimeout(function () {
stream.close();
expect(spy.callCount).to.be.greaterThan(2);
done();
}, 2000);
let interval = setInterval(function () {
if (spy.callCount > 2) {
stream.close();
clearInterval(interval);
done();
}
}, 500);
});

it('eventstream with since param', function (done) {
this.timeout(8000);
let sinceTime = new bot.date().subtract(5, 'hours');
let stream = new bot.stream('recentchange', {
since: sinceTime
Expand All @@ -64,11 +68,13 @@ describe('supplementary functions', function() {
}
let spy = sinon.spy(messageHandler);
stream.addListener({}, spy);
setTimeout(function () {
stream.close();
expect(spy.callCount).to.be.greaterThan(2);
done();
}, 2000);
let interval = setInterval(function () {
if (spy.callCount > 10) {
stream.close();
clearInterval(interval);
done();
}
}, 500);
});


Expand Down

0 comments on commit 0dfba93

Please sign in to comment.