Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-check

Package Overview
Dependencies
Maintainers
1
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-check - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

lib/check/polyfills.d.ts

12

CHANGELOG.md

@@ -0,1 +1,13 @@

# 1.3.0
_Filter invalid values directly in predicates using `fc.pre`_
## Features
- ([PR#140](/pull/140)) Make seed and path copy pasteable
- ([PR#138](/pull/138)) Remove core-js, no more global namespace pollution
- ([PR#118](/pull/118)) Enable preconditions in predicate
---
# 1.2.3

@@ -2,0 +14,0 @@

0

lib/check/arbitrary/ArrayArbitrary.d.ts

@@ -0,0 +0,0 @@ import Random from '../../random/generator/Random';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Random from '../../../random/generator/Random';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Random from '../../../random/generator/Random';

@@ -0,0 +0,0 @@ import Arbitrary from './Arbitrary';

@@ -0,0 +0,0 @@ import Stream from '../../../stream/Stream';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ArbitraryWithShrink } from './definition/ArbitraryWithShrink';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Arbitrary } from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Arbitrary } from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

import { tuple } from './TupleArbitrary.generated';
import { genericTuple } from './TupleArbitrary.generic';
export { tuple, genericTuple };

@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary';

@@ -0,0 +0,0 @@ import Random from '../../random/generator/Random';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

import { asyncProperty } from './AsyncProperty.generated';
import { AsyncProperty } from './AsyncProperty.generic';
export { asyncProperty, AsyncProperty };

@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

3

lib/check/property/AsyncProperty.generic.d.ts
import Random from '../../random/generator/Random';
import Arbitrary from '../arbitrary/definition/Arbitrary';
import Shrinkable from '../arbitrary/definition/Shrinkable';
import { PreconditionFailure } from '../precondition/PreconditionFailure';
import { IProperty } from './IProperty';

@@ -16,3 +17,3 @@ /**

generate(mrng: Random, runId?: number): Shrinkable<Ts>;
run(v: Ts): Promise<string | null>;
run(v: Ts): Promise<PreconditionFailure | string | null>;
}

@@ -38,2 +38,3 @@ "use strict";

exports.__esModule = true;
var PreconditionFailure_1 = require("../precondition/PreconditionFailure");
var IProperty_1 = require("./IProperty");

@@ -67,2 +68,6 @@ /**

err_1 = _a.sent();
// precondition failure considered as success for the first version
if (PreconditionFailure_1.PreconditionFailure.isFailure(err_1))
return [2 /*return*/, err_1];
// exception as string in case of real failure
if (err_1 instanceof Error && err_1.stack)

@@ -69,0 +74,0 @@ return [2 /*return*/, err_1 + "\n\nStack trace: " + err_1.stack];

@@ -0,0 +0,0 @@ "use strict";

import Random from '../../random/generator/Random';
import Shrinkable from '../arbitrary/definition/Shrinkable';
import { PreconditionFailure } from '../precondition/PreconditionFailure';
/**

@@ -28,3 +29,3 @@ * Property

*/
run(v: Ts): Promise<string | null> | (string | null);
run(v: Ts): Promise<PreconditionFailure | string | null> | (PreconditionFailure | string | null);
}

@@ -31,0 +32,0 @@ /**

@@ -0,0 +0,0 @@ "use strict";

import { property } from './Property.generated';
import { Property } from './Property.generic';
export { property, Property };

@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary';

@@ -0,0 +0,0 @@ "use strict";

import Random from '../../random/generator/Random';
import Arbitrary from '../arbitrary/definition/Arbitrary';
import Shrinkable from '../arbitrary/definition/Shrinkable';
import { PreconditionFailure } from '../precondition/PreconditionFailure';
import { IProperty } from './IProperty';

@@ -16,3 +17,3 @@ /**

generate(mrng: Random, runId?: number): Shrinkable<Ts>;
run(v: Ts): string | null;
run(v: Ts): PreconditionFailure | string | null;
}
"use strict";
exports.__esModule = true;
var PreconditionFailure_1 = require("../precondition/PreconditionFailure");
var IProperty_1 = require("./IProperty");

@@ -24,2 +25,6 @@ /**

catch (err) {
// precondition failure considered as success for the first version
if (PreconditionFailure_1.PreconditionFailure.isFailure(err))
return err;
// exception as string in case of real failure
if (err instanceof Error && err.stack)

@@ -26,0 +31,0 @@ return err + "\n\nStack trace: " + err.stack;

@@ -0,0 +0,0 @@ "use strict";

@@ -11,3 +11,3 @@ import Random from '../../random/generator/Random';

generate(mrng: Random, runId?: number): Shrinkable<Ts>;
run(v: Ts): Promise<string | null>;
run(v: Ts): Promise<string | import("../precondition/PreconditionFailure").PreconditionFailure | null>;
}

@@ -0,0 +0,0 @@ "use strict";

import Random from '../../random/generator/Random';
import Shrinkable from '../arbitrary/definition/Shrinkable';
import IProperty from './IProperty';

@@ -9,4 +8,4 @@ /** @hidden */

isAsync: () => boolean;
generate: (mrng: Random, runId?: number | undefined) => Shrinkable<Ts>;
run: (v: Ts) => string | Promise<string | null> | null;
generate: (mrng: Random, runId?: number | undefined) => import("../arbitrary/definition/Shrinkable").default<Ts>;
run: (v: Ts) => string | import("../precondition/PreconditionFailure").PreconditionFailure | Promise<string | import("../precondition/PreconditionFailure").PreconditionFailure | null> | null;
}

