
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
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.
Terminal Text Parsing Support Checklist Refer to Full List of Ansi Escape Codes that need to be handled.
With NPM:
npm install --save-dev cli-testing-library
With Yarn:
yarn add --dev cli-testing-library
Check out Interactive Examples on Stackblitz
// hello-world.test.js
const { createCommandInterface } = require('cli-testing-library');
test('should print greetings', async () => {
const commandInterface = createCommandInterface('node ./hello-world.js', {
cwd: __dirname, // Directory from where you want to run the command
});
await commandInterface.type('Saurabh\n');
const terminal = await commandInterface.getOutput();
expect(terminal.stringOutput).toBe("What's your name?Hi, Saurabh!");
});
The code that we're testing-
// hello-world.js
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
readline.question(`What's your name?`, (name) => {
console.log(`Hi, ${name}!`);
readline.close();
});
Check out this example of StackBlitz
Sometimes you may want to test if the output has correct color and graphics. You can use the .tokenizedOutput
method to get tokens in the output.
Check out list of tokens that library outputs.
// colored-output.test.js
const { createCommandInterface } = require('cli-testing-library');
test('should have bold red text', async () => {
const commandInterface = createCommandInterface('node ./colored-output.js', {
cwd: __dirname,
});
const terminal = await commandInterface.getOutput();
expect(terminal.tokenizedOutput).toBe("This has a [BOLD_START][RED_START]red and bold[COLOR_END][BOLD_END] text.");
});
Big Shoutout to
FAQs
Simple and complete CLI testing utilities that encourage good testing practices.
The npm package cli-testing-library receives a total of 2,665 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.
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.