passpipe

Pipe output to simple handler for testing in .spec files.

Usage no npm install needed!

<script type="module">
  import passpipe from 'https://cdn.skypack.dev/passpipe';
</script>

README

Passpipe

Pipes node Child Process stdout to simple handler which builds chunks using PassThru then callsback on "end". Useful for executing spawn in your testing frameworks then using assertion before continuing tests.

Install

$ npm install passpipe --save

Import

Import or require Passpipe.

TypeScript

import { spawn } from 'child_process';
import * as passpipe from 'passpipe';

Require

const spawn = require('child-process').spawn;
const passpipe = require('passpipe');

Usage

Passpipe accepts method which returns a node ChildProcess, the args you want to pass to the process and a callback to be called on [PassThru] end. You can also pass a command as the method that is known to your system in which case Passpipe will create spawn.

const proc = passpipe.method(spawn, /* spawn args */, (chunk) => {
  // do something with chunk.
});

Example

Example using Mocha/Chai testing frameworks.

const mocha = require('mocha');
const chai = require('chai');
const passpipe = require('../');

const assert = chai.assert;

it('should spawn and output.', (done) => {
  passpipe.command('npm', ['prefix', '-g'], (chunk) => {
    assert.equal(chunk, '/usr/local');
    done();
  });
});

Change

See CHANGE.md

License

See LICENSE.md