From fe2f0fe3e5d69c8aa5e9331cf793dc3a4bc41dac Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Sat, 30 Sep 2017 17:50:39 +0900 Subject: [PATCH 1/2] chore: decaffeinate --- src/index.coffee | 105 --------------- src/index.js | 162 +++++++++++++++++++++++ test/custom-text-message_test.coffee | 21 --- test/custom-text-message_test.js | 32 +++++ test/enter-leave_test.coffee | 21 --- test/enter-leave_test.js | 32 +++++ test/events_test.coffee | 29 ---- test/events_test.js | 41 ++++++ test/hello-world-listener_test.coffee | 22 --- test/hello-world-listener_test.js | 33 +++++ test/hello-world_test.coffee | 25 ---- test/hello-world_test.js | 37 ++++++ test/httpd-world_test.coffee | 22 --- test/httpd-world_test.js | 33 +++++ test/load-multiple-scripts_test.coffee | 23 ---- test/load-multiple-scripts_test.js | 34 +++++ test/mock-response_test.coffee | 27 ---- test/mock-response_test.js | 40 ++++++ test/private-message_test.coffee | 26 ---- test/private-message_test.js | 38 ++++++ test/scripts/bye.coffee | 5 - test/scripts/bye.js | 10 ++ test/scripts/custom-text-message.coffee | 7 - test/scripts/custom-text-message.js | 12 ++ test/scripts/enter-leave.coffee | 8 -- test/scripts/enter-leave.js | 12 ++ test/scripts/events.coffee | 9 -- test/scripts/events.js | 15 +++ test/scripts/hello-world-listener.coffee | 9 -- test/scripts/hello-world-listener.js | 12 ++ test/scripts/hello-world.coffee | 5 - test/scripts/hello-world.js | 10 ++ test/scripts/httpd-world.coffee | 5 - test/scripts/httpd-world.js | 10 ++ test/scripts/mock-response.coffee | 6 - test/scripts/mock-response.js | 13 ++ test/scripts/private-message.coffee | 5 - test/scripts/private-message.js | 10 ++ test/scripts/user-params.coffee | 8 -- test/scripts/user-params.js | 12 ++ test/user-params_test.coffee | 22 --- test/user-params_test.js | 43 ++++++ 42 files changed, 641 insertions(+), 410 deletions(-) delete mode 100644 src/index.coffee create mode 100644 src/index.js delete mode 100644 test/custom-text-message_test.coffee create mode 100644 test/custom-text-message_test.js delete mode 100644 test/enter-leave_test.coffee create mode 100644 test/enter-leave_test.js delete mode 100644 test/events_test.coffee create mode 100644 test/events_test.js delete mode 100644 test/hello-world-listener_test.coffee create mode 100644 test/hello-world-listener_test.js delete mode 100644 test/hello-world_test.coffee create mode 100644 test/hello-world_test.js delete mode 100644 test/httpd-world_test.coffee create mode 100644 test/httpd-world_test.js delete mode 100644 test/load-multiple-scripts_test.coffee create mode 100644 test/load-multiple-scripts_test.js delete mode 100644 test/mock-response_test.coffee create mode 100644 test/mock-response_test.js delete mode 100644 test/private-message_test.coffee create mode 100644 test/private-message_test.js delete mode 100644 test/scripts/bye.coffee create mode 100644 test/scripts/bye.js delete mode 100644 test/scripts/custom-text-message.coffee create mode 100644 test/scripts/custom-text-message.js delete mode 100644 test/scripts/enter-leave.coffee create mode 100644 test/scripts/enter-leave.js delete mode 100644 test/scripts/events.coffee create mode 100644 test/scripts/events.js delete mode 100644 test/scripts/hello-world-listener.coffee create mode 100644 test/scripts/hello-world-listener.js delete mode 100644 test/scripts/hello-world.coffee create mode 100644 test/scripts/hello-world.js delete mode 100644 test/scripts/httpd-world.coffee create mode 100644 test/scripts/httpd-world.js delete mode 100644 test/scripts/mock-response.coffee create mode 100644 test/scripts/mock-response.js delete mode 100644 test/scripts/private-message.coffee create mode 100644 test/scripts/private-message.js delete mode 100644 test/scripts/user-params.coffee create mode 100644 test/scripts/user-params.js delete mode 100644 test/user-params_test.coffee create mode 100644 test/user-params_test.js diff --git a/src/index.coffee b/src/index.coffee deleted file mode 100644 index 404071f..0000000 --- a/src/index.coffee +++ /dev/null @@ -1,105 +0,0 @@ -Fs = require('fs') -Path = require('path') -Hubot = require('hubot') - -process.setMaxListeners(0) - -class MockResponse extends Hubot.Response - sendPrivate: (strings...) -> - @robot.adapter.sendPrivate @envelope, strings... - -class MockRobot extends Hubot.Robot - constructor: (httpd=true) -> - super null, null, httpd, 'hubot' - - @Response = MockResponse - - loadAdapter: -> - @adapter = new Room(@) - -class Room extends Hubot.Adapter - constructor: (@robot) -> - @messages = [] - - @privateMessages = {} - - @user = - say: (userName, message, userParams) => - @receive(userName, message, userParams) - - enter: (userName, userParams) => - @enter(userName, userParams) - - leave: (userName, userParams) => - @leave(userName, userParams) - - receive: (userName, message, userParams = {}) -> - new Promise (resolve) => - textMessage = null - if typeof message is 'object' and message - textMessage = message - else - userParams.room = @name - user = new Hubot.User(userName, userParams) - textMessage = new Hubot.TextMessage(user, message) - - @messages.push [userName, textMessage.text] - @robot.receive(textMessage, resolve) - - destroy: -> - @robot.server.close() if @robot.server - - reply: (envelope, strings...) -> - @messages.push ['hubot', "@#{envelope.user.name} #{str}"] for str in strings - - send: (envelope, strings...) -> - @messages.push ['hubot', str] for str in strings - - sendPrivate: (envelope, strings...) -> - if envelope.user.name not of @privateMessages - @privateMessages[envelope.user.name] = [] - @privateMessages[envelope.user.name].push ['hubot', str] for str in strings - - robotEvent: () -> - @robot.emit.apply(@robot, arguments) - - enter: (userName, userParams = {}) -> - new Promise (resolve) => - userParams.room = @name - user = new Hubot.User(userName, userParams) - @robot.receive(new Hubot.EnterMessage(user), resolve) - - leave: (userName, userParams = {}) -> - new Promise (resolve) => - userParams.room = @name - user = new Hubot.User(userName, userParams) - @robot.receive(new Hubot.LeaveMessage(user), resolve) - -class Helper - @Response = MockResponse - - constructor: (scriptsPaths) -> - if not Array.isArray(scriptsPaths) - scriptsPaths = [scriptsPaths] - @scriptsPaths = scriptsPaths - - createRoom: (options={}) -> - robot = new MockRobot(options.httpd) - - if 'response' of options - robot.Response = options.response - - for script in @scriptsPaths - script = Path.resolve(Path.dirname(module.parent.filename), script) - if Fs.statSync(script).isDirectory() - for file in Fs.readdirSync(script).sort() - robot.loadFile script, file - else - robot.loadFile Path.dirname(script), Path.basename(script) - - robot.brain.emit 'loaded' - - robot.adapter.name = options.name or 'room1' - robot.adapter - -module.exports = Helper diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..faf58b7 --- /dev/null +++ b/src/index.js @@ -0,0 +1,162 @@ +/* + * decaffeinate suggestions: + * DS001: Remove Babel/TypeScript constructor workaround + * DS101: Remove unnecessary use of Array.from + * DS102: Remove unnecessary code created because of implicit returns + * DS206: Consider reworking classes to avoid initClass + * DS207: Consider shorter variations of null checks + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Fs = require('fs'); +const Path = require('path'); +const Hubot = require('hubot'); + +process.setMaxListeners(0); + +class MockResponse extends Hubot.Response { + sendPrivate(...strings) { + return this.robot.adapter.sendPrivate(this.envelope, ...Array.from(strings)); + } +} + +class MockRobot extends Hubot.Robot { + constructor(httpd) { + if (httpd == null) { httpd = true; } + super(null, null, httpd, 'hubot'); + + this.Response = MockResponse; + } + + loadAdapter() { + return this.adapter = new Room(this); + } +} + +class Room extends Hubot.Adapter { + constructor(robot) { + { + // Hack: trick Babel/TypeScript into allowing this before super. + if (false) { super(); } + let thisFn = (() => { this; }).toString(); + let thisName = thisFn.slice(thisFn.indexOf('{') + 1, thisFn.indexOf(';')).trim(); + eval(`${thisName} = this;`); + } + this.robot = robot; + this.messages = []; + + this.privateMessages = {}; + + this.user = { + say: (userName, message, userParams) => { + return this.receive(userName, message, userParams); + }, + + enter: (userName, userParams) => { + return this.enter(userName, userParams); + }, + + leave: (userName, userParams) => { + return this.leave(userName, userParams); + } + }; + } + + receive(userName, message, userParams) { + if (userParams == null) { userParams = {}; } + return new Promise(resolve => { + let textMessage = null; + if ((typeof message === 'object') && message) { + textMessage = message; + } else { + userParams.room = this.name; + const user = new Hubot.User(userName, userParams); + textMessage = new Hubot.TextMessage(user, message); + } + + this.messages.push([userName, textMessage.text]); + return this.robot.receive(textMessage, resolve); + }); + } + + destroy() { + if (this.robot.server) { return this.robot.server.close(); } + } + + reply(envelope, ...strings) { + return Array.from(strings).map((str) => this.messages.push(['hubot', `@${envelope.user.name} ${str}`])); + } + + send(envelope, ...strings) { + return Array.from(strings).map((str) => this.messages.push(['hubot', str])); + } + + sendPrivate(envelope, ...strings) { + if (!(envelope.user.name in this.privateMessages)) { + this.privateMessages[envelope.user.name] = []; + } + return Array.from(strings).map((str) => this.privateMessages[envelope.user.name].push(['hubot', str])); + } + + robotEvent() { + return this.robot.emit.apply(this.robot, arguments); + } + + enter(userName, userParams) { + if (userParams == null) { userParams = {}; } + return new Promise(resolve => { + userParams.room = this.name; + const user = new Hubot.User(userName, userParams); + return this.robot.receive(new Hubot.EnterMessage(user), resolve); + }); + } + + leave(userName, userParams) { + if (userParams == null) { userParams = {}; } + return new Promise(resolve => { + userParams.room = this.name; + const user = new Hubot.User(userName, userParams); + return this.robot.receive(new Hubot.LeaveMessage(user), resolve); + }); + } +} + +class Helper { + static initClass() { + this.Response = MockResponse; + } + + constructor(scriptsPaths) { + if (!Array.isArray(scriptsPaths)) { + scriptsPaths = [scriptsPaths]; + } + this.scriptsPaths = scriptsPaths; + } + + createRoom(options) { + if (options == null) { options = {}; } + const robot = new MockRobot(options.httpd); + + if ('response' in options) { + robot.Response = options.response; + } + + for (let script of Array.from(this.scriptsPaths)) { + script = Path.resolve(Path.dirname(module.parent.filename), script); + if (Fs.statSync(script).isDirectory()) { + for (let file of Array.from(Fs.readdirSync(script).sort())) { + robot.loadFile(script, file); + } + } else { + robot.loadFile(Path.dirname(script), Path.basename(script)); + } + } + + robot.brain.emit('loaded'); + + robot.adapter.name = options.name || 'room1'; + return robot.adapter; + } +} +Helper.initClass(); + +module.exports = Helper; diff --git a/test/custom-text-message_test.coffee b/test/custom-text-message_test.coffee deleted file mode 100644 index 89f5ec0..0000000 --- a/test/custom-text-message_test.coffee +++ /dev/null @@ -1,21 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/custom-text-message.coffee') -Hubot = require('hubot') - -co = require('co') -expect = require('chai').expect - -describe 'custom-text-message', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'Passing a custom text message object', -> - beforeEach -> - co => - textMessage = new Hubot.TextMessage({}, '') - textMessage.isCustom = true - textMessage.custom = 'custom' - yield @room.user.say 'user', textMessage - - it 'sends back', -> - expect(@room.messages[1][1]).to.be.equal('custom') diff --git a/test/custom-text-message_test.js b/test/custom-text-message_test.js new file mode 100644 index 0000000..3944f4b --- /dev/null +++ b/test/custom-text-message_test.js @@ -0,0 +1,32 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/custom-text-message.coffee'); +const Hubot = require('hubot'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('custom-text-message', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + return context('Passing a custom text message object', function() { + beforeEach(function() { + return co(function*() { + const textMessage = new Hubot.TextMessage({}, ''); + textMessage.isCustom = true; + textMessage.custom = 'custom'; + return yield this.room.user.say('user', textMessage); + }.bind(this)); + }); + + return it('sends back', function() { + return expect(this.room.messages[1][1]).to.be.equal('custom'); + }); + }); +}); diff --git a/test/enter-leave_test.coffee b/test/enter-leave_test.coffee deleted file mode 100644 index b559aad..0000000 --- a/test/enter-leave_test.coffee +++ /dev/null @@ -1,21 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/enter-leave.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'enter-leave', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'user entering then leaving the room', -> - beforeEach -> - co => - yield @room.user.enter 'user1' - yield @room.user.leave 'user1' - - it 'greets the user', -> - expect(@room.messages).to.eql [ - ['hubot', 'Hi user1!'] - ['hubot', 'Bye user1!'] - ] diff --git a/test/enter-leave_test.js b/test/enter-leave_test.js new file mode 100644 index 0000000..99c6803 --- /dev/null +++ b/test/enter-leave_test.js @@ -0,0 +1,32 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/enter-leave.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('enter-leave', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + return context('user entering then leaving the room', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.enter('user1'); + return yield this.room.user.leave('user1'); + }.bind(this)); + }); + + return it('greets the user', function() { + return expect(this.room.messages).to.eql([ + ['hubot', 'Hi user1!'], + ['hubot', 'Bye user1!'] + ]); + }); +}); +}); diff --git a/test/events_test.coffee b/test/events_test.coffee deleted file mode 100644 index 54e1de7..0000000 --- a/test/events_test.coffee +++ /dev/null @@ -1,29 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/events.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'events', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'should post on an event', -> - beforeEach -> - @room.robotEvent 'some-event', 'event', 'data' - - it 'should reply to user', -> - expect(@room.messages).to.eql [ - ['hubot', 'got event with event data'] - ] - - context 'should hear events emitted by responses', -> - - - it 'should trigger an event', -> - response = null - @room.robot.on 'response-event', (event) -> - response = event.content - - @room.user.say('bob', '@hubot send event').then => - expect(response).to.eql('hello') diff --git a/test/events_test.js b/test/events_test.js new file mode 100644 index 0000000..543169e --- /dev/null +++ b/test/events_test.js @@ -0,0 +1,41 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/events.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('events', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + context('should post on an event', function() { + beforeEach(function() { + return this.room.robotEvent('some-event', 'event', 'data'); + }); + + return it('should reply to user', function() { + return expect(this.room.messages).to.eql([ + ['hubot', 'got event with event data'] + ]); + }); +}); + + return context('should hear events emitted by responses', () => + + + it('should trigger an event', function() { + let response = null; + this.room.robot.on('response-event', event => response = event.content); + + return this.room.user.say('bob', '@hubot send event').then(() => { + return expect(response).to.eql('hello'); + }); + }) + ); +}); diff --git a/test/hello-world-listener_test.coffee b/test/hello-world-listener_test.coffee deleted file mode 100644 index c9314d1..0000000 --- a/test/hello-world-listener_test.coffee +++ /dev/null @@ -1,22 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/hello-world-listener.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'hello-world', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'user says hi to hubot', -> - beforeEach -> - co => - yield @room.user.say 'alice', '@hubot hi' - yield @room.user.say 'bob', '@hubot hi' - - it 'should reply to user', -> - expect(@room.messages).to.eql [ - ['alice', '@hubot hi'] - ['bob', '@hubot hi'] - ['hubot', '@bob hi'] - ] diff --git a/test/hello-world-listener_test.js b/test/hello-world-listener_test.js new file mode 100644 index 0000000..4e69019 --- /dev/null +++ b/test/hello-world-listener_test.js @@ -0,0 +1,33 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/hello-world-listener.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('hello-world', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + return context('user says hi to hubot', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.say('alice', '@hubot hi'); + return yield this.room.user.say('bob', '@hubot hi'); + }.bind(this)); + }); + + return it('should reply to user', function() { + return expect(this.room.messages).to.eql([ + ['alice', '@hubot hi'], + ['bob', '@hubot hi'], + ['hubot', '@bob hi'] + ]); + }); +}); +}); diff --git a/test/hello-world_test.coffee b/test/hello-world_test.coffee deleted file mode 100644 index 2f01e44..0000000 --- a/test/hello-world_test.coffee +++ /dev/null @@ -1,25 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/hello-world.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'hello-world', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - afterEach -> - @room.destroy() - - context 'user says hi to hubot', -> - beforeEach -> - co => - yield @room.user.say 'alice', '@hubot hi' - yield @room.user.say 'bob', '@hubot hi' - - it 'should reply to user', -> - expect(@room.messages).to.eql [ - ['alice', '@hubot hi'] - ['hubot', '@alice hi'] - ['bob', '@hubot hi'] - ['hubot', '@bob hi'] - ] diff --git a/test/hello-world_test.js b/test/hello-world_test.js new file mode 100644 index 0000000..0b35562 --- /dev/null +++ b/test/hello-world_test.js @@ -0,0 +1,37 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/hello-world.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('hello-world', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + afterEach(function() { + return this.room.destroy(); + }); + + return context('user says hi to hubot', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.say('alice', '@hubot hi'); + return yield this.room.user.say('bob', '@hubot hi'); + }.bind(this)); + }); + + return it('should reply to user', function() { + return expect(this.room.messages).to.eql([ + ['alice', '@hubot hi'], + ['hubot', '@alice hi'], + ['bob', '@hubot hi'], + ['hubot', '@bob hi'] + ]); + }); +}); +}); diff --git a/test/httpd-world_test.coffee b/test/httpd-world_test.coffee deleted file mode 100644 index 892b17d..0000000 --- a/test/httpd-world_test.coffee +++ /dev/null @@ -1,22 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts') -http = require('http') - -expect = require('chai').expect - -process.env.EXPRESS_PORT = 8080 - -describe 'httpd-world', -> - beforeEach -> - @room = helper.createRoom() - - afterEach -> - @room.destroy() - - context 'GET /hello/world', -> - beforeEach (done) -> - http.get 'http://localhost:8080/hello/world', (@response) => done() - .on 'error', done - - it 'responds with status 200', -> - expect(@response.statusCode).to.equal 200 diff --git a/test/httpd-world_test.js b/test/httpd-world_test.js new file mode 100644 index 0000000..4869d3a --- /dev/null +++ b/test/httpd-world_test.js @@ -0,0 +1,33 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts'); +const http = require('http'); + +const { expect } = require('chai'); + +process.env.EXPRESS_PORT = 8080; + +describe('httpd-world', function() { + beforeEach(function() { + return this.room = helper.createRoom(); + }); + + afterEach(function() { + return this.room.destroy(); + }); + + return context('GET /hello/world', function() { + beforeEach(function(done) { + return http.get('http://localhost:8080/hello/world', response => { this.response = response; return done(); }) + .on('error', done); + }); + + return it('responds with status 200', function() { + return expect(this.response.statusCode).to.equal(200); + }); + }); +}); diff --git a/test/load-multiple-scripts_test.coffee b/test/load-multiple-scripts_test.coffee deleted file mode 100644 index 19b80ca..0000000 --- a/test/load-multiple-scripts_test.coffee +++ /dev/null @@ -1,23 +0,0 @@ -Helper = require('../src/index') -helper = new Helper(['./scripts/hello-world.coffee', './scripts/bye.coffee']) - -co = require('co') -expect = require('chai').expect - -describe 'hello-world', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'user says hi to hubot', -> - beforeEach -> - co => - yield @room.user.say 'alice', '@hubot hi' - yield @room.user.say 'bob', '@hubot bye' - - it 'should reply to user', -> - expect(@room.messages).to.eql [ - ['alice', '@hubot hi'] - ['hubot', '@alice hi'] - ['bob', '@hubot bye'] - ['hubot', '@bob bye'] - ] diff --git a/test/load-multiple-scripts_test.js b/test/load-multiple-scripts_test.js new file mode 100644 index 0000000..0f50a66 --- /dev/null +++ b/test/load-multiple-scripts_test.js @@ -0,0 +1,34 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper(['./scripts/hello-world.coffee', './scripts/bye.coffee']); + +const co = require('co'); +const { expect } = require('chai'); + +describe('hello-world', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + return context('user says hi to hubot', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.say('alice', '@hubot hi'); + return yield this.room.user.say('bob', '@hubot bye'); + }.bind(this)); + }); + + return it('should reply to user', function() { + return expect(this.room.messages).to.eql([ + ['alice', '@hubot hi'], + ['hubot', '@alice hi'], + ['bob', '@hubot bye'], + ['hubot', '@bob bye'] + ]); + }); +}); +}); diff --git a/test/mock-response_test.coffee b/test/mock-response_test.coffee deleted file mode 100644 index 50ef691..0000000 --- a/test/mock-response_test.coffee +++ /dev/null @@ -1,27 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/mock-response.coffee') - -co = require('co') -expect = require('chai').expect - -class NewMockResponse extends Helper.Response - random: (items) -> - 3 - -describe 'mock-response', -> - beforeEach -> - @room = helper.createRoom(response: NewMockResponse, httpd: false) - - context 'user says "give me a random" number to hubot', -> - beforeEach -> - co => - yield @room.user.say 'alice', '@hubot give me a random number' - yield @room.user.say 'bob', '@hubot give me a random number' - - it 'should reply to user with a random number', -> - expect(@room.messages).to.eql [ - ['alice', '@hubot give me a random number'] - ['hubot', '@alice 3'] - ['bob', '@hubot give me a random number'] - ['hubot', '@bob 3'] - ] diff --git a/test/mock-response_test.js b/test/mock-response_test.js new file mode 100644 index 0000000..5d11602 --- /dev/null +++ b/test/mock-response_test.js @@ -0,0 +1,40 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/mock-response.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +class NewMockResponse extends Helper.Response { + random(items) { + return 3; + } +} + +describe('mock-response', function() { + beforeEach(function() { + return this.room = helper.createRoom({response: NewMockResponse, httpd: false}); + }); + + return context('user says "give me a random" number to hubot', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.say('alice', '@hubot give me a random number'); + return yield this.room.user.say('bob', '@hubot give me a random number'); + }.bind(this)); + }); + + return it('should reply to user with a random number', function() { + return expect(this.room.messages).to.eql([ + ['alice', '@hubot give me a random number'], + ['hubot', '@alice 3'], + ['bob', '@hubot give me a random number'], + ['hubot', '@bob 3'] + ]); + }); +}); +}); diff --git a/test/private-message_test.coffee b/test/private-message_test.coffee deleted file mode 100644 index 09d8b48..0000000 --- a/test/private-message_test.coffee +++ /dev/null @@ -1,26 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/private-message.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'private-message', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'user asks hubot for a secret', -> - beforeEach -> - co => - yield @room.user.say 'alice', '@hubot tell me a secret' - - it 'should not post to the public channel', -> - expect(@room.messages).to.eql [ - ['alice', '@hubot tell me a secret'] - ] - - it 'should private message user', -> - expect(@room.privateMessages).to.eql { - 'alice': [ - ['hubot', 'whisper whisper whisper'] - ] - } diff --git a/test/private-message_test.js b/test/private-message_test.js new file mode 100644 index 0000000..3e769a7 --- /dev/null +++ b/test/private-message_test.js @@ -0,0 +1,38 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/private-message.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('private-message', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + return context('user asks hubot for a secret', function() { + beforeEach(function() { + return co(function*() { + return yield this.room.user.say('alice', '@hubot tell me a secret'); + }.bind(this)); + }); + + it('should not post to the public channel', function() { + return expect(this.room.messages).to.eql([ + ['alice', '@hubot tell me a secret'] + ]); + }); + + return it('should private message user', function() { + return expect(this.room.privateMessages).to.eql({ + 'alice': [ + ['hubot', 'whisper whisper whisper'] + ] + }); + }); +}); +}); diff --git a/test/scripts/bye.coffee b/test/scripts/bye.coffee deleted file mode 100644 index a9f85cd..0000000 --- a/test/scripts/bye.coffee +++ /dev/null @@ -1,5 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.respond /bye$/i, (msg) -> - msg.reply 'bye' diff --git a/test/scripts/bye.js b/test/scripts/bye.js new file mode 100644 index 0000000..1704fd5 --- /dev/null +++ b/test/scripts/bye.js @@ -0,0 +1,10 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.respond(/bye$/i, msg => msg.reply('bye')) +; diff --git a/test/scripts/custom-text-message.coffee b/test/scripts/custom-text-message.coffee deleted file mode 100644 index 0908e4d..0000000 --- a/test/scripts/custom-text-message.coffee +++ /dev/null @@ -1,7 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.listen( - (message) -> message.isCustom - (response) -> response.send response.message.custom - ) diff --git a/test/scripts/custom-text-message.js b/test/scripts/custom-text-message.js new file mode 100644 index 0000000..30a3140 --- /dev/null +++ b/test/scripts/custom-text-message.js @@ -0,0 +1,12 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.listen( + message => message.isCustom, + response => response.send(response.message.custom)) +; diff --git a/test/scripts/enter-leave.coffee b/test/scripts/enter-leave.coffee deleted file mode 100644 index 840c9ce..0000000 --- a/test/scripts/enter-leave.coffee +++ /dev/null @@ -1,8 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.enter (res) -> - res.send "Hi #{res.message.user.name}!" - - robot.leave (res) -> - res.send "Bye #{res.message.user.name}!" diff --git a/test/scripts/enter-leave.js b/test/scripts/enter-leave.js new file mode 100644 index 0000000..bd3c208 --- /dev/null +++ b/test/scripts/enter-leave.js @@ -0,0 +1,12 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = function(robot) { + robot.enter(res => res.send(`Hi ${res.message.user.name}!`)); + + return robot.leave(res => res.send(`Bye ${res.message.user.name}!`)); +}; diff --git a/test/scripts/events.coffee b/test/scripts/events.coffee deleted file mode 100644 index 9b971c5..0000000 --- a/test/scripts/events.coffee +++ /dev/null @@ -1,9 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.on 'some-event', (some, data) -> - robot.messageRoom 'room1', "got event with #{some} #{data}" - - robot.respond /send event$/i, (msg) -> - robot.emit 'response-event', - content: 'hello' diff --git a/test/scripts/events.js b/test/scripts/events.js new file mode 100644 index 0000000..d945b1e --- /dev/null +++ b/test/scripts/events.js @@ -0,0 +1,15 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = function(robot) { + robot.on('some-event', (some, data) => robot.messageRoom('room1', `got event with ${some} ${data}`)); + + return robot.respond(/send event$/i, msg => + robot.emit('response-event', + {content: 'hello'}) + ); +}; diff --git a/test/scripts/hello-world-listener.coffee b/test/scripts/hello-world-listener.coffee deleted file mode 100644 index 0d73573..0000000 --- a/test/scripts/hello-world-listener.coffee +++ /dev/null @@ -1,9 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.listen( - (message) -> - message.user.name is 'bob' - (response) -> - response.reply 'hi' - ) diff --git a/test/scripts/hello-world-listener.js b/test/scripts/hello-world-listener.js new file mode 100644 index 0000000..4e49409 --- /dev/null +++ b/test/scripts/hello-world-listener.js @@ -0,0 +1,12 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.listen( + message => message.user.name === 'bob', + response => response.reply('hi')) +; diff --git a/test/scripts/hello-world.coffee b/test/scripts/hello-world.coffee deleted file mode 100644 index e65ec41..0000000 --- a/test/scripts/hello-world.coffee +++ /dev/null @@ -1,5 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.respond /hi$/i, (msg) -> - msg.reply 'hi' diff --git a/test/scripts/hello-world.js b/test/scripts/hello-world.js new file mode 100644 index 0000000..dedfb0e --- /dev/null +++ b/test/scripts/hello-world.js @@ -0,0 +1,10 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.respond(/hi$/i, msg => msg.reply('hi')) +; diff --git a/test/scripts/httpd-world.coffee b/test/scripts/httpd-world.coffee deleted file mode 100644 index 9e772a6..0000000 --- a/test/scripts/httpd-world.coffee +++ /dev/null @@ -1,5 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.router.get "/hello/world", (req, res) -> - res.status(200).send("Hello World!") diff --git a/test/scripts/httpd-world.js b/test/scripts/httpd-world.js new file mode 100644 index 0000000..023d141 --- /dev/null +++ b/test/scripts/httpd-world.js @@ -0,0 +1,10 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.router.get("/hello/world", (req, res) => res.status(200).send("Hello World!")) +; diff --git a/test/scripts/mock-response.coffee b/test/scripts/mock-response.coffee deleted file mode 100644 index 0215b67..0000000 --- a/test/scripts/mock-response.coffee +++ /dev/null @@ -1,6 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.respond /give me a random number$/i, (msg) -> - randomNumber = msg.random [1, 2, 3, 4, 5] - msg.reply randomNumber diff --git a/test/scripts/mock-response.js b/test/scripts/mock-response.js new file mode 100644 index 0000000..1498a2e --- /dev/null +++ b/test/scripts/mock-response.js @@ -0,0 +1,13 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.respond(/give me a random number$/i, function(msg) { + const randomNumber = msg.random([1, 2, 3, 4, 5]); + return msg.reply(randomNumber); + }) +; diff --git a/test/scripts/private-message.coffee b/test/scripts/private-message.coffee deleted file mode 100644 index 5f0c64e..0000000 --- a/test/scripts/private-message.coffee +++ /dev/null @@ -1,5 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.respond /tell me a secret$/i, (msg) -> - msg.sendPrivate 'whisper whisper whisper' diff --git a/test/scripts/private-message.js b/test/scripts/private-message.js new file mode 100644 index 0000000..ec00b79 --- /dev/null +++ b/test/scripts/private-message.js @@ -0,0 +1,10 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.respond(/tell me a secret$/i, msg => msg.sendPrivate('whisper whisper whisper')) +; diff --git a/test/scripts/user-params.coffee b/test/scripts/user-params.coffee deleted file mode 100644 index 0eb6a98..0000000 --- a/test/scripts/user-params.coffee +++ /dev/null @@ -1,8 +0,0 @@ -# Description: -# Test script -module.exports = (robot) -> - robot.listen( - () -> true - (response) -> - response.send JSON.stringify(response.message.user) - ) diff --git a/test/scripts/user-params.js b/test/scripts/user-params.js new file mode 100644 index 0000000..c03007a --- /dev/null +++ b/test/scripts/user-params.js @@ -0,0 +1,12 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// Description: +// Test script +module.exports = robot => + robot.listen( + () => true, + response => response.send(JSON.stringify(response.message.user))) +; diff --git a/test/user-params_test.coffee b/test/user-params_test.coffee deleted file mode 100644 index d648adb..0000000 --- a/test/user-params_test.coffee +++ /dev/null @@ -1,22 +0,0 @@ -Helper = require('../src/index') -helper = new Helper('./scripts/user-params.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'enter-leave', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - context 'user entering, leaving the room and sending a message', -> - params = { id: 1, name: 2, profile: 3 } - beforeEach -> - co => - yield @room.user.enter 'user1', params - yield @room.user.say 'user1', 'Hi', params - yield @room.user.leave 'user1', params - - it 'sends back', -> - for msg in @room.messages - if msg[0] is 'hubot' - expect(JSON.parse msg[1]).to.include(params) diff --git a/test/user-params_test.js b/test/user-params_test.js new file mode 100644 index 0000000..db96d02 --- /dev/null +++ b/test/user-params_test.js @@ -0,0 +1,43 @@ +/* + * decaffeinate suggestions: + * DS101: Remove unnecessary use of Array.from + * DS102: Remove unnecessary code created because of implicit returns + * DS205: Consider reworking code to avoid use of IIFEs + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const Helper = require('../src/index'); +const helper = new Helper('./scripts/user-params.coffee'); + +const co = require('co'); +const { expect } = require('chai'); + +describe('enter-leave', function() { + beforeEach(function() { + return this.room = helper.createRoom({httpd: false}); + }); + + return context('user entering, leaving the room and sending a message', function() { + const params = { id: 1, name: 2, profile: 3 }; + beforeEach(function() { + return co(function*() { + yield this.room.user.enter('user1', params); + yield this.room.user.say('user1', 'Hi', params); + return yield this.room.user.leave('user1', params); + }.bind(this)); + }); + + return it('sends back', function() { + return (() => { + const result = []; + for (let msg of Array.from(this.room.messages)) { + if (msg[0] === 'hubot') { + result.push(expect(JSON.parse(msg[1])).to.include(params)); + } else { + result.push(undefined); + } + } + return result; + })(); + }); + }); +}); From 6a621be0863f5c762b9072804ed1566c6f70102b Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Sat, 30 Sep 2017 18:39:39 +0900 Subject: [PATCH 2/2] perf: es2015 --- Dockerfile | 2 +- README.md | 196 ++++++++++++++------------- package.json | 9 +- src/index.js | 90 ++++++------ test/custom-text-message_test.js | 19 +-- test/enter-leave_test.js | 23 ++-- test/events_test.js | 29 ++-- test/hello-world-listener_test.js | 23 ++-- test/hello-world_test.coffee | 25 ++++ test/hello-world_test.js | 25 ++-- test/httpd-world_test.js | 25 ++-- test/load-multiple-scripts_test.js | 23 ++-- test/mock-response_test.js | 23 ++-- test/private-message_test.js | 27 ++-- test/scripts/bye.js | 5 - test/scripts/custom-text-message.js | 5 - test/scripts/enter-leave.js | 5 - test/scripts/events.js | 10 +- test/scripts/hello-world-listener.js | 10 +- test/scripts/hello-world.coffee | 5 + test/scripts/hello-world.js | 5 - test/scripts/httpd-world.js | 5 - test/scripts/mock-response.js | 7 +- test/scripts/private-message.js | 5 - test/scripts/user-params.js | 5 - test/user-params_test.js | 35 ++--- 26 files changed, 290 insertions(+), 351 deletions(-) create mode 100644 test/hello-world_test.coffee create mode 100644 test/scripts/hello-world.coffee diff --git a/Dockerfile b/Dockerfile index cb49be9..4763f28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ -FROM node +FROM node:4 RUN npm install -g yarn diff --git a/README.md b/README.md index 8a93d49..e94b562 100644 --- a/README.md +++ b/README.md @@ -12,46 +12,50 @@ Helper for testing Hubot script. If you have a following hubot script: -```coffee -module.exports = (robot) -> - robot.respond /hi$/i, (msg) -> - msg.reply 'hi' +```javascript +module.exports = robot => + robot.respond(/hi$/i, msg => msg.reply('hi')) ``` You can test it like: -```coffee -Helper = require('hubot-test-helper') -# helper loads all scripts passed a directory -helper = new Helper('./scripts') - -# helper loads a specific script if it's a file -scriptHelper = new Helper('./scripts/specific-script.coffee') - -co = require('co') -expect = require('chai').expect - -describe 'hello-world', -> - - beforeEach -> - @room = helper.createRoom() - - afterEach -> - @room.destroy() - - context 'user says hi to hubot', -> - beforeEach -> - co => - yield @room.user.say 'alice', '@hubot hi' - yield @room.user.say 'bob', '@hubot hi' - - it 'should reply to user', -> - expect(@room.messages).to.eql [ - ['alice', '@hubot hi'] - ['hubot', '@alice hi'] - ['bob', '@hubot hi'] +```javascript +const Helper = require('hubot-test-helper'); +// helper loads all scripts passed a directory +const helper = new Helper('./scripts'); + +// helper loads a specific script if it's a file +const scriptHelper = new Helper('./scripts/specific-script.js'); + +const co = require('co'); +const expect = require('chai').expect; + +describe('hello-world', function() { + beforeEach(function() { + this.room = helper.createRoom(); + }); + afterEach(function() { + this.room.destroy(); + }); + + context('user says hi to hubot', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.say('alice', '@hubot hi'); + yield this.room.user.say('bob', '@hubot hi'); + }.bind(this)); + }); + + it('should reply to user', function() { + expect(this.room.messages).to.eql([ + ['alice', '@hubot hi'], + ['hubot', '@alice hi'], + ['bob', '@hubot hi'], ['hubot', '@bob hi'] - ] + ]); + }); + }); +}); ``` #### HTTPD @@ -62,7 +66,7 @@ tests and so requires it to be shutdown during teardown using `room.destroy()`. This feature can be turned off in tests that don't need it by passing using `helper.createRoom(httpd: false)`. -See [the tests](test/httpd-world_test.coffee) for an example of testing the +See [the tests](test/httpd-world_test.js) for an example of testing the HTTP server. @@ -74,47 +78,53 @@ in testing we may anticipate the delayed reply with a manual time delay. For example we have the following script: -```coffee -module.exports = (robot) -> - robot.hear /(http(?:s?):\/\/(\S*))/i, (res) -> - url = res.match[1] - res.send "ok1: #{url}" - robot.http(url).get() (err, response, body) -> - res.send "ok2: #{url}" +```javascript +module.exports = robot => + robot.hear(/(http(?:s?):\/\/(\S*))/i, res => { + const url = res.match[1]; + res.send(`ok1: ${url}`); + robot.http(url).get()((err, response, body) => res.send(`ok2: ${url}`)); + }); ``` To test the second callback response "ok2: ..." we use the following script: -```coffee -Helper = require('hubot-test-helper') -helper = new Helper('../scripts/http.coffee') - -Promise= require('bluebird') -co = require('co') -expect = require('chai').expect - -# test ping -describe 'http', -> - beforeEach -> - @room = helper.createRoom(httpd: false) - - # Test case - context 'user posts link', -> - beforeEach -> - co => - yield @room.user.say 'user1', 'http://google.com' - # delay one second for the second - # callback message to be posted to @room - yield new Promise.delay(1000) - - # response - it 'expects deplayed callback from ok2', -> - console.log @room.messages - expect(@room.messages).to.eql [ - ['user1', 'http://google.com'] - ['hubot', 'ok1: http://google.com'] +```javascript +const Helper = require('hubot-test-helper'); +const helper = new Helper('../scripts/http.js'); + +const Promise = require('bluebird'); +const co = require('co'); +const expect = require('chai').expect; + +// test ping +describe('http', function() { + beforeEach(function() { + this.room = helper.createRoom({httpd: false}); + }); + + // Test case + context('user posts link', function() { + beforeEach(function() { + return co(function*() { + yield this.room.user.say('user1', 'http://google.com'); + // delay one second for the second + // callback message to be posted to @room + yield new Promise.delay(1000); + }.bind(this)); + }); + + // response + it('expects deplayed callback from ok2', function() { + console.log(this.room.messages); + expect(this.room.messages).to.eql([ + ['user1', 'http://google.com'], + ['hubot', 'ok1: http://google.com'], ['hubot', 'ok2: http://google.com'] - ] + ]); + }); + }); +}); ``` Note that `yield` and *generators* are part of [**ECMA6**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*), so it may not work on older node.js versions. It will wait for the delay to complete the `beforeEach` before proceeding to the test `it`. @@ -128,37 +138,41 @@ may want to test the creation of a Given the following script: -```coffee -module.exports = (robot) -> - - robot.respond /check status$/i, (msg) -> - robot.emit 'slack.attachment', +```javascript +module.exports = robot => + robot.respond(/check status$/i, msg => + robot.emit('slack.attachment', { message: msg.message, content: { - color: "good" + color: "good", text: "It's all good!" } + }) + ) ``` you could test the emitted event like this: -```coffee -Helper = require 'hubot-test-helper' -helper = new Helper('../scripts/status_check.coffee') +```javascript +const Helper = require('hubot-test-helper'); +const helper = new Helper('../scripts/status_check.js'); -expect = require('chai').expect +const expect = require('chai').expect; -describe 'status check', -> - beforeEach -> - @room = helper.createRoom(httpd: false) +describe('status check', function() { + beforeEach(function() { + this.room = helper.createRoom({httpd: false}); + }); - it 'should send a slack event', -> - response = null - @room.robot.on 'slack.attachment', (event) -> - response = event.content + it('should send a slack event', function() { + let response = null; + this.room.robot.on('slack.attachment', event => response = event.content); - @room.user.say('bob', '@hubot check status').then => - expect(response.text).to.eql("It's all good!") + this.room.user.say('bob', '@hubot check status').then(() => { + expect(response.text).to.eql("It's all good!"); + }); + }); +}); ``` ## Development diff --git a/package.json b/package.json index dbe72d9..1f7902b 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,22 @@ { "name": "hubot-test-helper", "description": "Helper for testing hubot script", - "main": "./lib/index.js", + "main": "./src/index.js", "scripts": { "test": "mocha --compilers coffee:coffee-script/register test", - "semantic-release": "semantic-release pre && npm publish && semantic-release post", - "prepublish": "coffee --compile --output lib/ src/" + "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, "keywords": [ "hubot" ], "dependencies": { - "hubot": ">=2.6.0 <10 || 0.0.0-development" + "hubot": ">=3.0.0 <10 || 0.0.0-development" }, "devDependencies": { "chai": "latest", "co": "latest", - "coffee-script": "latest", "mocha": "latest", + "coffee-script": "latest", "semantic-release": "latest" }, "author": "Fumiaki MATSUSHIMA", diff --git a/src/index.js b/src/index.js index faf58b7..dd29a51 100644 --- a/src/index.js +++ b/src/index.js @@ -1,21 +1,16 @@ -/* - * decaffeinate suggestions: - * DS001: Remove Babel/TypeScript constructor workaround - * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns - * DS206: Consider reworking classes to avoid initClass - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Fs = require('fs'); const Path = require('path'); -const Hubot = require('hubot'); +const Hubot = require('hubot/es2015'); process.setMaxListeners(0); class MockResponse extends Hubot.Response { - sendPrivate(...strings) { - return this.robot.adapter.sendPrivate(this.envelope, ...Array.from(strings)); + sendPrivate(/* ...strings*/) { + const strings = [].slice.call(arguments, 0); + + this.robot.adapter.sendPrivate.apply(this.robot.adapter, [this.envelope].concat(strings)); } } @@ -28,36 +23,31 @@ class MockRobot extends Hubot.Robot { } loadAdapter() { - return this.adapter = new Room(this); + this.adapter = new Room(this); } } class Room extends Hubot.Adapter { - constructor(robot) { - { - // Hack: trick Babel/TypeScript into allowing this before super. - if (false) { super(); } - let thisFn = (() => { this; }).toString(); - let thisName = thisFn.slice(thisFn.indexOf('{') + 1, thisFn.indexOf(';')).trim(); - eval(`${thisName} = this;`); + // XXX: https://github.com/hubotio/hubot/pull/1390 + static messages(obj) { + if (obj instanceof MockRobot) { + return obj.adapter.messages; + } else { + return obj.messages; } + } + + constructor(robot) { + super(); this.robot = robot; this.messages = []; this.privateMessages = {}; this.user = { - say: (userName, message, userParams) => { - return this.receive(userName, message, userParams); - }, - - enter: (userName, userParams) => { - return this.enter(userName, userParams); - }, - - leave: (userName, userParams) => { - return this.leave(userName, userParams); - } + say: (userName, message, userParams) => this.receive(userName, message, userParams), + enter: (userName, userParams) => this.enter(userName, userParams), + leave: (userName, userParams) => this.leave(userName, userParams) }; } @@ -74,31 +64,37 @@ class Room extends Hubot.Adapter { } this.messages.push([userName, textMessage.text]); - return this.robot.receive(textMessage, resolve); + this.robot.receive(textMessage, resolve); }); } destroy() { - if (this.robot.server) { return this.robot.server.close(); } + if (this.robot.server) { this.robot.server.close(); } } - reply(envelope, ...strings) { - return Array.from(strings).map((str) => this.messages.push(['hubot', `@${envelope.user.name} ${str}`])); + reply(envelope/*, ...strings*/) { + const strings = [].slice.call(arguments, 1); + + strings.forEach((str) => Room.messages(this).push(['hubot', `@${envelope.user.name} ${str}`])); } - send(envelope, ...strings) { - return Array.from(strings).map((str) => this.messages.push(['hubot', str])); + send(envelope/*, ...strings*/) { + const strings = [].slice.call(arguments, 1); + + strings.forEach((str) => Room.messages(this).push(['hubot', str])); } - sendPrivate(envelope, ...strings) { + sendPrivate(envelope/*, ...strings*/) { + const strings = [].slice.call(arguments, 1); + if (!(envelope.user.name in this.privateMessages)) { this.privateMessages[envelope.user.name] = []; } - return Array.from(strings).map((str) => this.privateMessages[envelope.user.name].push(['hubot', str])); + strings.forEach((str) => this.privateMessages[envelope.user.name].push(['hubot', str])); } robotEvent() { - return this.robot.emit.apply(this.robot, arguments); + this.robot.emit.apply(this.robot, arguments); } enter(userName, userParams) { @@ -106,7 +102,7 @@ class Room extends Hubot.Adapter { return new Promise(resolve => { userParams.room = this.name; const user = new Hubot.User(userName, userParams); - return this.robot.receive(new Hubot.EnterMessage(user), resolve); + this.robot.receive(new Hubot.EnterMessage(user), resolve); }); } @@ -115,16 +111,12 @@ class Room extends Hubot.Adapter { return new Promise(resolve => { userParams.room = this.name; const user = new Hubot.User(userName, userParams); - return this.robot.receive(new Hubot.LeaveMessage(user), resolve); + this.robot.receive(new Hubot.LeaveMessage(user), resolve); }); } } class Helper { - static initClass() { - this.Response = MockResponse; - } - constructor(scriptsPaths) { if (!Array.isArray(scriptsPaths)) { scriptsPaths = [scriptsPaths]; @@ -140,10 +132,10 @@ class Helper { robot.Response = options.response; } - for (let script of Array.from(this.scriptsPaths)) { + for (let script of this.scriptsPaths) { script = Path.resolve(Path.dirname(module.parent.filename), script); if (Fs.statSync(script).isDirectory()) { - for (let file of Array.from(Fs.readdirSync(script).sort())) { + for (let file of Fs.readdirSync(script).sort()) { robot.loadFile(script, file); } } else { @@ -157,6 +149,6 @@ class Helper { return robot.adapter; } } -Helper.initClass(); +Helper.Response = MockResponse; module.exports = Helper; diff --git a/test/custom-text-message_test.js b/test/custom-text-message_test.js index 3944f4b..208dfd6 100644 --- a/test/custom-text-message_test.js +++ b/test/custom-text-message_test.js @@ -1,32 +1,27 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ const Helper = require('../src/index'); -const helper = new Helper('./scripts/custom-text-message.coffee'); +const helper = new Helper('./scripts/custom-text-message.js'); const Hubot = require('hubot'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('custom-text-message', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); - return context('Passing a custom text message object', function() { + context('Passing a custom text message object', function() { beforeEach(function() { return co(function*() { const textMessage = new Hubot.TextMessage({}, ''); textMessage.isCustom = true; textMessage.custom = 'custom'; - return yield this.room.user.say('user', textMessage); + yield this.room.user.say('user', textMessage); }.bind(this)); }); - return it('sends back', function() { - return expect(this.room.messages[1][1]).to.be.equal('custom'); + it('sends back', function() { + expect(this.room.messages[1][1]).to.be.equal('custom'); }); }); }); diff --git a/test/enter-leave_test.js b/test/enter-leave_test.js index 99c6803..b5ccd4d 100644 --- a/test/enter-leave_test.js +++ b/test/enter-leave_test.js @@ -1,32 +1,29 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/enter-leave.coffee'); +const helper = new Helper('./scripts/enter-leave.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('enter-leave', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); - return context('user entering then leaving the room', function() { + context('user entering then leaving the room', function() { beforeEach(function() { return co(function*() { yield this.room.user.enter('user1'); - return yield this.room.user.leave('user1'); + yield this.room.user.leave('user1'); }.bind(this)); }); - return it('greets the user', function() { - return expect(this.room.messages).to.eql([ + it('greets the user', function() { + expect(this.room.messages).to.eql([ ['hubot', 'Hi user1!'], ['hubot', 'Bye user1!'] ]); + }); }); }); -}); diff --git a/test/events_test.js b/test/events_test.js index 543169e..3ed588e 100644 --- a/test/events_test.js +++ b/test/events_test.js @@ -1,40 +1,35 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/events.coffee'); +const helper = new Helper('./scripts/events.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('events', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); context('should post on an event', function() { beforeEach(function() { - return this.room.robotEvent('some-event', 'event', 'data'); + this.room.robotEvent('some-event', 'event', 'data'); }); - return it('should reply to user', function() { - return expect(this.room.messages).to.eql([ + it('should reply to user', function() { + expect(this.room.messages).to.eql([ ['hubot', 'got event with event data'] ]); + }); }); -}); - - return context('should hear events emitted by responses', () => - + context('should hear events emitted by responses', () => it('should trigger an event', function() { let response = null; this.room.robot.on('response-event', event => response = event.content); - return this.room.user.say('bob', '@hubot send event').then(() => { - return expect(response).to.eql('hello'); + this.room.user.say('bob', '@hubot send event').then(() => { + expect(response).to.eql('hello'); }); }) ); diff --git a/test/hello-world-listener_test.js b/test/hello-world-listener_test.js index 4e69019..6cf4ef7 100644 --- a/test/hello-world-listener_test.js +++ b/test/hello-world-listener_test.js @@ -1,33 +1,30 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/hello-world-listener.coffee'); +const helper = new Helper('./scripts/hello-world-listener.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('hello-world', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); - return context('user says hi to hubot', function() { + context('user says hi to hubot', function() { beforeEach(function() { return co(function*() { yield this.room.user.say('alice', '@hubot hi'); - return yield this.room.user.say('bob', '@hubot hi'); + yield this.room.user.say('bob', '@hubot hi'); }.bind(this)); }); - return it('should reply to user', function() { - return expect(this.room.messages).to.eql([ + it('should reply to user', function() { + expect(this.room.messages).to.eql([ ['alice', '@hubot hi'], ['bob', '@hubot hi'], ['hubot', '@bob hi'] ]); + }); }); }); -}); diff --git a/test/hello-world_test.coffee b/test/hello-world_test.coffee new file mode 100644 index 0000000..2f01e44 --- /dev/null +++ b/test/hello-world_test.coffee @@ -0,0 +1,25 @@ +Helper = require('../src/index') +helper = new Helper('./scripts/hello-world.coffee') + +co = require('co') +expect = require('chai').expect + +describe 'hello-world', -> + beforeEach -> + @room = helper.createRoom(httpd: false) + afterEach -> + @room.destroy() + + context 'user says hi to hubot', -> + beforeEach -> + co => + yield @room.user.say 'alice', '@hubot hi' + yield @room.user.say 'bob', '@hubot hi' + + it 'should reply to user', -> + expect(@room.messages).to.eql [ + ['alice', '@hubot hi'] + ['hubot', '@alice hi'] + ['bob', '@hubot hi'] + ['hubot', '@bob hi'] + ] diff --git a/test/hello-world_test.js b/test/hello-world_test.js index 0b35562..4c57d89 100644 --- a/test/hello-world_test.js +++ b/test/hello-world_test.js @@ -1,37 +1,34 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/hello-world.coffee'); +const helper = new Helper('./scripts/hello-world.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('hello-world', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); afterEach(function() { - return this.room.destroy(); + this.room.destroy(); }); - return context('user says hi to hubot', function() { + context('user says hi to hubot', function() { beforeEach(function() { return co(function*() { yield this.room.user.say('alice', '@hubot hi'); - return yield this.room.user.say('bob', '@hubot hi'); + yield this.room.user.say('bob', '@hubot hi'); }.bind(this)); }); - return it('should reply to user', function() { - return expect(this.room.messages).to.eql([ + it('should reply to user', function() { + expect(this.room.messages).to.eql([ ['alice', '@hubot hi'], ['hubot', '@alice hi'], ['bob', '@hubot hi'], ['hubot', '@bob hi'] ]); + }); }); }); -}); diff --git a/test/httpd-world_test.js b/test/httpd-world_test.js index 4869d3a..2dcc8e2 100644 --- a/test/httpd-world_test.js +++ b/test/httpd-world_test.js @@ -1,33 +1,32 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); const helper = new Helper('./scripts'); const http = require('http'); -const { expect } = require('chai'); +const expect = require('chai').expect; process.env.EXPRESS_PORT = 8080; describe('httpd-world', function() { beforeEach(function() { - return this.room = helper.createRoom(); + this.room = helper.createRoom(); }); afterEach(function() { - return this.room.destroy(); + this.room.destroy(); }); - return context('GET /hello/world', function() { + context('GET /hello/world', function() { beforeEach(function(done) { - return http.get('http://localhost:8080/hello/world', response => { this.response = response; return done(); }) - .on('error', done); + http.get('http://localhost:8080/hello/world', response => { + this.response = response; + done(); + }).on('error', done); }); - return it('responds with status 200', function() { - return expect(this.response.statusCode).to.equal(200); + it('responds with status 200', function() { + expect(this.response.statusCode).to.equal(200); }); }); }); diff --git a/test/load-multiple-scripts_test.js b/test/load-multiple-scripts_test.js index 0f50a66..427e85e 100644 --- a/test/load-multiple-scripts_test.js +++ b/test/load-multiple-scripts_test.js @@ -1,34 +1,31 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper(['./scripts/hello-world.coffee', './scripts/bye.coffee']); +const helper = new Helper(['./scripts/hello-world.js', './scripts/bye.js']); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('hello-world', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); - return context('user says hi to hubot', function() { + context('user says hi to hubot', function() { beforeEach(function() { return co(function*() { yield this.room.user.say('alice', '@hubot hi'); - return yield this.room.user.say('bob', '@hubot bye'); + yield this.room.user.say('bob', '@hubot bye'); }.bind(this)); }); - return it('should reply to user', function() { - return expect(this.room.messages).to.eql([ + it('should reply to user', function() { + expect(this.room.messages).to.eql([ ['alice', '@hubot hi'], ['hubot', '@alice hi'], ['bob', '@hubot bye'], ['hubot', '@bob bye'] ]); + }); }); }); -}); diff --git a/test/mock-response_test.js b/test/mock-response_test.js index 5d11602..d116ab7 100644 --- a/test/mock-response_test.js +++ b/test/mock-response_test.js @@ -1,13 +1,10 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/mock-response.coffee'); +const helper = new Helper('./scripts/mock-response.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; class NewMockResponse extends Helper.Response { random(items) { @@ -17,24 +14,24 @@ class NewMockResponse extends Helper.Response { describe('mock-response', function() { beforeEach(function() { - return this.room = helper.createRoom({response: NewMockResponse, httpd: false}); + this.room = helper.createRoom({response: NewMockResponse, httpd: false}); }); - return context('user says "give me a random" number to hubot', function() { + context('user says "give me a random" number to hubot', function() { beforeEach(function() { return co(function*() { yield this.room.user.say('alice', '@hubot give me a random number'); - return yield this.room.user.say('bob', '@hubot give me a random number'); + yield this.room.user.say('bob', '@hubot give me a random number'); }.bind(this)); }); - return it('should reply to user with a random number', function() { - return expect(this.room.messages).to.eql([ + it('should reply to user with a random number', function() { + expect(this.room.messages).to.eql([ ['alice', '@hubot give me a random number'], ['hubot', '@alice 3'], ['bob', '@hubot give me a random number'], ['hubot', '@bob 3'] ]); + }); }); }); -}); diff --git a/test/private-message_test.js b/test/private-message_test.js index 3e769a7..cd4ba61 100644 --- a/test/private-message_test.js +++ b/test/private-message_test.js @@ -1,38 +1,35 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/private-message.coffee'); +const helper = new Helper('./scripts/private-message.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('private-message', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); - return context('user asks hubot for a secret', function() { + context('user asks hubot for a secret', function() { beforeEach(function() { return co(function*() { - return yield this.room.user.say('alice', '@hubot tell me a secret'); + yield this.room.user.say('alice', '@hubot tell me a secret'); }.bind(this)); }); it('should not post to the public channel', function() { - return expect(this.room.messages).to.eql([ + expect(this.room.messages).to.eql([ ['alice', '@hubot tell me a secret'] ]); - }); + }); - return it('should private message user', function() { - return expect(this.room.privateMessages).to.eql({ + it('should private message user', function() { + expect(this.room.privateMessages).to.eql({ 'alice': [ ['hubot', 'whisper whisper whisper'] ] }); + }); }); }); -}); diff --git a/test/scripts/bye.js b/test/scripts/bye.js index 1704fd5..e160cba 100644 --- a/test/scripts/bye.js +++ b/test/scripts/bye.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => diff --git a/test/scripts/custom-text-message.js b/test/scripts/custom-text-message.js index 30a3140..6c482ef 100644 --- a/test/scripts/custom-text-message.js +++ b/test/scripts/custom-text-message.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => diff --git a/test/scripts/enter-leave.js b/test/scripts/enter-leave.js index bd3c208..3f0f1c7 100644 --- a/test/scripts/enter-leave.js +++ b/test/scripts/enter-leave.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = function(robot) { diff --git a/test/scripts/events.js b/test/scripts/events.js index d945b1e..e77ba88 100644 --- a/test/scripts/events.js +++ b/test/scripts/events.js @@ -1,15 +1,7 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = function(robot) { robot.on('some-event', (some, data) => robot.messageRoom('room1', `got event with ${some} ${data}`)); - return robot.respond(/send event$/i, msg => - robot.emit('response-event', - {content: 'hello'}) - ); + robot.respond(/send event$/i, msg => robot.emit('response-event', {content: 'hello'})); }; diff --git a/test/scripts/hello-world-listener.js b/test/scripts/hello-world-listener.js index 4e49409..d513071 100644 --- a/test/scripts/hello-world-listener.js +++ b/test/scripts/hello-world-listener.js @@ -1,12 +1,4 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => - robot.listen( - message => message.user.name === 'bob', - response => response.reply('hi')) -; + robot.listen(message => message.user.name === 'bob', response => response.reply('hi')) diff --git a/test/scripts/hello-world.coffee b/test/scripts/hello-world.coffee new file mode 100644 index 0000000..e65ec41 --- /dev/null +++ b/test/scripts/hello-world.coffee @@ -0,0 +1,5 @@ +# Description: +# Test script +module.exports = (robot) -> + robot.respond /hi$/i, (msg) -> + msg.reply 'hi' diff --git a/test/scripts/hello-world.js b/test/scripts/hello-world.js index dedfb0e..67dce1d 100644 --- a/test/scripts/hello-world.js +++ b/test/scripts/hello-world.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => diff --git a/test/scripts/httpd-world.js b/test/scripts/httpd-world.js index 023d141..2325990 100644 --- a/test/scripts/httpd-world.js +++ b/test/scripts/httpd-world.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => diff --git a/test/scripts/mock-response.js b/test/scripts/mock-response.js index 1498a2e..cbb7679 100644 --- a/test/scripts/mock-response.js +++ b/test/scripts/mock-response.js @@ -1,13 +1,8 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => robot.respond(/give me a random number$/i, function(msg) { const randomNumber = msg.random([1, 2, 3, 4, 5]); - return msg.reply(randomNumber); + msg.reply(randomNumber); }) ; diff --git a/test/scripts/private-message.js b/test/scripts/private-message.js index ec00b79..b73b1ff 100644 --- a/test/scripts/private-message.js +++ b/test/scripts/private-message.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => diff --git a/test/scripts/user-params.js b/test/scripts/user-params.js index c03007a..db8eaee 100644 --- a/test/scripts/user-params.js +++ b/test/scripts/user-params.js @@ -1,8 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ // Description: // Test script module.exports = robot => diff --git a/test/user-params_test.js b/test/user-params_test.js index db96d02..9aa221a 100644 --- a/test/user-params_test.js +++ b/test/user-params_test.js @@ -1,43 +1,32 @@ -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns - * DS205: Consider reworking code to avoid use of IIFEs - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ +'use strict' + const Helper = require('../src/index'); -const helper = new Helper('./scripts/user-params.coffee'); +const helper = new Helper('./scripts/user-params.js'); const co = require('co'); -const { expect } = require('chai'); +const expect = require('chai').expect; describe('enter-leave', function() { beforeEach(function() { - return this.room = helper.createRoom({httpd: false}); + this.room = helper.createRoom({httpd: false}); }); - return context('user entering, leaving the room and sending a message', function() { + context('user entering, leaving the room and sending a message', function() { const params = { id: 1, name: 2, profile: 3 }; beforeEach(function() { return co(function*() { yield this.room.user.enter('user1', params); yield this.room.user.say('user1', 'Hi', params); - return yield this.room.user.leave('user1', params); + yield this.room.user.leave('user1', params); }.bind(this)); }); - return it('sends back', function() { - return (() => { - const result = []; - for (let msg of Array.from(this.room.messages)) { - if (msg[0] === 'hubot') { - result.push(expect(JSON.parse(msg[1])).to.include(params)); - } else { - result.push(undefined); - } + it('sends back', function() { + for (let msg of this.room.messages) { + if (msg[0] === 'hubot') { + expect(JSON.parse(msg[1])).to.include(params) } - return result; - })(); + } }); }); });