From 18c9840a6f668a0bcd5e7441213de8a340057e31 Mon Sep 17 00:00:00 2001 From: Shane DeWael Date: Mon, 22 Oct 2018 15:56:20 -0700 Subject: [PATCH 1/2] imports hubot dynamically for extensions --- src/extensions.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/extensions.coffee b/src/extensions.coffee index 6b2998c9..84194a8e 100644 --- a/src/extensions.coffee +++ b/src/extensions.coffee @@ -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" ###* From 06a4f1a797cb023ff8f4875908b62b5036c4922c Mon Sep 17 00:00:00 2001 From: Shane DeWael Date: Tue, 18 Dec 2018 16:19:45 -0800 Subject: [PATCH 2/2] Add test for extensions --- package.json | 3 ++- test/bot.coffee | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 81653cc5..f590a9b7 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/bot.coffee b/test/bot.coffee index f1633f72..9780a236 100644 --- a/test/bot.coffee +++ b/test/bot.coffee @@ -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', ->