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

@johanmnto/testings

v1.1.0

Published

A testing package I personnally use in all of my projects.

Downloads

12

Readme

@johanmnto/testings

Get Started

Performing single-tests

There is two ways to perform tests, the first one is by using UnitTest. Using UnitTest allows you to perform one unique test. To do so, you need to provide 3 informations to this function. The first one is the name of your unit-test, the second one is the script to test and the third one is the expected result. Let see an example:

import { Testings } from "@johanmnto/testings";
Testings.Testers.UnitTest("Some-Test", () => 2 * 9, 18);

The expected result is:

Some-Test: 0.074ms  → result: 👌 Passed

Peforming multiple-tests

The second way to perform tests is by using GroupTest. This function allows you to run multiple tests at once, it can be used when you want to make a test configuration. If you use Typescript, you can use UnitParameters<ExpectedReturnType>[] to define your test units. Let see an example:

import { Testings } from "@johanmnto/testings";
import { UnitParameters } from "@johanmnto/testings/dist/testers.d.ts";
const units: UnitParameters<any>[] = [
  {
    name: "Some-Test-Expect-18",
    runner: () => 2 * 9,
    expect: 18
  },
  {
    name: "Some-Test-Expect-9",
    runner: () => 3 * 3,
    expect: 9
  }
];

Testings.Testers.GroupTest(units);

Advanced usage

Filtering tests in GroupTest

GroupTest features a functionnality that defines which test units to run. To do so, you just need to put an array with the name of the tests you want to run on the second parameter of GroupTest. Assuming that we take the test unit configuration of GetStarted.PerformingMultipleTests, it means that if we want to run only the second test unit, the last line would look like:

// all the code set before
Testings.Testers.GroupTest(units, ["Some-Test-Expect-9"]);

Outputting synchronous/asynchronous data with LogGroup

LogGroup is a tool used in this package to output a lot of data in the console. It's used to output those data and manages their asynchronousity, etc... To use LogGroup you just need to create a LogGroup instance and add synchronous data with add, asynchronous data with scope and show them in the console using show. There is an example:

import { Testings } from "@johanmnto/testings";

const logInstance = new Testings.Loggers.LogGroup("nameOfYourLogGroup");
logInstance.add("nameOfTheDataToAdd", 12).add("anotherNameForAnotherData", {a: true});
// there is no need for any async/await expression or Promise structure, `LogGroup` automatically
// handle them.
logInstance.scope("somePromise", fetch("https://www.johanmontorfano.com"))
// it is not important if the promise is not fulfilled, the `show` function will always wait for 
// every promise to be finished before performing any actions.
          .show();