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

test-a-bit

v1.1.1

Published

Super simple NodeJS test tools for free-style testing and benchmarking at home.

Downloads

5

Readme

test-a-bit

Zero-dependency light weight testing & benchmarking tool for node-js.

BEWARE!!!

This package is not ready for production, but still can be fun to use.

Installation

npm i test-a-bit --save-dev

runner

Call runner(<test_scripts>, <options>)

Each test script running in a separate process. You can specify the timeout for each script.

/* run_test.js */

import { runner } from 'test-a-bit'

runner([
      { script: './tests/success.js' },
      { script: './tests/fail.js' },
      { script: './tests/timeout.js', timeout: 200 },
      { script: './tests/random.js', timeout: 200, silent: false },
    ],
    {
      silent: false, // log or not process output by default
      timeout: 1000, // default timeout 
    }
).then(results => console.log(results, 'bye'))

<tests_list>

List of objects with script and timeout.

[silent=false]

Set to true to suppress console output from console.log inside the tests.

results

Runner returns Promise with results map like this:

{
  '12ebd1-9daf62-594cd5': {
    uid: '12ebd1-9daf62-594cd5',
    name: 'sample fail test',
    note: 'oh, no!',
    timeout: 200,
    script: './tests/random.js',
    silent: false,
    result: 'fail',
    delta: 0.09140002727508545,
    delta_precision: 'milli',
    delta_precision_sym: 'ms',
    exit_code: 1
  }
}

If you are lazy enough - just use auto_runner to automatically run all scripts in the specific folder.

auto_runner('./tests/').then(results => console.log('bye'))

Actual Test

Each test is a separated file that calls the execute method once with the test function. To indicate test result - run the success or fail function.

/* tests/random-test.js */

import { execute } from 'test-a-bit'

execute('sample fail test', (success, fail, is_runner) => {
  const rnd = Math.random()

  if (!is_runner) console.log(`oh wow! rolled: rnd`)

  success > 0.5
      ? success('got lucky!')
      : fail('oh, no!')
})

Possible output:

[fail]     sample fail test >> oh, no! / Δ=0.07ms

execute(<name>, <callback>)

<name> - Is a string - will be passed to the output.

<callback> - Callback Function with your test inside.

Callback Arguments

Callback function has 3 arguments: result functions success & fail, and is_runner flag.

fail([note]) & success([note])

Call this to mark test passed or failed respectively.

note - string, will be passed to the output.

is_runner

Is this test was runner by a runner (along with other tests). Might be handy to decide if you need to spam the console.

That's it. Have a fun! :3