Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
depends-on
Advanced tools
Manages the external services that your tests depend on. Think of it as async.auto with process control for integration tests.
dependencies.json
is a file describing your dependencies. Keep it next to your tests.
test-thing.js
:
var ready = require('depends-on')('redis');
var test = require('tape');
test('init dependencies for ' + __filename, ready);
test('test that uses redis', function(t) {
…
});
dependencies.json
:
{
"redis": {
"cmd": ["/usr/sbin/redis-server"],
"wait_for": {
"port": 6379
}
}
}
ready()
is a function that takes a callback (or a tape test object). It will call that callback when your dependencies are ready. They'll be stopped automatically when your tests are done.
Dependencies can have dependencies. This is the typical use case, where multiple services must start before your tests can run.
Building on the previous example, say you want to clear all values from (or load some fixtures into) Redis after it starts, but before your tests run.
test-other-thing.js
:
var ready = require('depends-on')('fresh & clean redis');
var test = require('tape');
test('start fresh redis', ready);
test('test that uses redis', function(t) {
…
});
dependencies.json
:
{
"redis-server": {
"cmd": ["/usr/sbin/redis-server"],
"wait_for": {
"port": 6379
}
},
"fresh & clean redis": {
"cmd": ["./bin/flushall.sh"],
"depends": ["redis-server"],
"wait_for": {
"exit_code": 0
}
}
}
If multiple tests are require()
'd and share dependencies, depends-on will share them across the test files, each dependency only being started once. When node exits, all dependencies will stopped (by default with SIGTERM
but the signal is configurable).
dependencies.json
is a file containing a json object mapping dependency names to objects that describe each dependency.
You can wait for either a socket to be accepting connections or for a process to exit, so one of port
or exit_code
is required to use wait_for
.
"wait_for": {
"host": "127.0.0.1",
"port": 22181,
"timeout": 30
}
By default, depends-on will throw an error if one of the processes it starts exits before your tests are done. Use an exit_code
in your wait_for
block if a process is expected to complete and exit prior to tests running (maybe you're loading a db schema).
"wait_for": {
"exit_code": 0,
"timeout": 120
}
Just for fun, bin/graph-dependencies.js
can graph the dependencies in your project with graphviz.
For example, graphing the dependencies in this repo's fixtures:
dot -Tpng -odeps.png <(./bin/graph-dependencies.js) && open deps.png
->
Be sure to require('depends-on')
before you require('tape')
. Like this:
var ready = require('depends-on')('something');
var test = require('tape');
Both depends-on and tape have process.on('exit', …)
handlers, but tape calls process.exit
in its process.on('exit', …)
handler, so if tape's handler runs first, depends-on's handler will never run (and child processes won't be cleaned up). Handlers run in the order they are added, so depends-on must be required first.
I like to be able to run integration tests individually like $ node tests.js
without running anything else or relying on some external service coincidentally being on.
FAQs
Spins up external processes your tests need
The npm package depends-on receives a total of 0 weekly downloads. As such, depends-on popularity was classified as not popular.
We found that depends-on demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.