
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
depends-on
Advanced tools
Spins up external processes your tests need. Think of it as async.auto
with process control for integration tests.
{
"redis": {
"cmd": ["/usr/sbin/redis-server"],
"wait_for": {
"port": 6379
}
}
}
var ready = require('depends-on')('redis');
var test = require('tape');
test('init', ready);
< … tests that use redis here … >
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 when your node process exits.
Dependencies can have dependencies. Say you want to clear all values from Redis after it starts, but before your tests run:
{
"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
}
}
}
var ready = require('depends-on')('fresh & clean redis');
var test = require('tape');
test('start fresh redis', ready);
test('test that uses redis', function(t) {
…
});
…
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 exit.
dependencies.json
is a file containing a json object mapping dependency names to objects that describe each dependency.
One of port
or exit_code
is required to use wait_for
.
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
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.