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

@basd/testr

v0.1.6

Published

A lightweight, flexible and based testing library for JS

Downloads

39

Readme

Testr

gitr done, testr first

npm pipeline license downloads

Gitlab Github Twitter Discord

Testr is a flexible, lightweight and based testing library for JS. It's designed to work seamlessly in both browser and Node.js environments. It supports a variety of features such as nesting, asynchronous execution, and exclusion/inclusion of test cases to streamline your testing workflow.

Installation

To install Testr, use npm:

npm i -D @basd/testr

Usage

Basic Usage

Here is a simple example of using Testr:

const Testr = require('@basd/testr')

const testr = new Testr()

testr.describe('A test suite', () => {
  testr.it('A test case', () => {
    if (1 + 1 !== 2) {
      throw new Error('Math is broken!')
    }
    expect(2 + 2).to.equal(4)
  })
})

testr.run()

Or you can instantiate and destructure the functions you need:

const { describe, it, before, after, expect, assert, run, testr } = new Testr()
// or as a function
const { describe, it, before, after, expect, assert, run, testr } = Testr()
// which means you can do this:
const { describe, it, before, after, expect, assert, run, testr } = require('@basd/testr')()

In this example, we create a test suite with describe(), add a test case with it(), and run our tests with run().

Skipping and Only Running Certain Tests

You can also mark test cases or suites to be skipped with describe.omit() and it.omit(), or to be the only ones run with describe.only() and it.only().

describe.omit('A skipped test suite', () => {
  it('A skipped test case', () => {})
})

describe.only('A test suite to run alone', () => {
  it.only('A test case to run alone', () => {})
})

Before and After Hooks

You can use before.each(), after.each(), before.all(), and after.all() to set up and tear down for tests:

describe('A test suite', () => {
  let counter = 0
  
  before.each(() => {
    counter = 1
  })
  
  it('A test case', () => {
    if (counter !== 1) {
      throw new Error('Counter not initialized!')
    }
  })
  
  after.each(() => {
    counter = 0
  })
})

Node.js Environment

For Node.js environments, TestrNode provides additional functionality:

const TestrNode = require('@basd/testr')

TestrNode.explode('path/to/tests', ['path/to/tests/to/ignore'])

In this example, TestrNode will automatically find and require test files in the specified directory that end with .test.js, and ignore the ones in the directories to ignore.

CLI Usage

If you have installed Testr globally or in your project, you can use the testr command to run your tests from the command line:

# Run all test files in a directory
testr path/to/tests

# Run all test files, except those in certain directories (coming soon..)
testr path/to/tests --ignore path/to/tests/to/ignore

This will automatically find and run any files ending with .test.js.

Contributing

Contributions are welcome! Please open an issue if you encounter any problems, or a pull request if you make a change.

Donations

If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!

Bitcoin (BTC):

1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF

Monero (XMR):

46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ

License

@basd/testr is MIT licensed.