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

enough-test

v1.0.1

Published

Really small JavaScript class for formatting test output

Downloads

2

Readme

enough-test

There are others out there who figured out that you don't really need a lot of code to run the tests and print a report of what worked. Same here.

Of course, it does not go into the coverage report. But, not all modules really need that.

This is 100 lines of program (some lines are empty).

This is enough for lots of stuff.

install

npm install --save-dev enough-test

purpose

Format some tests for some modules without adding something encyclopedic.

The following example is a gist that fits.

Example - a test of the test

Instead of assert, notice the line

passes &&= (t1 !== null)

That checks that the test report object actually got constructed, which is highly likely. But, it could be something else:

passes &&= (predicate should be true after running some method)

Then, you can say the test past if passes is true.

if ( passes ) t1.pass()

That is passes starts out true, while t1.status starts out false. t1.pass() set t1.status to true. Then, the reporting method test_report check the status of each Report that it put into an array.

Here is an example, which is also run by the following command:

npm test

The code:


const {Report,reset_tests,test_report,title,verbosity,kill} = require('../report')


async function run_tests_0() {
    // this is a test
    reset_tests()
    title("running tests 1 for enough-tests...report.js ")

    let passes = true
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    let t1 = new Report("constructed","Report object gets construced")
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    verbosity("it got constructed")
    passes &&= (t1 !== null)
    //
    if ( passes ) t1.pass()

    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    let t2 = new Report("title","prints another title")
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    title("another title")
    if ( passes ) t2.pass()
    //
    test_report()
}

async function run_tests_1() {
    // this is a test
    reset_tests()
    title("running tests 2 for enough-tests...report.js ")

    let passes = true
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    let t1 = new Report("constructed","Report object gets construced")
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    verbosity("it reset the test list and now adding more reports")
    //
    if ( passes ) t1.pass()

    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    let t2 = new Report("test_report","last time we see a report")
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    verbosity("this is verbose --- formatted log")
    verbosity("next we'll kill the process as if something bad was about to happen")
    if ( passes ) t2.pass()
    //
    test_report()
}

async function run_tests_2() {
    // this is a test
    reset_tests()
    title("running tests 3 for enough-tests...report.js ")

    let passes = true
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    let t1 = new Report("kill","You should not see this")
    // ---- ---- ---- ---- ---- ---- ---- ---- ---- ----    
    verbosity("killing")
    kill("this is going to stop everything")
    //
    if ( passes ) t1.pass()
    //
    test_report()
}



async function run_tests() {
    await run_tests_0()
    await run_tests_1()
    await run_tests_2()
}


run_tests()     // this line has to be there

Real world use

So, I used it just yesterday. And, I did have to do the tests. The nice format gives me the feel that I am using one of those larger than life testing stacks. But, of course, I just had to exercise the code, raise a few questions and make a few changes.

Contributing

Do you want to have more things for this to do? Make pull requests, etc.