
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@inquirer/testing
Advanced tools
@inquirer/testing
The @inquirer/testing
package is Inquirer's answer to testing prompts built with @inquirer/core
.
npm | yarn |
---|---|
|
|
Here's an example of a test running with Jest (though @inquirer/testing
will work with any runners).
import { render } from '@inquirer/testing';
import input from './src/index.mjs';
describe('input prompt', () => {
it('handle simple use case', async () => {
const { answer, events, getScreen } = await render(input, {
message: 'What is your name',
});
expect(getScreen()).toMatchInlineSnapshot(`"? What is your name"`);
events.type('J');
expect(getScreen()).toMatchInlineSnapshot(`"? What is your name J"`);
events.type('ohn');
events.keypress('enter');
// or events.keypress({ name: 'enter' })
await expect(answer).resolves.toEqual('John');
expect(getScreen()).toMatchInlineSnapshot(`"? What is your name John"`);
});
});
The core utility of @inquirer/testing
is the render()
function. This render
function will create and instrument a command line like interface.
render
takes 2 arguments:
createPrompt()
)render
then returns a promise that will resolve once the prompt is rendered and the test environment up and running. This promise returns the utilities we'll use to interact with our tests:
answer
(Promise
) This is the promise that'll be resolved once an answer is provided and valid.getScreen
(({ raw: boolean }) => string
) This function returns the state of what is printed on the command line screen at any given time. You can use its return value to validate your prompt is properly rendered. By default this function will strip the ANSI codes (used for colors.)events
({ keypress: (name | Key) => void, type: (string) => void }
) Is the utilities allowing you to interact with the prompt. Use it to trigger keypress events, or typing any input.getFullOutput
(() => string
) Return a raw dump of everything that got sent on the output stream.You can refer to the @inquirer/input
prompt test suite as a practical example.
Copyright (c) 2023 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.
FAQs
Inquirer testing utilities
The npm package @inquirer/testing receives a total of 7,381 weekly downloads. As such, @inquirer/testing popularity was classified as popular.
We found that @inquirer/testing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.