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

@tim-code/autotest

v1.0.2

Published

``` npm install @tim-code/autotest ```

Downloads

45

Readme

autotest

npm install @tim-code/autotest

A zero-dependency helper function to reduce boilerplate in writing Jest tests

Philosophy

import { autotest, factory } from "@tim-code/autotest"

autotest(functionToTest, options)(input1, input2, ...)(expected)

factory(options)(functionToTest)(input1, input2, ...)(expected)

Note expected itself can be a (async) callback. If so, autotest will pass the test output to it instead of using expect(output).toEqual(expected).

Similar Jest code for comparison:

test("functionToTest(...)", () => {
  expect(functionToTest(input1, input2, ...)).toEqual(expected)
})

Options

name: Name the test. Otherwise, try to make one from the test function's name and passed in input.

callbackName: If name is not specified, used instead of functionToTest.name to name the test.

error: Specify that an error is expected.

only: Use test.only to make only one test run, which is useful for debugging.

timeout: Specifies the max execution time for the test and is useful for debugging

setup: (async) callback that is always invoked with no arguments before the test is run; its return value has no effect

teardown: (async) callback that is always invoked with no arguments after all callbacks are run (or error); its return value has no effect

after: a (async) callback that is invoked with the test function output; its return value will be tested with/using expected

before:

This is a (async) callback that is invoked with the input before the test is run (but after setup). Its return value must be iterable and will be passed to the test callback via the spread operator. This can be useful for generating input to a test. For example:

const autotest = factory({ before: (add, multiple) => [add + Math.random() * multiple] })
autotest(handleOneToSix)(1, 5)(expected)
autotest(handleOneToEleven)(1, 10)(expected)

consume:

This is a (async) callback that is invoked with the test function and the input, which is useful for testing higher order functions.

const add = (x) => (y) => x + y
const autotest = factory({ consume: (func, [x, y]) => func(x)(y) })
const test = autotest(add)
test(1, 2)(3) // test name will be add(1,2), not add(1)(2)

For convenience, the above consume function is exported as consume2 with consume3 and consume4 analogs.

There is also consume2Iterables, consume3Iterables, and consume4Iterables exported which spread their input:

const add = (x) => (y) => (z) => x + y + z
const autotest = factory({ consume: consume3Iterables })
const test = autotest(add)
test([1], [2], [3])(6) // test name will be add([1],[2],[3]), not add([1])([2])([3])