Skip to content

Commit

Permalink
Merge pull request #541 from shanedewael/fix-es2015-prototype-compata…
Browse files Browse the repository at this point in the history
…bility

Imports Hubot prototype dynamically for extensions
  • Loading branch information
Shane DeWael authored Dec 19, 2018
2 parents a442154 + 06a4f1a commit 571803a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
},
"devDependencies": {
"chai": "^3.5.0",
"codecov": "^2.3.1",
"coffee-coverage": "^2.0.0",
"coffeescript": "^1.12.7",
"codecov": "^2.3.1",
"hubot": ">= 2.19.0",
"istanbul": "^0.4.3",
"mocha": "^3.5.3",
"mockery": "^2.1.0",
"should": "^8.0.0"
},
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions src/extensions.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{Robot} = require.main.require "hubot"

# Requires the es2015 version of Hubot for v3 or higher so the correct prototype is updated
if Robot.name == "CoffeeScriptCompatibleClass"
{Robot} = require.main.require "hubot/es2015"

{ReactionMessage, PresenceMessage} = require "./message"

###*
Expand Down
33 changes: 19 additions & 14 deletions test/bot.coffee
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
should = require 'should'
chai = require 'chai'
{ EnterMessage, LeaveMessage, TopicMessage, CatchAllMessage, Robot } = require.main.require 'hubot'
mockery = require 'mockery'
hubotSlackMock = require '../slack.coffee'
mockery.registerMock('hubot-slack', hubotSlackMock);

{ EnterMessage, LeaveMessage, TopicMessage, CatchAllMessage, Robot, loadBot } = require.main.require 'hubot'
{ SlackTextMessage, ReactionMessage, PresenceMessage } = require '../src/message'
SlackClient = require '../src/client'
_ = require 'lodash'

describe 'Adapter', ->
before ->
mockery.enable({
warnOnUnregistered: false
});

after ->
mockery.disable()

it 'Should initialize with a robot', ->
@slackbot.robot.should.eql @stubs.robot

it 'Should add the `react` method to the hubot `Robot` prototype', ->
Robot.prototype.react.should.be.an.instanceOf(Function).with.lengthOf(3)

# This is a sanity check to ensure the @slackbot.robot stub is proper.
@slackbot.robot.listen.should.be.an.instanceOf(Function).with.lengthOf(3)
@slackbot.robot.react.should.be.an.instanceOf(Function).with.lengthOf(3)

it 'Should add the `presenceChange` method to the hubot `Robot` prototype', ->
Robot.prototype.presenceChange.should.be.an.instanceOf(Function).with.lengthOf(3)

# This is a sanity check to ensure the @slackbot.robot stub is proper.
@slackbot.robot.listen.should.be.an.instanceOf(Function).with.lengthOf(3)
@slackbot.robot.presenceChange.should.be.an.instanceOf(Function).with.lengthOf(3)
it 'Should load an instance of Robot with extended methods', ->
loadedRobot = loadBot('', 'slack', false, 'Hubot')

# Check to make sure presenceChange and react are loaded to Robot
loadedRobot.presenceChange.should.be.an.instanceOf(Function).with.lengthOf(3)
loadedRobot.react.should.be.an.instanceOf(Function).with.lengthOf(3)

describe 'Connect', ->
it 'Should connect successfully', ->
Expand Down

0 comments on commit 571803a

Please sign in to comment.