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

betest

v3.2.1

Published

Tiny framework for testing your js code

Downloads

48

Readme

Betest

Betest is a small and simple way to write and run JavaScript tests with zero dependencies!

Table of content

Installation

npm install betest --save-dev

For beta see Github

npm install betest@beta --save-dev

Usage

Assuming that you have folder "tests" and file "index.js" inside.

node ./tests/index.js

or add this to your package.json

  "scripts": {
    "test": "node ./tests/index.js"
  },

Example

Create an instance of Betest:

import {Betest} from 'betest';

const betest = new Betest();

You can choose how results will be look in console using parameters object:

betestParams = {
    results: {
        showAs: "Table" // or "Line"(Colorful PASS/FAIL)
    }
}
const betest = new Betest(betestParams);

Add your named group and functions using method "addGroup":


betest.addGroup(
    { 
        name: "Example Group", 
        tests: [
            {   
                expected: {
                    fisrstName: "First Name",
                    secondName: "Second Name"
                },
                test: function checkObject() {
                    return {
                    fisrstName: "First Name",
                    secondName: "Second Name"
                    }
                }
            },
            {   
                expected: 7,
                test: function findHypotenuse() {
                    return Math.round(Math.sqrt(5 ** 2 + 5 ** 2));
                }
            },
            {   
                expected: [
                    [6, -8, 1],
                    [4, 1, 0],
                    [2, 3, 5]
                ],
                test: function checkArrayEquality() {
                    return [
                        [6, -8, 1],
                        [4, 1, 0],
                        [2, 3, 5]
                    ]
                }
            }
        ]
    }
);

You can run all tests in all groups, either one group or only one test in the group:

  1. Run all tests in all groups
betest.runAll();
  1. Run only one group's tests
betest.runGroup("Example Group");
  1. Run only one test in the group
betest.runTest("Example Group", "findHypotenuse");

Or you can run test on the fly

betest.go(
    [ // groups
        { // one group
            tests: {
                expected: 1,
                test: function findSinus() {
                    return Math.sin(90 * 180 / Math.PI);
                }
            }
        }
    ]
);

And see results:

|(index)| (name) | Values | |-------| -------------------| -----------| | 0 | multiplication | true | | 1 | sum | true |

Constructor Params

const betestParams = {
    results: {
        // 1. "Table" for table result.
        // 2. "Line" for colorful PASS/FAIL message
        showAs: string
    }
}