
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
hubot-mock-adapter
Advanced tools
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.
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)");
});
};
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!
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!
FAQs
A mock Adapter for unit testing Hubot scripts
The npm package hubot-mock-adapter receives a total of 23 weekly downloads. As such, hubot-mock-adapter popularity was classified as not popular.
We found that hubot-mock-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.