Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
A basic implementation of Readable and Writable streams to mock
process.stdout
, process.stderr
, process.stdin
, or any readable and
writable streams.
npm install --save stdio-mock
This project is proudly written in TypeScript so you can enjoy using beautiful typings! :smile:
for standard i/o
import { stdio } from 'stdio-mock';
const { stdout, stdin } = stdio();
stdin.pipe(stdout);
stdout.on('data', data => {
// do stuff
})
stdin.write('test data');
stdin.end();
for more general purpose use cases
import { MockReadable, MockWriteable } from 'stdio-mock';
const stdin = new MockReadable();
const stdout = new MockWriteable();
stdio(): StdIO
This is the main function exposed by the library as a convenience to mock your standard input and output streams.
type StdIO = {
stdin: MockReadable,
stdout: MockWriteable,
stderr: MockWriteable,
}
import { stdio } from 'stdio-mock';
const { stdout, stdin } = stdio();
stdin.pipe(stdout);
stdout.on('data', data => {
// do stuff
})
stdin.write('test data');
stdin.end();
MockReadable :: stream.Readable
This is an implementation of Node.js' stream.Readable
with additional methods
for use in testing.
MockReadable.write(...data: Array): MockWriteable
Pushes data into the Readable stream. This will throw and error if the stream has ended.
import { MockReadable } from 'stdio-mock';
const readable = new MockReadable();
readable.on('data', (data: string) => {
assert.stictEqual(data, 'test');
});
readable.write('test');
MockReadable.data(): Array
Returns an array containing all data that has been passed into the stream.
import { MockReadable } from 'stdio-mock';
const readable = new MockReadable();
readable.write('test');
const data = readable.data();
assert.strictEqual(data[0], 'test');
MockReadable.end(): void
Ends the stream asynchronously.
import { MockReadable } from 'stdio-mock';
const readable = new MockReadable();
readable.write('test');
readable.end();
This is an implementation of Node.js' stream.Writable
with an additional method
to query all the data that has been pushed to it.
MockWriteable.data(): Array
Returns an array containing all data that has been passed into the stream.
import { MockWritable } from 'stdio-mock';
const writable = new MockWritable();
writable.write('test');
const data = writable.data();
assert.strictEqual(data[0], 'test');
FAQs
Mock Command Line Applications
The npm package stdio-mock receives a total of 809 weekly downloads. As such, stdio-mock popularity was classified as not popular.
We found that stdio-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.