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

testlet

v0.2.0

Published

A simple test framework

Downloads

8

Readme

Testlet - A Simple Test Framework for NodeJS

Testlet is a simple test framework for Node.

Installation

To install - use npm.

npm install -g testlet

Usage

Similar with other frameworks, you organize a test folder within your source tree, with each files denoting specific test case. Then you just call testlet at the root of the source tree.

testlet

In the command line version it will automatically look within the test folder, and then execute them.

Testlet has the following parameters

  • -t|--timeout

    Default 2000 in milliseconds. This specifies how long a test case is to run before timing out.

    The timeout parameter can also be specified with each test case itself.

Test Script Structure

Testlet expects similar test script structure to other test framework such as Mocha.

You can write a test script as follows

// foo.js
describe('this is a test suite', function() {

    it('this is a test case', function() {
        // your assertions go here
    });

    it('this is another test case - an async one', function(done) {
        try {
            // your assertions go here
            done(null);
        } catch (e) {
           done(e);
        }
    });

    it('this test case has a timeout specified', 50000, function(done) {
      // note the second parameter is now a timeout in milliseconds.
      // stuff goes here.
    });
});

describe creates a test suite that can be used to group test cases, and it creates a test case that can be used to run assertions. As long as all assertions pass the test case is successful.

Both describe and it expects a name (string), and a function. The function for describe is used to create the test cases, and the function for it is the test case itself.

The function for it can be either synchronous or asynchronous. If you define a parameter for the function, it will be run as async (i.e. you are expected to call the callback). it can also take an optional timeout parameter to control timeout for this specific test case. Passing 0 for infinite timeout.

describe is an alias for test.add, and it is an alias for test.it.

Assertions

You are free to use any assertion framework. On the other hand, testlet comes with a few built-in assertions for your use.

test.ok(function() { return true; }, <msg>); // test.ok -> assert the function returns true value

test.equal(1, 2, <msg>); // test.equal - assert the two values are equal - it's a deepEqual comparison.

test.throws(function() { throw 1; }, <msg>); // test.throws asserts the function will throw

test.isa(val, type); // test.isa asserts the value is of the type type. type can be a string (uses typeof) or object (uses instanceof).

Logging

console.log is hard to use in combination with test cases because of the asynchronous execution nature. You can instead log to test.log (with the same signature), and the log will be displayed along with the test case result.