npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hubot-pretend

v1.2.0

Published

Test Hubot scripts with a mock robot, rooms and users.

Downloads

2,346

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.

npm version Build Status dependencies Status devDependencies Status

semantic-release Commitizen friendly JavaScript Style Guide License: MIT


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 to robot.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 build
  • npm run dev - lint, compile and test development changes
  • npm run dev:watch - run dev scripts automatically on change
  • npm 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