Skip to content

Commit 3eb3727

Browse files
committed
Disconnect clients at end of tests
1 parent a721a6c commit 3eb3727

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

lib/bot.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ class Bot {
133133
this.attachListeners();
134134
}
135135

136+
disconnect() {
137+
this.ircClient.disconnect();
138+
this.discord.destroy();
139+
Object.values(this.webhooks).forEach(x => x.client.destroy());
140+
}
141+
136142
attachListeners() {
137143
this.discord.on('ready', () => {
138144
logger.info('Connected to Discord');

test/bot-events.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import discord from 'discord.js';
77
import Bot from '../lib/bot';
88
import logger from '../lib/logger';
99
import createDiscordStub from './stubs/discord-stub';
10+
import createWebhookStub from './stubs/webhook-stub';
1011
import ClientStub from './stubs/irc-client-stub';
1112
import config from './fixtures/single-test-config.json';
1213

@@ -36,13 +37,15 @@ describe('Bot Events', function () {
3637
this.sendStub = sandbox.stub();
3738
irc.Client = ClientStub;
3839
discord.Client = createDiscordStub(this.sendStub);
40+
discord.WebhookClient = createWebhookStub(this.sendStub);
3941
ClientStub.prototype.send = sandbox.stub();
4042
ClientStub.prototype.join = sandbox.stub();
4143
this.bot = createBot();
4244
this.bot.connect();
4345
});
4446

4547
afterEach(function () {
48+
this.bot.disconnect();
4649
sandbox.restore();
4750
});
4851

test/stubs/discord-stub.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default function createDiscordStub(sendStub) {
2525
this.rest = this.createRestStub();
2626
}
2727

28+
destroy() {}
29+
2830
addTextChannel(guild, textChannel) {
2931
const textChannelData = {
3032
type: discord.Constants.ChannelTypes.TEXT,

test/stubs/irc-client-stub.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import events from 'events';
22

3+
/* eslint-disable class-methods-use-this */
34
class ClientStub extends events.EventEmitter {
45
constructor(...args) {
56
super();
67
this.nick = args[1]; // eslint-disable-line prefer-destructuring
78
}
9+
10+
disconnect() {}
811
}
912

1013
export default ClientStub;

test/stubs/webhook-stub.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ export default function createWebhookStub(sendWebhookMessage) {
1010
sendWebhookMessage(...args);
1111
return new Promise(() => {});
1212
}
13+
14+
destroy() {}
1315
};
1416
}

0 commit comments

Comments
 (0)