
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
cli-testing-library
Advanced tools
A testing library that allows you to test input and outputs of your CLI command.
A testing library that allows you to test input and outputs of your CLI command.
Note: This is a work in progress. The API is likely going to change.
npm install --save cli-testing-library # yarn add cli-testing-library
Test file
// experiment.test.js
const { createCommandInterface } = require('cli-testing-library');
test('should print appropriate greetings', async () => {
const commandInterface = createCommandInterface('node ./experiment.js', {
cwd: __dirname
});
await commandInterface.type('Saurabh\n');
await commandInterface.type('22\n');
const terminal = await commandInterface.getOutput();
expect(terminal.textAfter("What's your name?")).toBe('Hi, Saurabh!');
expect(terminal.textAfter("What's your age?")).toBe('So you are 22!');
});
Code that is being tested A node program that asks user for their name and age, and then prints a greeting.
// experiment.js
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question(`What's your name?`, (name) => {
console.log(`Hi, ${name}!`);
readline.question(`What's your age?`, (age) => {
console.log(`So you are ${age}!`);
readline.close();
});
});
FAQs
Simple and complete CLI testing utilities that encourage good testing practices.
The npm package cli-testing-library receives a total of 2,227 weekly downloads. As such, cli-testing-library popularity was classified as popular.
We found that cli-testing-library demonstrated a healthy version release cadence and project activity because the last version was released less than 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
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.