🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mock-stdin

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-stdin

Mock STDIN file descriptor in Node.js

1.0.0
latest
Source
npm
Version published
Weekly downloads
214K
-3.74%
Maintainers
1
Weekly downloads
 
Created

What is mock-stdin?

The mock-stdin npm package is used to mock the standard input (stdin) stream in Node.js applications. This is particularly useful for testing command-line applications where user input is required.

What are mock-stdin's main functionalities?

Mocking stdin input

This feature allows you to simulate user input by sending data to the stdin stream. The example demonstrates how to send 'input data' to stdin and then end the input stream.

const mockStdin = require('mock-stdin').stdin();

// Start mocking stdin
mockStdin.send('input data\n');
mockStdin.end();

// Your application code that reads from stdin
process.stdin.on('data', (data) => {
  console.log(`Received: ${data}`);
});

Pausing and resuming stdin

This feature allows you to pause and resume the stdin stream. The example shows how to send 'input data' to stdin, pause the stream, and then resume it.

const mockStdin = require('mock-stdin').stdin();

// Start mocking stdin
mockStdin.send('input data\n');
mockStdin.pause();

// Your application code that reads from stdin
process.stdin.on('data', (data) => {
  console.log(`Received: ${data}`);
});

// Resume stdin
mockStdin.resume();

Flushing stdin

This feature allows you to flush the stdin stream, ensuring that all data sent to stdin is processed immediately. The example demonstrates how to send 'input data' to stdin and then flush the stream.

const mockStdin = require('mock-stdin').stdin();

// Start mocking stdin
mockStdin.send('input data\n');
mockStdin.flush();

// Your application code that reads from stdin
process.stdin.on('data', (data) => {
  console.log(`Received: ${data}`);
});

Other packages similar to mock-stdin

Keywords

test

FAQs

Package last updated on 14 Nov 2019

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