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

@jpcx/testts

v0.4.0

Published

an asynchronous, nesting, composable testing framework for TypeScript [zero-dependency]

Downloads

13

Readme

testts 0.4.0


About

testts is an asynchronous, nesting, composable testing framework for TypeScript.

  • Intended to be minimal, testts will always be dependency-free
  • Tests execute code and are witten to either expect no throw or to describe an expected throw
  • Use alongside an assertion library

Composition

testts facilitates composition within the type system:

  • tests are registered and executed asynchronously
  • they may be nested indefinitely
  • and they return typed promises that resolve to the test body return value

API

There are two test registrars, test(descr, body) and test.throws(...?)?(descr, body)

  • any test statement, if executed, will be outputted to the console
  • promises returned from test registration will resolve or reject when the test passes or fails

Settings

From anywhere in the test files:

  • test.deleteStacks(setting=true, passToChildren=true): void
    • Deletes stack traces from Error instances thrown during failures.
    • If output is congested with errors, this will improve readability.
    • deleteStacks applies to the test parent and all of its children (unless passToChildren is false).

Using the configuration file $PWD/.testts.json:

{
  prioritized: string[]
}
  • prioritized
    • Allows for specifying certain test paths for independent, ordered execution.
    • If some of your tests require timing and you don't want the event loop populated during execution, be sure to list them here.
    • Prioritized tests happen first, and are each completed before the next execution.
      • (By default, tests execute all of their children and then wait for each one afterwards).

Notes

In order to achieve nesting, test parents must provide a test parameter.

  • If a test parameter is not written, test statements will create siblings instead.

Although promises returned by test statements can reject, a process listener is used to catch unhandled promises.

  • test statements do not require .catch blocks
  • If an unhandled rejection belongs to a test it is passed on to the report.
  • Any other unhandled rejections cause a non-zero exit.

See the usage examples for more info

Requirements

Node.js >=10.0.0

Examples

npm i --save-dev @jpcx/testts
npx @jpcx/testts dist/ # recursively runs tests from any nested *.test.js files

# any number of files/folers may be used as arguments
# manually specified files do not need to conform to the *.test.js requirement
# npx @jpcx/testts dist/my.compiled.test.js dist/my.other.compiled_test.js dist/other/

# there is only one setting available: `npx @jpcx/testts -m(--match) [ECMAScript regex]`
# the default match regex is "\\.test\\.js"
import { test } from "@jpcx/testts";
import * as assert from "assert";

import { getSampleDB } from "../";

test("simple test", () => {
  assert(true);
  // assert(false); // fails test
});

// all tests return promises (their execution is deferred). In the absence of an
// await statement, tests below will be registered even if the above test fails

test("asynchronous test", async () => {
  await new Promise((resolve) => setTimeout(resolve, 100));
  assert(true);
});

// use a parameter to allow `test` to refer to a parent context
test("nested tests", (test) => {
  test("failure fails parent", () => {
    assert(true);
  });
});

test("dependent testing", async (test) => {
  // tests return promises!!
  const waitforme = await test("nested tested value", () => "yay");

  // TS `typeof waitforme`: 'string'
  test("dependent test", () => assert(waitforme === "yay"));
});

test.throws("unspecified throw expected", () => {
  throw new Error();
});
test.throws("bad")("error message specified", () => {
  throw new Error("bad");
});
test.throws(TypeError)("error constructor specified", () => {
  throw new TypeError();
});
test.throws(TypeError, "bad")(
  "error constructor and messsage specified",
  () => {
    throw new TypeError("bad");
  }
);
test.throws((e: number) => e === 42)("predicate-based specification", () => {
  throw 42;
});

Contributing

Contribution is welcome! Please make a pull request.

License

Copyright (C) 2021 Justin Collier <[email protected]>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the internalied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.