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

actuator

v0.0.2

Published

A small utility for easily unit testing Hubot scripts.

Downloads

1,788

Readme

Actuator

Actuator is a tiny wrapper around a mock hubot adapter that makes it easier to write unit tests for Hubot scripts.

Note: This project is in early development, and versioning is a little different. Read this for more details.

Installation

$ npm install actuator --save-dev

Usage example:

{expect} = require 'chai'

hubot = require 'actuator'

beforeEach (done) ->
  hubot.initiate(script: './lib/hubot_script.coffee', done)

afterEach ->
  hubot.terminate()

describe 'test hubot script', ->

  it 'should have 3 help commands', (done) ->
    expect(hubot.robot.helpCommands()).to.have.length(3)
    done()

  it 'should parse help', (done) ->
    hubot.on('hubot help')
      .spread (response) ->
        expect(response).to.equal """
        hubot actuator - actuator is awesome.
        hubot help - Displays all of the help commands that hubot knows about.
        hubot help <query> - Displays all help commands that match <query>.
        """
      .done(done.bind(@, null), done)

  it 'should respond to messages', (done) ->
    hubot.on('hubot actuator')
      .spread (response) ->
        expect(response).to.equal 'actuator is awesome'
      .done(done.bind(@, null), done)

API Usage

actuator.initiate(settings, done)

This starts up a Hubot instance to run all your tests against. It is required for this module to work, and belongs in your test runner's beforeEach hook. It is asynchronous, and requires done to be passed to it from beforeEach. settings is a JavaScript object with only one property at the moment: script. settings.script is essentially just the path to the script that you want to test.

e.g.

beforeEach (done) ->
  actuator.initiate(script: './lib/your_hubot_script.coffee', done)

actuator.terminate()

This shuts down the Hubot instance and it's webserver. Calling this in your test runner's afterEach hook is necessary in order to prevent any weird errors (like the ports Hubot runs on being regarded as in use).

e.g.

afterEach ->
  actuator.terminate()

actuator.robot

This is a direct reference to the Hubot instance itself. Any properties you might need to reference from Hubot can be found here.

e.g.

it 'should have 3 help commands', (done) ->
  expect(actuator.robot.helpCommands()).to.have.length(3)
  done()

actuator.on(command)

This is where the magic happens. This method is used to listen for Hubot commands and assert their response. command is a string for the command Hubot should be listening for.

This method is asynchronous and returns a promise for Hubot's response to the command. The responses thenable is an array of all the msg.send calls in Hubot's handler for that command.

For example, if your Hubot script listens for "hubot greet me twice", like so:

module.exports = (robot) ->
  robot.respond /greet me twice/i, (msg) ->
    msg.send("Hi there.")
    msg.send("Wassup!?")

...then this is what your test would look like:

it 'responds with two greetings', (done) ->
  actuator.on('hubot greet me twice')
    .then (responses) ->
      expect(responses[0]).to.equal "Hi there."
      expect(responses[1]).to.equal "Wassup!?"
    .then -> done()
    .catch done

Since this returns a when.js promise (which has some excellent documentation), we can actually make the above test simpler like so:

it 'responds with two greetings', (done) ->
  actuator.on('hubot greet me twice')
    .spread (first_greeting, second_greeting) ->
      expect(first_greeting).to.equal "Hi there."
      expect(second_greeting).to.equal "Wassup!?"
    .done(done.bind(@, null), done)