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.3

Published

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

Downloads

164

Readme

test-a-bit

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

Features

  • ✅ It's really simple.
  • ✅ Individual test isolation
  • ✅ Test startup and execution time in vacuum
  • ✅ Actual stacktraces
  • ✅ Zero dependencies

Why?

For non-conventional testing, of course.

Installation

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

Writing Tests

Each test file should use execute function to define a single test:

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

// One execute per test file
execute('my test', (success, fail) => {
  // Your test logic here
  if (someCondition) {
    success('test passed!') // Resolves test immediately
  } else {
    fail('test failed!')    // Resolves test immediately
  }
})

// Async example
execute('async test', async (success, fail) => {
  try {
    const result = await someOperation()
    success('all good')  // Resolves test
  } catch (err) {
    fail(err.message)    // Resolves test with failure
  }
})

Running Tests

There are several ways to run your tests:

Direct Node Execution

Run a single test file directly:

node tests/my-test.js

Test Runner

Run multiple test files with specific options:

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

await runner([
  { script: './tests/first.js' },
  { script: './tests/second.js', timeout: 1000 },
  { script: './tests/debug.js', silent: false }, // show console output
])

Auto-Discovery

Automatically find and run all tests in a directory:

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

await auto_runner('./tests/', { timeout: 1000 })

Advanced Features

Output Control

Control console output visibility:

// Global silent mode (default: true)
await runner(tests, { silent: true })

// Per-test silent mode
await runner([
  { script: './test1.js', silent: false }, // show output
  { script: './test2.js' }, // inherit global silent setting
])

Hard Break Mode

Stop execution immediately when a test fails:

await runner([
  { script: './test1.js' },
  { script: './test2.js', hard_break: true }, // break if this fails
  { script: './test3.js' }, // won't run if test2 fails
], { hard_break: false }) // global setting

Timeout Control

await runner([
  { script: './quick.js', timeout: 100 },
  { script: './slow.js', timeout: 5000 },
  { script: './infinite.js', timeout: -1 }, // no timeout
])

API Reference

execute(name, testFn, [precision])

Defines a single test. Use one per test file.

  • name: Test name (string)
  • testFn: Test function (success, fail) => void
    • success(message): Call to pass the test (resolves immediately)
    • fail(message): Call to fail the test (resolves immediately)
  • precision: Time measurement precision ('milli', 'micro', 'nano')

runner(tests, options)

Runs multiple test files in sequence.

  • tests: Array of test configurations
    • script: Path to test file
    • timeout: Test timeout in ms (-1 for no timeout)
    • silent: Control test's console output
    • hard_break: Stop execution on test failure
  • options:
    • timeout: Default timeout (default: 5000ms)
    • silent: Control console output (default: true)
    • hard_break: Stop on first failure (default: false)
    • log: Show summary after completion

auto_runner(directory, options)

Automatically discovers and runs tests in a directory.

  • directory: Path to test directory
  • options: Same as runner options

License

MIT License - feel free to use this project commercially.


With love ❤️ from Ukraine 🇺🇦