Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hubot-mock-adapter

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hubot-mock-adapter

A mock Adapter for unit testing Hubot scripts

  • 2.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Mock adapter for unit-testing Hubot

Pipeline Status

I've whacked together a couple of Hubot scripts, but then they started getting more complicated. TDD is really the ONLY way to do any kind of meaningful development. But even if you're not TDD'ing, you are testing, right? Right?

I couldn't find an existing method for writing unit tests for Hubot scripts. After digging around under Hubot's hood, I figured out all I really needed was an Adapter implementation I could spy on. That is what you see here.

Example Usage

Let's assume you've got a really simple script, like this:

module.exports = function (robot) {
  robot.hear(/Computer!/, function (msg) {
    msg.reply("Why hello there! (ticker tape, ticker tape)");
  });
};

Node Test Runner

Create a test file in a folder. e.g. index.test.mjs.

You'll need a Node version > 17.

Assuming your tests are in test/ or have .test. before the file extension, just run node --test. For less typing, in your package.json, add a test script:

"scripts": {
  "test": "node --test"
}

Then you can use npm test to run your tests!

Mocha

Create a test file in a folder. e.g. index.js.

You'll need devDependencies something like this in your package.json:

"devDependencies": {
  "coffeescript": "^2.7.0",
  "chai": "^4.3.7",
  "hubot-mock-adapter": "^1.x.x",
  "mocha": "^10.2.0",
  "hubot": "^7.x.x",
}

Assuming your tests are in test/, just run node_modules/.bin/mocha --exit. For less typing, in your package.json, add a test script:

"scripts": {
  "test": "mocha --exit"
}

Then you can use npm test to run your tests!

Keywords

FAQs

Package last updated on 01 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc