npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tape-spawn

v1.4.2

Published

spawn processes conveniently in tape tests and match against stdout/stderr streaming output

Downloads

3,629

Readme

tape-spawn

spawn processes conveniently in tape tests and match against stdout/stderr streaming output

NPM

Build Status

js-standard-style

installation

npm install tape-spawn

usage

use this in conjunction with tape, e.g.

var test = require('tape')
var spawn = require('tape-spawn')

test('spawn ls', function (t) {
  var st = spawn(t, 'ls ' + __dirname)
  st.stdout.match(/example.js/)
  st.end()
})

debugging

If you set DEBUG=tape-spawn in your ENV when running your tests then the STDERR of the spawned child process will be piped into the STDERR of your terminal.

api

var spawn = require('tape-spawn')

returns a function, spawn, that can be used to spawn new processes and test their output with tape

processes are spawned with npm-execspawn, meaning local node_modules bins will be matched first before looking in your PATH

var spawnTest = spawn(tapeTest, commandString, [options])

returns spawnTest, which can be used to set up assertions. also spawns a process using commandString. options are optional, and can have the following properties:

  • end (default true) - if false no t.end() assertion will be set up for the test, which means you will have to use spawnTest.end(onEnd) to handle it yourself

in addition, the entire options object will get passed as the second argument to spawn, so you can do e.g. {env: {FOO: 'bar'}} to pass env vars to pass custom spawn options (see the child_process node docs for more info)

spawnTest.fails([message])

sets up a tape assertion that expects a non-zero exit code – with an optional message

spawnTest.succeeds([message])

sets up a tape assertion that expects exit code to equal 0 – with an optional message

spawnTest.exitCode(code, [message])

code must be a number. sets up a tape assertion that expects exit code to equal code – with an optional message

spawnTest.timeout(time, [message])

waits for time milliseconds and then kills the spawned process and fails the test with the optional message string assert message. if message is a function it will be called after the timeout, and no fail assert will be created

spawnTest.end([onDone])

sets up a tape assertion for t.end(). if you pass the optional onDone callback, no t.end() assertion will be created, and your onDone callback will be called when the test is done

spawnTest.kill()

kills the spawned process

spawnTest.stdin

this property is the internally spawned process stdin stream instance

spawnTest.stdout.match(pattern, [message, failMessage])

matches stdout output (assumes utf8 encoding). if pattern is a RegExp it will set up a tape assertion that uses use pattern.test(output). if pattern is a string it will use t.equals() to match the entire output against message. if pattern is a function it should return true/false and take 1 argument, the full output of the spawn

You can pass the optional message or failMessage to customize the tape assertion messages

spawnTest.stdout.empty()

takes no args. sets up a tape assertion that expects output to match /^$/ (e.g. to be empty)

spawnTest.stderr.match(pattern, [message, failMessage])

the same as spawnTest.stdout.match but matches stderr instead

spawnTest.stderr.empty()

the same as spawnTest.stdout.empty but matches stderr instead