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

depends-on

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depends-on

Spins up external processes your tests need

  • 1.8.3
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

depends-on

Spins up external processes your tests need. Think of it as async.auto with process control for integration tests.

example:

{
  "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

dependencies.json is a file containing a json object mapping dependency names to objects that describe each dependency.

dependency fields

cmd
array of command and args for child_process.spawn (required)
depends
array of names of dependencies which this dependency depends on
cwd
The cwd to pass to child_process.spawn
stdout
path to log dependency's stdout to (default: your stdout)
stderr
path to log dependency's stderr to (default: your stderr)
signal
signal to use to tell the dependency to shut down (default: `SIGTERM`)
wait_for
lets you specify an ip:port and timeout to wait for socket availability before considering a dependency started

wait_for fields

One of port or exit_code is required to use wait_for.

host
default: localhost
port
if port is set, will wait for a TCP connection to be accepted on this port
exit_code
if exit_code is set, will wait for the process to exit with this code before proceeding
timeout
seconds to wait before considering a dependency to have failed starting up (default: 30)

notes

using with tape

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.

why not use a bash script or Makefile?

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

Package last updated on 24 Oct 2014

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