From 6a621be0863f5c762b9072804ed1566c6f70102b Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Sat, 30 Sep 2017 18:39:39 +0900 Subject: [PATCH] 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; - })(); + } }); }); });