hubot-pretend
v1.2.0
Published
Test Hubot scripts with a mock robot, rooms and users.
Downloads
2,346
Maintainers
Readme
Hubot Pretend
Pretend is a powerful test suite for Hubot, providing mock messaging and internal processes, with helpers to make shorthand assertions using mocha, chai and sinon.
Install
npm install hubot-pretend --save-dev
or
yarn add hubot-pretend --dev
Usage examples
See the docs for specific usage examples
Quick Usage
We have the following Hubot script (hello-world.coffee)...
module.exports = (robot) ->
robot.respond /hello$/i, (msg) -> msg.reply 'hello'
Test file processes some messages...
const pretend = require('hubot-pretend')
const {expect} = require('chai')
describe('Hello World', function () {
it('says hello back', function (done) {
pretend.read('scripts/hello-world.coffee').start()
pretend.user('margaret').send('hubot hello').then(function() {
expect(pretend.messages).to.eql([
['margaret', 'hubot hello'],
['hubot', '@margaret hello']
])
pretend.shutdown()
done()
})
})
})
.read
reads in scripts (can be done before test).start
creates a robot and adapter to route messages.user
creates user with helpers for pre-populated message envelopes.send
passes messages torobot.receive
and returns a promise*.messages
keeps a record of all messages sent and received by the robot.shutdown
resets collections and runs shutdown on the robot
This example shows a minimal dependency approach using the tests's done
function on the promise .then
.
Other examples in the docs show how to improve the style of such tests using generators with co.
Important Notes
Currently has trouble installing in node v8, I think because of incompatibility with dependencies for node v4. Needs more testing and possibly prune some less important deps. For now node v8 is being removed from Travis supported versions.
Script paths are resolved from the package root, not relative to tests.
Currently, Pretend uses a custom fork of hubot that adds promises to middleware, to allow async tests. It can test your hubot scripts, but it won't use your own package's hubot version. Hopefully in later versions of hubot, async will be supported and Pretend can be adapted to test with the exact dependencies of your hubot projects.
Contributing
This is a fairly new project, so there's no contrib guidelines yet. Just follow the standard process.
See the TODO list below for the roadmap of objectives if you'd like to help. Or just create an issue and start working on it if you've found something wrong.
Use the NPM scripts to test and build any changes:
npm run test
- lint and test current buildnpm run dev
- lint, compile and test development changesnpm run dev:watch
- run dev scripts automatically on changenpm run build
- lint, compile, test, regenerate docs
NB: Before publishing, build from Node v4 to ensure babel compatibility
NB: Full test includes usage with compiled JS from build (not tested in dev)
Follow standardsj syntax to avoid bikeshedding.
Use the commitizen cli for writing commit messages.
TODO
- fix dependency incompatibility between node 4 and 8
- generate coverage and write missing module tests
- clean up jsDoc format for default export modules
- convert co usage to babel async/await
- convert room/user messages to property getter
- link back to docs for HTH #32, #37, #38
- helper methods to test hubot brain - HTH #31
- helper methods to test user id, other attributes - HTH #26
- helpers and promise returns for get/post request tests
- add end to end test with internal IRC server and adapter