Futuristic test features from AVA integrated with JSVerify test-case generation.
- 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.
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.
npm install --save-dev ava-verify
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
.