Skip to content

Commit

Permalink
migrate user.coffee to es6 hubotio#1138
Browse files Browse the repository at this point in the history
  • Loading branch information
gasolin committed Mar 30, 2016
1 parent b9adae6 commit a38d7e2
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["add-module-exports"]
}
2 changes: 1 addition & 1 deletion bin/hubot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# vim:ft=coffee ts=2 sw=2 et :
# -*- mode:coffee -*-

Hubot = require '..'
Hubot = require '../dist'

Fs = require 'fs'
OptParse = require 'optparse'
Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,33 @@
"scoped-http-client": "0.11.0"
},
"devDependencies": {
"hubot-mock-adapter": "^1.0.0",
"babel-cli": "^6.6.5",
"babel-core": "^6.7.4",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.7.2",
"chai": "~2.1.0",
"coffee-errors": "0.8.6",
"hubot-mock-adapter": "^1.0.0",
"mocha": "^2.1.0",
"mockery": "^1.4.0",
"sinon-chai": "^2.8.0",
"sinon": "~1.17.0",
"chai": "~2.1.0"
"sinon-chai": "^2.8.0"
},
"engines": {
"node": ">= 0.8.x",
"npm": ">= 1.1.x"
},
"main": "./index",
"main": "dist/index.js",
"bin": {
"hubot": "./bin/hubot"
},
"scripts": {
"test": "./script/test"
"test": "./script/test",
"prebuild": "rm -rf dist && mkdir dist",
"build": "npm run build_coffee && npm run build_es6",
"build_coffee": "cp index.coffee dist/index.coffee && cp -r src dist/src",
"build_es6": "babel src/user.js -o dist/src/user.js",
"postbuild": "cp package.json dist/"
}
}
3 changes: 3 additions & 0 deletions script/release
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cd $(dirname "$0")/..

npm update && script/smoke-test

# compile hubot to dist/
npm run build

# Make sure we're on the master branch.

(git branch | grep -q '* master') || {
Expand Down
2 changes: 1 addition & 1 deletion script/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

source script/bootstrap
mocha --require coffee-errors --compilers coffee:coffee-script "$@"
mocha --require coffee-errors --compilers coffee:coffee-script,js:babel-register "$@"
11 changes: 0 additions & 11 deletions src/user.coffee

This file was deleted.

18 changes: 18 additions & 0 deletions src/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Represents a participating user in the chat.
*
* @param {string} id - A unique ID for the user.
* @param {object} options - An optional Hash of key, value pairs for this user.
*/
class User {
constructor(id, options = {}) {
this.id = id;
let ref = options || {};
for (let key of Object.keys(ref)) {
this[key] = options[key];
}
this['name'] || (this['name'] = this.id.toString());
}
}

export default User;
2 changes: 1 addition & 1 deletion test/brain_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chai.use require 'sinon-chai'

# Hubot classes
Brain = require '../src/brain.coffee'
User = require '../src/user.coffee'
User = require '../src/user'

describe 'Brain', ->
beforeEach ->
Expand Down
12 changes: 6 additions & 6 deletions test/listener_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ chai.use require 'sinon-chai'
{ CatchAllMessage, EnterMessage, TextMessage } = require '../src/message'
{ Listener, TextListener } = require '../src/listener'
Response = require '../src/response.coffee'
User = require '../src/user.coffee'
User = require '../src/user'

describe 'Listener', ->
beforeEach ->
Expand Down Expand Up @@ -287,21 +287,21 @@ describe 'Listener', ->
testMessage = new TextMessage(@user, 'test')
testMessage.match = sinon.stub().returns(true)
testRegex = /test/

testListener = new TextListener(@robot, testRegex, callback)
result = testListener.matcher(testMessage)

expect(result).to.be.ok
expect(testMessage.match).to.have.been.calledWith(testRegex)

it 'does not match EnterMessages', ->
callback = sinon.spy()
testMessage = new EnterMessage(@user)
testMessage.match = sinon.stub().returns(true)
testRegex = /test/

testListener = new TextListener(@robot, testRegex, callback)
result = testListener.matcher(testMessage)

expect(result).to.not.be.ok
expect(testMessage.match).to.not.have.been.called
2 changes: 1 addition & 1 deletion test/message_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chai.use require 'sinon-chai'
{ expect } = chai

# Hubot classes
User = require '../src/user.coffee'
User = require '../src/user'
{ CatchAllMessage, EnterMessage, Message, TextMessage } = require '../src/message'

describe 'Message', ->
Expand Down
2 changes: 1 addition & 1 deletion test/user_test.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{expect} = require 'chai'
User = require '../src/user.coffee'
User = require '../src/user'

describe 'User', ->
describe 'new', ->
Expand Down

0 comments on commit a38d7e2

Please sign in to comment.