Skip to content

Commit 74a0911

Browse files
committed
fix tests
1 parent 4b9ae08 commit 74a0911

File tree

5 files changed

+26
-48
lines changed

5 files changed

+26
-48
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
REMOTE=origin
44

5-
TESTS = test/*.coffee
5+
TESTS = test/*.js
66

77
test:
8-
./node_modules/.bin/mocha --compilers coffee:coffee-script $(TESTS)
8+
./node_modules/.bin/mocha $(TESTS)
99

1010
release: bump-version
1111
@echo "Tagging $(VERSION)"

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ hubot-xmpp will then automatically resolve the JID to a private
6565
chat JID, and private message the sender.
6666

6767
If you need to get the private chat JID, you can use
68-
'msg.envelope.user.privateChatJid' where msg is the parameter of hubot's
69-
"route" callback.
68+
`msg.envelope.user.privateChatJid` where `msg` is the parameter of hubot's
69+
`route` callback.
7070

7171
Example:
7272

73-
```coffeescript
74-
robot.respond /talk to me$/i, ( msg ) ->
75-
# Simply reply
76-
msg.reply "Hello #{msg.envelope.user.name}. Your private JID is #{msg.envelope.user.privateChatJID}"
73+
```js
74+
robot.respond(/talk to me$/i, msg => {
75+
// Simply reply
76+
msg.reply(`Hello ${msg.envelope.user.name}. Your private JID is ${msg.envelope.user.privateChatJID}`);
77+
});
7778

78-
robot.respond /talk to me in private$/i, ( msg ) ->
79-
msg.envelope.user.type = 'direct'
80-
msg.send "Hey #{msg.envelope.user.name}! You told me in room #{msg.envelope.user.room} to talk to you."
79+
robot.respond(/talk to me in private$/i, msg => {
80+
msg.envelope.user.type = 'direct';
81+
msg.send(`Hey ${msg.envelope.user.name}! You told me in room ${msg.envelope.user.room} to talk to you.`);
82+
});
8183
```

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
"uuid": "2.0.2"
3333
},
3434
"devDependencies": {
35-
"coffee-script": "1.1.3",
36-
"sinon": "1.9.0",
37-
"mocha": "1.15.1",
38-
"hubot": ">=2.4.1"
35+
"hubot": ">=3.0.0",
36+
"mocha": "^6.2.2",
37+
"sinon": "1.9.0"
3938
},
4039
"volta": {
4140
"node": "8.15.1",

src/xmpp.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,21 @@
99
* DS207: Consider shorter variations of null checks
1010
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
1111
*/
12-
const {Adapter,Robot,TextMessage,EnterMessage,LeaveMessage} = require('hubot');
12+
const {Adapter,Robot,TextMessage,EnterMessage,LeaveMessage} = require('hubot/es2015');
1313
const {JID, Stanza, Client, parse, Element} = require('node-xmpp-client');
1414
const uuid = require('uuid');
1515
const util = require('util');
1616

1717
class XmppBot extends Adapter {
18-
static initClass() {
19-
20-
this.prototype.reconnectTryCount = 0;
21-
this.prototype.currentIqId = 1001;
22-
this.prototype.joining = [];
23-
this.prototype.joined = [];
24-
}
25-
2618
constructor( robot ) {
27-
{
28-
// Hack: trick Babel/TypeScript into allowing this before super.
29-
if (false) { super(); }
30-
let thisFn = (() => { return this; }).toString();
31-
let thisName = thisFn.match(/return (?:_assertThisInitialized\()*(\w+)\)*;/)[1];
32-
eval(`${thisName} = this;`);
33-
}
34-
this.error = this.error.bind(this);
35-
this.online = this.online.bind(this);
36-
this.ping = this.ping.bind(this);
37-
this.read = this.read.bind(this);
38-
this.readIq = this.readIq.bind(this);
39-
this.readMessage = this.readMessage.bind(this);
40-
this.readPresence = this.readPresence.bind(this);
41-
this.offline = this.offline.bind(this);
42-
this.checkCanStart = this.checkCanStart.bind(this);
43-
this.robot = robot;
19+
super(robot)
4420

4521
// Flag to log a warning message about group chat configuration only once
4622
this.anonymousGroupChatWarningLogged = false;
4723

4824
// Store the room JID to private JID map.
4925
// Key is the room JID, value is the private JID
5026
this.roomToPrivateJID = {};
51-
52-
// http://stackoverflow.com/a/646643
53-
if (String.prototype.startsWith == null) { String.prototype.startsWith = function(s) { return this.slice(0, s.length) === s; }; }
5427
}
5528

5629
run() {
@@ -592,7 +565,11 @@ class XmppBot extends Adapter {
592565
}
593566
}
594567
}
595-
XmppBot.initClass();
568+
569+
XmppBot.prototype.reconnectTryCount = 0;
570+
XmppBot.prototype.currentIqId = 1001;
571+
XmppBot.prototype.joining = [];
572+
XmppBot.prototype.joined = [];
596573

597574
exports.use = robot => new XmppBot(robot);
598575

@@ -605,4 +582,4 @@ function __guardMethod__(obj, methodName, transform) {
605582
}
606583
function __guard__(value, transform) {
607584
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
608-
}
585+
}

test/adapter-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ describe('XmppBot', function() {
13171317
name: 'message',
13181318
flag: 'ignore_me'
13191319
};
1320-
const proxied = bot.readMessage;
1320+
const proxied = bot.readMessage.bind(bot);
13211321
bot.readMessage = function(message) {
13221322
proxied(message);
13231323
if (message.flag === 'ignore_me') {
@@ -1347,7 +1347,7 @@ describe('XmppBot', function() {
13471347
};
13481348
}
13491349
};
1350-
const proxied = bot.readMessage;
1350+
const proxied = bot.readMessage.bind(bot);
13511351
bot.readMessage = function(message) {
13521352
proxied(message);
13531353
assert.equal(true, Array.from(bot.joined).includes('test@example.com'));

0 commit comments

Comments
 (0)