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

@closeio/test-console

v0.1.2

Published

Library for handling console logs in tests in a flexible way

Downloads

3,389

Readme

test-console

A flexible framework for managing console messages in your tests.

When to Use This?

Test output can get clutterd with logs and warnings for many reasons:

  • You upgraded a library and it started showing warnings where it didn't before. There are many of these and you don't have time to resolve them all right now
  • You started using a new testing library and it's showing you output or warnings about many things all at once
  • A warning started showing and you just didn't notice at the time, but now you do

Whatever the reason, if you find that there's a lot of noise in the output of your tests and you'd like to manage that, this library is for you!

Approach

Our approach is to give you a succinct way to identify output in your tests and deal with them in a systematic manner.

For instance, at Close we set the test output in our CI system to only show CRITICAL items. That way we have only the most important information in the output from our CI system, and if a test fails it's very easy to see why. While testing in watch mode in our development environment shows everything.

When we want to eliminate a particular warning from our test system, we set that matcher to be CRITICAL and run our tests with an CRITICAL threshold so we only see the items we need to fix. This helps us focus on the task at hand and see clearly when we've reached our goal.

Install

yarn add -D @closeio/test-console
npm i --save-dev @closeio/test-console

Usage

In a file that you load before running your tests, you can do something like this:

import { patchConsoleMethods } from '@closeio/test-console';

// Make the threshold customizable from the command line
const threshold = process.env.TEST_CONSOLE_LEVEL || 'ERROR';

patchConsoleMethods(
  ['debug', 'info', 'log', 'warn', 'error'], // the console methods to patch
  // A list of tests to compare against logged messages, and their associated
  // log level if matched.
  [
    { matcher: /warning: failed prop type:/i, level: 'WARNING' },
    {
      matcher: 'Each child in a list should have a unique "key" prop',
      level: 'ERROR',
    },
    {
      matcher: /warning: an update to .* inside a test was not wrapped in act/i,
      level: 'CRITICAL',
    },
  ],
  {
    // filenameRegex determines what lines from the stack trace will show when
    // logging out the test location.
    filenameRegex: /\.test\.[jt]sx?/,
    // If given, getTestName will be called when logging out test location, to
    // help you track down where logs are coming from.
    getTestName: () => expect.getState().currentTestName,
    // Log messages whose level is >= the threshold will be shown, along with
    // log messages that didn't match one of the log tests.
    threshold,
  },
);

And then you can run your tests with the level you want like:

TEST_CONSOLE_LEVEL=INFO yarn test