@@ -0,0 +0,0 @@ "use strict";

@@ -16,2 +16,11 @@ /**

/**
* Maximal number of skipped values per run
*
* Skipped is considered globally, so this value is used to compute maxSkips = maxSkipsPerRun * numRuns.
* Runner will consider a run to have failed if it skipped maxSkips+1 times before having generated numRuns valid entries.
*
* See {@link pre} for more details on pre-conditions
*/
maxSkipsPerRun?: number;
/**
* Maximum time in milliseconds for the predicate to answer: disabled by default

@@ -18,0 +27,0 @@ *

"use strict";
exports.__esModule = true;

@@ -12,2 +12,3 @@ import { Parameters } from './Parameters';

numRuns: number;
maxSkipsPerRun: number;
timeout: number | null;

@@ -20,2 +21,3 @@ path: string;

private static readNumRuns;
private static readMaxSkipsPerRun;
private static readTimeout;

@@ -22,0 +24,0 @@ private static readPath;

@@ -21,2 +21,3 @@ "use strict";

numRuns: QualifiedParameters.readNumRuns(p),
maxSkipsPerRun: QualifiedParameters.readMaxSkipsPerRun(p),
timeout: QualifiedParameters.readTimeout(p),

@@ -53,2 +54,5 @@ logger: QualifiedParameters.readLogger(p),

};
QualifiedParameters.readMaxSkipsPerRun = function (p) {
return p != null && p.maxSkipsPerRun != null ? p.maxSkipsPerRun : 100;
};
QualifiedParameters.readTimeout = function (p) { return (p != null && p.timeout != null ? p.timeout : null); };

@@ -55,0 +59,0 @@ QualifiedParameters.readPath = function (p) { return (p != null && p.path != null ? p.path : ''); };

@@ -19,2 +19,9 @@ /**

/**
* Number of skipped entries due to failed pre-condition
*
* As `numRuns` it only takes into account the skipped values that occured before the first failure.
* Refer to {@link pre} to add such pre-conditions.
*/
numSkips: number;
/**
* Number of shrinks required to get to the minimal failing case (aka counterexample)

@@ -21,0 +28,0 @@ */

"use strict";
exports.__esModule = true;

@@ -15,4 +15,8 @@ import { RunDetails } from './RunDetails';

allFailures: Ts[];
numSkips: number;
numSuccesses: number;
constructor(storeFailures: boolean);
fail(value: Ts, id: number, message: string): void;
skip(): void;
success(): void;
private isSuccess;

@@ -22,3 +26,3 @@ private firstFailure;

private static mergePaths;
toRunDetails(seed: number, basePath: string, numRuns: number): RunDetails<Ts>;
toRunDetails(seed: number, basePath: string, numRuns: number, maxSkips: number): RunDetails<Ts>;
}

