passpipe
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i passpipe

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

9.28 kB

Total Files

9

Last publish

Collaborators

  • origin1tech