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

minitsis

v6.0.1

Published

This is a more-or-less faithful clone of David MacIver's [Minithesis](https://github.com/drmaciver/minithesis), a generative testing library. As such, it offers internal shrinking and a test case database.

Downloads

790

Readme

MiniTSis

This is a more-or-less faithful clone of David MacIver's Minithesis, a generative testing library. As such, it offers internal shrinking and a test case database.

Why use this?

This is, charitably, a very small, young project. It has far fewer generators than mature TypeScript projects like fast-check, which was what I was using until I bumped into the problem with fast-check's shrinking: namely, that it can't shrink effectively through monadic bindings. This issue illustrates the core of the problem: once you've used chain (or bind, in Minithesis's terminology), you are pretty much on your own. Because MiniTSis inherits an internal shrinking methodology from Minithesis, you can actually guarantee optimal shrinking (at least given enough time, in small cases):

  test('shrinking regression in fast-check', async () => {
    const testFn = (testCase: TestCase) => {
      const [a, b] = testCase.any(integers(0,100).bind(b =>	tuples(integers(0,b), just(b))))

      // The predicate that will fail if 'a' and 'b' are not close enough
      if (b - a > 5n) {
	    throw new Error(`Predicate failed: b (${b}) - a (${a}) > 5`);
      }
    };

    expect(runTest(100, new Random(), new MapDB(), false)(wrapWithName(testFn)))
      .rejects.toThrow("Predicate failed: b (6) - a (0) > 5")
  });

In practice, better shrinking really does make it much easier to find minimal test cases, which makes development faster and more fun.

The other thing that it implements is a persistent test case database, which means that if you've found a test case breakage once, it will be tried immediately next time you run the test, which can be helpful if you had to do a lot of work to get the breakage. (MiniTSis itself is reasonably quick, even despite heavy use of bigints rather than numbers, but for my use case, individual property checks can easily take seconds.)

Wow, there really aren't many generators, are there

No, there aren't. Unlike Minithesis, though, I'd quite like for this to work for people using TS and JS in production. PRs for more generators gratefully received!

What's this wrapWithName nonsense?

I pull an evil trick to pull some test name information from the Jest runner, and hang it as a property on the side of the passed-in test function. In Minithesis it's done with decorators, but we don't have that in TypeScript, and we actually do need a real, unique name so that the test database can store results.

This does mean that if you change your test names, your failing tests may take a little longer to run until they find the breaks again.

What's left to do?

I made a halfhearted effort at making it run on the client side by abstracting out the test database so that it can be run using localStorage, but the test harness still uses the fs/promises module so I don't expect the test suite to actually run clientside. This is fixable with time and effort.

More generators, as mentioned.

fast-check compatibility shim, if possible.

set up CI on github.