@@ -38,2 +38,4 @@ "use strict";

this.allFailures = [];
this.numSkips = 0;
this.numSuccesses = 0;
}

@@ -50,17 +52,19 @@ RunExecution.prototype.fail = function (value, id, message) {

};
RunExecution.prototype.toRunDetails = function (seed, basePath, numRuns) {
return this.isSuccess()
? {
failed: false,
numRuns: numRuns,
numShrinks: 0,
seed: seed,
counterexample: null,
counterexamplePath: null,
error: null,
failures: []
}
: {
RunExecution.prototype.skip = function () {
if (this.pathToFailure == null) {
++this.numSkips;
}
};
RunExecution.prototype.success = function () {
if (this.pathToFailure == null) {
++this.numSuccesses;
}
};
RunExecution.prototype.toRunDetails = function (seed, basePath, numRuns, maxSkips) {
if (!this.isSuccess()) {
// encountered a property failure
return {
failed: true,
numRuns: this.firstFailure() + 1,
numRuns: this.firstFailure() + 1 - this.numSkips,
numSkips: this.numSkips,
numShrinks: this.numShrinks(),

@@ -73,2 +77,28 @@ seed: seed,

};
}
if (this.numSkips > maxSkips) {
// too many skips
return {
failed: true,
numRuns: this.numSuccesses,
numSkips: this.numSkips,
numShrinks: 0,
seed: seed,
counterexample: null,
counterexamplePath: null,
error: null,
failures: []
};
}
return {
failed: false,
numRuns: numRuns,
numSkips: this.numSkips,
numShrinks: 0,
seed: seed,
counterexample: null,
counterexamplePath: null,
error: null,
failures: []
};
};

@@ -75,0 +105,0 @@ RunExecution.mergePaths = function (offsetPath, path) {

@@ -0,0 +0,0 @@ import { AsyncProperty } from '../property/AsyncProperty';

@@ -47,3 +47,24 @@ "use strict";

};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
exports.__esModule = true;
var Stream_1 = require("../../stream/Stream");
var TimeoutProperty_1 = require("../property/TimeoutProperty");

@@ -57,7 +78,24 @@ var UnbiasedProperty_1 = require("../property/UnbiasedProperty");

/** @hidden */
function runIt(property, initialValues, verbose) {
function runIt(property, initialValues, maxInitialIterations, remainingSkips, verbose) {
var e_1, _a;
var runExecution = new RunExecution_1.RunExecution(verbose);
var done = false;
var values = initialValues;
function g() {
var n;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(--maxInitialIterations !== -1 && remainingSkips >= 0)) return [3 /*break*/, 2];
n = initialValues.next();
if (n.done)
return [2 /*return*/];
return [4 /*yield*/, n.value()];
case 1:
_a.sent();
return [3 /*break*/, 0];
case 2: return [2 /*return*/];
}
});
}
var values = g();
while (!done) {

@@ -70,3 +108,3 @@ done = true;

var out = property.run(v.value);
if (out != null) {
if (out != null && typeof out === 'string') {
runExecution.fail(v.value, idx, out);

@@ -77,2 +115,11 @@ values = v.shrink();

}
if (out != null) {
// skipped the run
runExecution.skip();
--remainingSkips;
++maxInitialIterations;
}
else {
runExecution.success();
}
++idx;

@@ -92,4 +139,21 @@ }

/** @hidden */
function asyncRunIt(property, initialValues, verbose) {
function asyncRunIt(property, initialValues, maxInitialIterations, remainingSkips, verbose) {
return __awaiter(this, void 0, void 0, function () {
function g() {
var n;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(--maxInitialIterations !== -1 && remainingSkips >= 0)) return [3 /*break*/, 2];
n = initialValues.next();
if (n.done)
return [2 /*return*/];
return [4 /*yield*/, n.value()];
case 1:
_a.sent();
return [3 /*break*/, 0];
case 2: return [2 /*return*/];
}
});
}
var e_2, _a, runExecution, done, values, idx, values_2, values_2_1, v, out, e_2_1;

@@ -101,3 +165,3 @@ return __generator(this, function (_b) {

done = false;
values = initialValues;
values = g();
_b.label = 1;

@@ -119,3 +183,3 @@ case 1:

out = _b.sent();
if (out != null) {
if (out != null && typeof out === 'string') {
runExecution.fail(v.value, idx, out);

@@ -126,2 +190,11 @@ values = v.shrink();

}
if (out != null) {
// skipped the run
runExecution.skip();
--remainingSkips;
++maxInitialIterations;
}
else {
runExecution.success();
}
++idx;

@@ -154,2 +227,11 @@ _b.label = 5;

}
/** @hidden */
function runnerPathWalker(valueProducers, path) {
var pathPoints = path.split(':');
var pathStream = Stream_1.stream(valueProducers)
.drop(pathPoints.length > 0 ? +pathPoints[0] : 0)
.map(function (producer) { return producer(); });
var adaptedPath = __spread(['0'], pathPoints.slice(1)).join(':');
return Stream_1.stream(PathWalker_1.pathWalk(adaptedPath, pathStream)).map(function (v) { return function () { return v; }; });
}
function check(rawProperty, params) {

@@ -163,28 +245,10 @@ if (rawProperty == null || rawProperty.generate == null)

var generator = Tosser_1.toss(property, qParams.seed);
function g() {
var idx;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
idx = 0;
_a.label = 1;
case 1:
if (!(idx < qParams.numRuns)) return [3 /*break*/, 4];
return [4 /*yield*/, generator.next().value()];
case 2:
_a.sent();
_a.label = 3;
case 3:
++idx;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
}
var initialValues = qParams.path.length === 0 ? g() : PathWalker_1.pathWalk(qParams.path, g());
var maxInitialIterations = qParams.path.length === 0 ? qParams.numRuns : -1;
var maxSkips = qParams.numRuns * qParams.maxSkipsPerRun;
var initialValues = qParams.path.length === 0 ? generator : runnerPathWalker(generator, qParams.path);
return property.isAsync()
? asyncRunIt(property, initialValues, qParams.verbose).then(function (e) {
return e.toRunDetails(qParams.seed, qParams.path, qParams.numRuns);
? asyncRunIt(property, initialValues, maxInitialIterations, maxSkips, qParams.verbose).then(function (e) {
return e.toRunDetails(qParams.seed, qParams.path, qParams.numRuns, maxSkips);
})
: runIt(property, initialValues, qParams.verbose).toRunDetails(qParams.seed, qParams.path, qParams.numRuns);
: runIt(property, initialValues, maxInitialIterations, maxSkips, qParams.verbose).toRunDetails(qParams.seed, qParams.path, qParams.numRuns, maxSkips);
}

@@ -191,0 +255,0 @@ exports.check = check;

@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary';

@@ -34,2 +34,3 @@ "use strict";

var Stream_1 = require("../../stream/Stream");
var polyfills_1 = require("../polyfills");
var Property_1 = require("../property/Property");

@@ -126,3 +127,3 @@ var UnbiasedProperty_1 = require("../property/UnbiasedProperty");

}
var data = Object.entries(recorded)
var data = polyfills_1.ObjectEntries(recorded)
.sort(function (a, b) { return b[1] - a[1]; })

@@ -135,3 +136,3 @@ .map(function (i) { return [i[0], (i[1] * 100.0 / qParams.numRuns).toFixed(2) + "%"]; });

var item = data_1_1.value;
qParams.logger(item[0].padEnd(longestName, '.') + ".." + item[1].padStart(longestPercent, '.'));
qParams.logger(polyfills_1.StringPadEnd(item[0], longestName, '.') + ".." + polyfills_1.StringPadStart(item[1], longestPercent, '.'));
}

@@ -138,0 +139,0 @@ }

@@ -0,0 +0,0 @@ import Shrinkable from '../arbitrary/definition/Shrinkable';

@@ -0,0 +0,0 @@ "use strict";

import Shrinkable from '../../arbitrary/definition/Shrinkable';
/** @hidden */
export declare function pathWalk<Ts>(path: string, initialValues: IterableIterator<Shrinkable<Ts>>): IterableIterator<Shrinkable<Ts>>;

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { RunDetails } from '../reporter/RunDetails';

@@ -47,3 +47,6 @@ "use strict";

if (out.failed) {
throw new Error("Property failed after " + out.numRuns + " tests (seed: " + out.seed + ", path: " + out.counterexamplePath + "): " + pretty(out.counterexample) + "\nShrunk " + out.numShrinks + " time(s)\nGot error: " + out.error + "\n\n" + (out.failures.length === 0
if (out.counterexample == null) {
throw new Error("Failed to run property, too many pre-condition failures encountered\n\nRan " + out.numRuns + " time(s)\nSkipped " + out.numSkips + " time(s)\n\nHint (1): Try to reduce the number of rejected values by combining map, flatMap and built-in arbitraries\nHint (2): Increase failure tolerance by setting maxSkipsPerRun to an higher value");
}
throw new Error("Property failed after " + out.numRuns + " tests\n{ seed: " + out.seed + ", path: \"" + out.counterexamplePath + "\" }\nCounterexample: " + pretty(out.counterexample) + "\nShrunk " + out.numShrinks + " time(s)\nGot error: " + out.error + "\n\n" + (out.failures.length === 0
? 'Hint: Enable verbose mode in order to have the list of all failing values encountered during the run'

@@ -50,0 +53,0 @@ : "Encountered failures were:\n- " + out.failures.map(pretty).join('\n- ')));

@@ -1,2 +0,2 @@

import 'core-js';
import { pre } from './check/precondition/Pre';
import { asyncProperty } from './check/property/AsyncProperty';

@@ -28,2 +28,2 @@ import { property } from './check/property/Property';

import { Stream, stream } from './stream/Stream';
export { sample, statistics, check, assert, property, asyncProperty, boolean, float, double, integer, nat, char, ascii, char16bits, unicode, fullUnicode, hexa, base64, string, asciiString, string16bits, stringOf, unicodeString, fullUnicodeString, hexaString, base64String, lorem, constant, constantFrom, option, oneof, frequency, array, set, tuple, genericTuple, record, dictionary, anything, object, json, jsonObject, unicodeJson, unicodeJsonObject, Arbitrary, Shrinkable, ObjectConstraints, Parameters, RecordConstraints, RunDetails, Random, Stream, stream };
export { sample, statistics, check, assert, pre, property, asyncProperty, boolean, float, double, integer, nat, char, ascii, char16bits, unicode, fullUnicode, hexa, base64, string, asciiString, string16bits, stringOf, unicodeString, fullUnicodeString, hexaString, base64String, lorem, constant, constantFrom, option, oneof, frequency, array, set, tuple, genericTuple, record, dictionary, anything, object, json, jsonObject, unicodeJson, unicodeJsonObject, Arbitrary, Shrinkable, ObjectConstraints, Parameters, RecordConstraints, RunDetails, Random, Stream, stream };
"use strict";
exports.__esModule = true;
require("core-js");
var Pre_1 = require("./check/precondition/Pre");
exports.pre = Pre_1.pre;
var AsyncProperty_1 = require("./check/property/AsyncProperty");

@@ -5,0 +6,0 @@ exports.asyncProperty = AsyncProperty_1.asyncProperty;

import * as fc from './fast-check-default';
export default fc;
export * from './fast-check-default';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import * as prand from 'pure-rand';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export default class Stream<T> implements IterableIterator<T> {

@@ -0,0 +0,0 @@ "use strict";

{
"name": "fast-check",
"version": "1.2.3",
"version": "1.3.0",
"description": "Property based testing framework in TypeScript (like QuickCheck)",

@@ -33,3 +33,2 @@ "main": "lib/fast-check.js",

"dependencies": {
"core-js": "^2.5.5",
"lorem-ipsum": "^1.0.4",

@@ -36,0 +35,0 @@ "pure-rand": "^1.1.1"

@@ -108,2 +108,3 @@ <h3 align="center">

- biased by default - *by default it generates both small and large values, making it easier to dig into counterexamples without having to tweak a size parameter manually*
- precondition checks with `fc.pre(...)` - *filtering invalid entries can be done directly inside the check function if needed*
- verbose mode - *easier troubleshooting with verbose mode enabled*

@@ -110,0 +111,0 @@ - replay directly on the minimal counterexample - *no need to replay the whole sequence, you get directly the counterexample*

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc