npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ink-testing-library

v4.0.0

Published

Utilities for testing Ink apps

Downloads

323,854

Readme

ink-testing-library test

Utilities for testing Ink apps

Install

$ npm install --save-dev ink-testing-library

Usage

import React from 'react';
import {Text} from 'ink';
import {render} from 'ink-testing-library';

const Counter = ({count}) => <Text>Count: {count}</Text>;

const {lastFrame, rerender} = render(<Counter count={0}/>);
lastFrame() === 'Count: 0'; //=> true

rerender(<Counter count={1}/>);
lastFrame() === 'Count: 1'; //=> true

API

render(tree)

tree

Type: ReactElement

React component to render.

render(<MyApp/>);

This function returns an object, which contains the following methods and properties.

lastFrame()

Type: function

Shortcut to stdout.lastFrame.

frames

Type: array

Shortcut to stdout.frames.

rerender(tree)

Type: function

tree

Type: ReactElement

Rerender root component with different props or replace with another component.

const {rerender} = render(<OldApp/>);
rerender(<NewApp/>);

unmount()

Type: function

Unmount current component.

const {unmount} = render(<Test/>);
unmount();

stdin

Type: object

write()

Type: function

Write data to current component's stdin stream.

import {useInput, Text} from 'ink';

const Test = () => {
	useInput(input => {
		console.log(input);
		//=> 'hello'
	});

	return …;
};

const {stdin} = render(<Test/>);
stdin.write('hello');

stdout

Type: object

lastFrame()

Type: function

Return the last rendered frame (output) from stdout stream.

const Test = () => <Text>Hello</Text>;

const {stdout} = render(<Test/>);
stdout.lastFrame(); //=> 'Hello'
frames

Type: array

Array of all rendered frames, where the last frame is also the last item in that array.

const Counter = ({count}) => <Text>Count: {count}</Text>;

const {stdout, rerender} = render(<Counter count={0}/>);
rerender(<Counter count={1}/>);

console.log(stdout.frames); //=> ['Count: 0', 'Count: 1']

stderr

Type: object

lastFrame()

Type: function

Same as lastFrame in stdout, but for stderr stream.

frames

Type: array

Same as frames in stdout, but for stderr stream.