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

ava-verify

v0.0.1

Published

JSVerify plugin for AVA

Downloads

9

Readme

JSVerify Plugin for AVA

Futuristic test features from AVA integrated with JSVerify test-case generation.

npm Build Status Codecov

Features

  • Runs generated test-cases in parallel
  • Shrinking failing test cases to produce small counter-examples (#1)
  • Full JSVerify output, including seed, counter-examples, etc. (#12)
  • Each test case can be given a unique name based on the generated values (#2)

Many more features are planned. See the issue tracker for the current list.

Background

It's possible to run JSVerify tests inside AVA:

const test = require("ava");
const jsc  = require("jsverify");

test("addition", t => {
  t.plan(0);
  jsc.assert(jsc.forall(jsc.int, jsc.int, jsc.int, (a, b, c) => {
    return a + b === c;
  }));
});

However, this ignores most of AVA's advantages: JSVerify will run the forall body an unknown number of times, so we can't use test planning and JSVerify's assertion library.

Instead, ava-verify creates an environment that takes advantage of AVA's power.

// Require `ava` yourself if you have tests that don't use `ava-verify`, but `ava-verify` will require `ava` itself.
// const test = require("ava");
const jsc = require("jsverify");
jsc.ava = require("ava-verify");

jsc.ava({
  suite: "addition",
  title: (suite, a, b, c) => `${suite}: ${a}+${b}=${c}`;
  runs: 50,
  passing: "hide",
  subseqFail: "skip",
}, [ jsc.int, jsc.int, jsc.int ], (t, a, b, c) => {
  t.plan(2);
  t.is(typeof a, "number");
  t.is(a + b, c);
});

Given the options, a list of arbitraries to generate, and a test body, ava-verify will create individual AVA tests for each test instance specified (by the runs option).

As each test instance is in it's own AVA test, you can use AVA's test planning and power-assert interface to produce descriptive assertion messages.

When each test instance fails, the generated variables will be shrunk and retried to produce smaller counter-examples according to the JSVerify shrink system. The internal AVA variables will be reset, so test planning and previous failures won't affect the retried test.

Optionally, subsequent test failures can be canceled and hidden, reducing the amount of output.

In addition, successful test cases can be hidden, so the number of successful tests is 1 per test suite, instead of 1 for each test case in a test suite.

Installation

npm install --save-dev ava-verify

Usage

Require ava-verify in your tests:

const jsc = require("jsverify");
jsc.ava = require("ava-verify");

(You can replace jsc.ava with any variable)

jsc.ava is a function that allows you to call the AVAVerify class without using new. Any arguments passed to the exported function will be handed to the AVAVerify class.

You can directly access the class through require("ava-verify/AVAVerify"), or require("ava-verify").AVAVerify.