fast-check
Advanced tools
Comparing version 3.6.1 to 3.6.2
@@ -0,1 +1,12 @@ | ||
# 3.6.2 | ||
_Still work in fake timer contexts_ | ||
[[Code](https://github.com/dubzzz/fast-check/tree/v3.6.2)][[Diff](https://github.com/dubzzz/fast-check/compare/v3.6.1...v3.6.2)] | ||
## Fixes | ||
- ([PR#3571](https://github.com/dubzzz/fast-check/pull/3571)) Bug: Resist to fake timers in interruptAfterTimeLimit | ||
- ([PR#3572](https://github.com/dubzzz/fast-check/pull/3572)) Bug: Resist to fake timers in timeout | ||
- ([PR#3564](https://github.com/dubzzz/fast-check/pull/3564)) Performance: Drop bailout linked to toss | ||
# 3.6.1 | ||
@@ -2,0 +13,0 @@ |
@@ -49,3 +49,3 @@ "use strict"; | ||
}) | ||
.map((values) => tupleWrapper(values)))); | ||
.map(tupleWrapper))); | ||
} | ||
@@ -66,3 +66,7 @@ return Stream_1.Stream.nil().join(...shrinks); | ||
generate(mrng, biasFactor) { | ||
return tupleWrapper((0, globals_1.safeMap)(this.arbs, (a) => a.generate(mrng, biasFactor))); | ||
const mapped = []; | ||
for (let idx = 0; idx !== this.arbs.length; ++idx) { | ||
(0, globals_1.safePush)(mapped, this.arbs[idx].generate(mrng, biasFactor)); | ||
} | ||
return tupleWrapper(mapped); | ||
} | ||
@@ -69,0 +73,0 @@ canShrinkWithoutContext(value) { |
@@ -5,6 +5,6 @@ "use strict"; | ||
const PreconditionFailure_1 = require("../precondition/PreconditionFailure"); | ||
function interruptAfter(timeMs) { | ||
function interruptAfter(timeMs, setTimeoutSafe, clearTimeoutSafe) { | ||
let timeoutHandle = null; | ||
const promise = new Promise((resolve) => { | ||
timeoutHandle = setTimeout(() => { | ||
timeoutHandle = setTimeoutSafe(() => { | ||
const preconditionFailure = new PreconditionFailure_1.PreconditionFailure(true); | ||
@@ -15,3 +15,3 @@ resolve(preconditionFailure); | ||
return { | ||
clear: () => clearTimeout(timeoutHandle), | ||
clear: () => clearTimeoutSafe(timeoutHandle), | ||
promise, | ||
@@ -21,6 +21,8 @@ }; | ||
class SkipAfterProperty { | ||
constructor(property, getTime, timeLimit, interruptExecution) { | ||
constructor(property, getTime, timeLimit, interruptExecution, setTimeoutSafe, clearTimeoutSafe) { | ||
this.property = property; | ||
this.getTime = getTime; | ||
this.interruptExecution = interruptExecution; | ||
this.setTimeoutSafe = setTimeoutSafe; | ||
this.clearTimeoutSafe = clearTimeoutSafe; | ||
this.skipAfterTime = this.getTime() + timeLimit; | ||
@@ -53,3 +55,3 @@ if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) { | ||
if (this.interruptExecution && this.isAsync()) { | ||
const t = interruptAfter(remainingTime); | ||
const t = interruptAfter(remainingTime, this.setTimeoutSafe, this.clearTimeoutSafe); | ||
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]); | ||
@@ -56,0 +58,0 @@ propRun.then(t.clear, t.clear); |
@@ -5,6 +5,6 @@ "use strict"; | ||
const globals_1 = require("../../utils/globals"); | ||
const timeoutAfter = (timeMs) => { | ||
const timeoutAfter = (timeMs, setTimeoutSafe, clearTimeoutSafe) => { | ||
let timeoutHandle = null; | ||
const promise = new Promise((resolve) => { | ||
timeoutHandle = setTimeout(() => { | ||
timeoutHandle = setTimeoutSafe(() => { | ||
resolve({ | ||
@@ -17,3 +17,3 @@ error: new globals_1.Error(`Property timeout: exceeded limit of ${timeMs} milliseconds`), | ||
return { | ||
clear: () => clearTimeout(timeoutHandle), | ||
clear: () => clearTimeoutSafe(timeoutHandle), | ||
promise, | ||
@@ -23,5 +23,7 @@ }; | ||
class TimeoutProperty { | ||
constructor(property, timeMs) { | ||
constructor(property, timeMs, setTimeoutSafe, clearTimeoutSafe) { | ||
this.property = property; | ||
this.timeMs = timeMs; | ||
this.setTimeoutSafe = setTimeoutSafe; | ||
this.clearTimeoutSafe = clearTimeoutSafe; | ||
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) { | ||
@@ -42,3 +44,3 @@ this.runBeforeEach = () => Promise.resolve(this.property.runBeforeEach()); | ||
async run(v, dontRunHook) { | ||
const t = timeoutAfter(this.timeMs); | ||
const t = timeoutAfter(this.timeMs, this.setTimeoutSafe, this.clearTimeoutSafe); | ||
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]); | ||
@@ -45,0 +47,0 @@ propRun.then(t.clear, t.clear); |
@@ -9,6 +9,8 @@ "use strict"; | ||
const safeDateNow = Date.now; | ||
const safeSetTimeout = setTimeout; | ||
const safeClearTimeout = clearTimeout; | ||
function decorateProperty(rawProperty, qParams) { | ||
let prop = rawProperty; | ||
if (rawProperty.isAsync() && qParams.timeout != null) { | ||
prop = new TimeoutProperty_1.TimeoutProperty(prop, qParams.timeout); | ||
prop = new TimeoutProperty_1.TimeoutProperty(prop, qParams.timeout, safeSetTimeout, safeClearTimeout); | ||
} | ||
@@ -19,6 +21,6 @@ if (qParams.unbiased) { | ||
if (qParams.skipAllAfterTimeLimit != null) { | ||
prop = new SkipAfterProperty_1.SkipAfterProperty(prop, safeDateNow, qParams.skipAllAfterTimeLimit, false); | ||
prop = new SkipAfterProperty_1.SkipAfterProperty(prop, safeDateNow, qParams.skipAllAfterTimeLimit, false, safeSetTimeout, safeClearTimeout); | ||
} | ||
if (qParams.interruptAfterTimeLimit != null) { | ||
prop = new SkipAfterProperty_1.SkipAfterProperty(prop, safeDateNow, qParams.interruptAfterTimeLimit, true); | ||
prop = new SkipAfterProperty_1.SkipAfterProperty(prop, safeDateNow, qParams.interruptAfterTimeLimit, true, safeSetTimeout, safeClearTimeout); | ||
} | ||
@@ -25,0 +27,0 @@ if (qParams.skipEqualValues) { |
@@ -8,10 +8,13 @@ "use strict"; | ||
const globals_1 = require("../../utils/globals"); | ||
function tossNext(generator, rng, index) { | ||
rng.unsafeJump(); | ||
return generator.generate(new Random_1.Random(rng), index); | ||
} | ||
function* toss(generator, seed, random, examples) { | ||
yield* (0, globals_1.safeMap)(examples, (e) => new Value_1.Value(e, undefined)); | ||
let idx = 0; | ||
const rng = random(seed); | ||
for (;;) { | ||
rng.unsafeJump(); | ||
yield generator.generate(new Random_1.Random(rng), idx++); | ||
for (let idx = 0; idx !== examples.length; ++idx) { | ||
yield new Value_1.Value(examples[idx], undefined); | ||
} | ||
for (let idx = 0, rng = random(seed);; ++idx) { | ||
yield tossNext(generator, rng, idx); | ||
} | ||
} | ||
@@ -18,0 +21,0 @@ exports.toss = toss; |
@@ -46,3 +46,3 @@ import { Stream } from '../../stream/Stream.js'; | ||
}) | ||
.map((values) => tupleWrapper(values)))); | ||
.map(tupleWrapper))); | ||
} | ||
@@ -62,3 +62,7 @@ return Stream.nil().join(...shrinks); | ||
generate(mrng, biasFactor) { | ||
return tupleWrapper(safeMap(this.arbs, (a) => a.generate(mrng, biasFactor))); | ||
const mapped = []; | ||
for (let idx = 0; idx !== this.arbs.length; ++idx) { | ||
safePush(mapped, this.arbs[idx].generate(mrng, biasFactor)); | ||
} | ||
return tupleWrapper(mapped); | ||
} | ||
@@ -65,0 +69,0 @@ canShrinkWithoutContext(value) { |
import { PreconditionFailure } from '../precondition/PreconditionFailure.js'; | ||
function interruptAfter(timeMs) { | ||
function interruptAfter(timeMs, setTimeoutSafe, clearTimeoutSafe) { | ||
let timeoutHandle = null; | ||
const promise = new Promise((resolve) => { | ||
timeoutHandle = setTimeout(() => { | ||
timeoutHandle = setTimeoutSafe(() => { | ||
const preconditionFailure = new PreconditionFailure(true); | ||
@@ -11,3 +11,3 @@ resolve(preconditionFailure); | ||
return { | ||
clear: () => clearTimeout(timeoutHandle), | ||
clear: () => clearTimeoutSafe(timeoutHandle), | ||
promise, | ||
@@ -17,6 +17,8 @@ }; | ||
export class SkipAfterProperty { | ||
constructor(property, getTime, timeLimit, interruptExecution) { | ||
constructor(property, getTime, timeLimit, interruptExecution, setTimeoutSafe, clearTimeoutSafe) { | ||
this.property = property; | ||
this.getTime = getTime; | ||
this.interruptExecution = interruptExecution; | ||
this.setTimeoutSafe = setTimeoutSafe; | ||
this.clearTimeoutSafe = clearTimeoutSafe; | ||
this.skipAfterTime = this.getTime() + timeLimit; | ||
@@ -49,3 +51,3 @@ if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) { | ||
if (this.interruptExecution && this.isAsync()) { | ||
const t = interruptAfter(remainingTime); | ||
const t = interruptAfter(remainingTime, this.setTimeoutSafe, this.clearTimeoutSafe); | ||
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]); | ||
@@ -52,0 +54,0 @@ propRun.then(t.clear, t.clear); |
import { Error } from '../../utils/globals.js'; | ||
const timeoutAfter = (timeMs) => { | ||
const timeoutAfter = (timeMs, setTimeoutSafe, clearTimeoutSafe) => { | ||
let timeoutHandle = null; | ||
const promise = new Promise((resolve) => { | ||
timeoutHandle = setTimeout(() => { | ||
timeoutHandle = setTimeoutSafe(() => { | ||
resolve({ | ||
@@ -13,3 +13,3 @@ error: new Error(`Property timeout: exceeded limit of ${timeMs} milliseconds`), | ||
return { | ||
clear: () => clearTimeout(timeoutHandle), | ||
clear: () => clearTimeoutSafe(timeoutHandle), | ||
promise, | ||
@@ -19,5 +19,7 @@ }; | ||
export class TimeoutProperty { | ||
constructor(property, timeMs) { | ||
constructor(property, timeMs, setTimeoutSafe, clearTimeoutSafe) { | ||
this.property = property; | ||
this.timeMs = timeMs; | ||
this.setTimeoutSafe = setTimeoutSafe; | ||
this.clearTimeoutSafe = clearTimeoutSafe; | ||
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) { | ||
@@ -38,3 +40,3 @@ this.runBeforeEach = () => Promise.resolve(this.property.runBeforeEach()); | ||
async run(v, dontRunHook) { | ||
const t = timeoutAfter(this.timeMs); | ||
const t = timeoutAfter(this.timeMs, this.setTimeoutSafe, this.clearTimeoutSafe); | ||
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]); | ||
@@ -41,0 +43,0 @@ propRun.then(t.clear, t.clear); |
@@ -6,6 +6,8 @@ import { SkipAfterProperty } from '../property/SkipAfterProperty.js'; | ||
const safeDateNow = Date.now; | ||
const safeSetTimeout = setTimeout; | ||
const safeClearTimeout = clearTimeout; | ||
export function decorateProperty(rawProperty, qParams) { | ||
let prop = rawProperty; | ||
if (rawProperty.isAsync() && qParams.timeout != null) { | ||
prop = new TimeoutProperty(prop, qParams.timeout); | ||
prop = new TimeoutProperty(prop, qParams.timeout, safeSetTimeout, safeClearTimeout); | ||
} | ||
@@ -16,6 +18,6 @@ if (qParams.unbiased) { | ||
if (qParams.skipAllAfterTimeLimit != null) { | ||
prop = new SkipAfterProperty(prop, safeDateNow, qParams.skipAllAfterTimeLimit, false); | ||
prop = new SkipAfterProperty(prop, safeDateNow, qParams.skipAllAfterTimeLimit, false, safeSetTimeout, safeClearTimeout); | ||
} | ||
if (qParams.interruptAfterTimeLimit != null) { | ||
prop = new SkipAfterProperty(prop, safeDateNow, qParams.interruptAfterTimeLimit, true); | ||
prop = new SkipAfterProperty(prop, safeDateNow, qParams.interruptAfterTimeLimit, true, safeSetTimeout, safeClearTimeout); | ||
} | ||
@@ -22,0 +24,0 @@ if (qParams.skipEqualValues) { |
@@ -5,10 +5,13 @@ import { skipN } from 'pure-rand'; | ||
import { safeMap } from '../../utils/globals.js'; | ||
function tossNext(generator, rng, index) { | ||
rng.unsafeJump(); | ||
return generator.generate(new Random(rng), index); | ||
} | ||
export function* toss(generator, seed, random, examples) { | ||
yield* safeMap(examples, (e) => new Value(e, undefined)); | ||
let idx = 0; | ||
const rng = random(seed); | ||
for (;;) { | ||
rng.unsafeJump(); | ||
yield generator.generate(new Random(rng), idx++); | ||
for (let idx = 0; idx !== examples.length; ++idx) { | ||
yield new Value(examples[idx], undefined); | ||
} | ||
for (let idx = 0, rng = random(seed);; ++idx) { | ||
yield tossNext(generator, rng, idx); | ||
} | ||
} | ||
@@ -15,0 +18,0 @@ export function* lazyToss(generator, seed, random, examples) { |
@@ -104,4 +104,4 @@ import { pre } from './check/precondition/Pre.js'; | ||
const __type = 'module'; | ||
const __version = '3.6.1'; | ||
const __commitHash = '6841f98c90165dac5921f1a3bbbe678b138d1200'; | ||
const __version = '3.6.2'; | ||
const __commitHash = '0d0a63c39c2e37243e673c722b02671ccaaa782e'; | ||
export { __type, __version, __commitHash, sample, statistics, check, assert, pre, PreconditionFailure, property, asyncProperty, boolean, falsy, float, double, integer, nat, maxSafeInteger, maxSafeNat, bigIntN, bigUintN, bigInt, bigUint, char, ascii, char16bits, unicode, fullUnicode, hexa, base64, mixedCase, string, asciiString, string16bits, stringOf, unicodeString, fullUnicodeString, hexaString, base64String, lorem, constant, constantFrom, mapToConstant, option, oneof, clone, shuffledSubarray, subarray, array, sparseArray, infiniteStream, uniqueArray, tuple, record, dictionary, anything, object, json, jsonValue, unicodeJson, unicodeJsonValue, letrec, memo, compareBooleanFunc, compareFunc, func, context, date, ipV4, ipV4Extended, ipV6, domain, webAuthority, webSegment, webFragments, webPath, webQueryParameters, webUrl, emailAddress, uuid, uuidV, int8Array, uint8Array, uint8ClampedArray, int16Array, uint16Array, int32Array, uint32Array, float32Array, float64Array, bigInt64Array, bigUint64Array, asyncModelRun, modelRun, scheduledModelRun, commands, scheduler, schedulerFor, Arbitrary, Value, cloneMethod, cloneIfNeeded, hasCloneMethod, toStringMethod, hasToStringMethod, asyncToStringMethod, hasAsyncToStringMethod, getDepthContextFor, stringify, asyncStringify, defaultReportMessage, asyncDefaultReportMessage, hash, VerbosityLevel, configureGlobal, readConfigureGlobal, resetConfigureGlobal, ExecutionStatus, Random, Stream, stream, createDepthIdentifier, }; |
@@ -229,5 +229,5 @@ "use strict"; | ||
exports.__type = __type; | ||
const __version = '3.6.1'; | ||
const __version = '3.6.2'; | ||
exports.__version = __version; | ||
const __commitHash = '6841f98c90165dac5921f1a3bbbe678b138d1200'; | ||
const __commitHash = '0d0a63c39c2e37243e673c722b02671ccaaa782e'; | ||
exports.__commitHash = __commitHash; |
@@ -120,3 +120,3 @@ import { pre } from './check/precondition/Pre'; | ||
/** | ||
* Version of fast-check used by your project (eg.: 3.6.1) | ||
* Version of fast-check used by your project (eg.: 3.6.2) | ||
* @remarks Since 1.22.0 | ||
@@ -127,3 +127,3 @@ * @public | ||
/** | ||
* Commit hash of the current code (eg.: 6841f98c90165dac5921f1a3bbbe678b138d1200) | ||
* Commit hash of the current code (eg.: 0d0a63c39c2e37243e673c722b02671ccaaa782e) | ||
* @remarks Since 2.7.0 | ||
@@ -130,0 +130,0 @@ * @public |
{ | ||
"name": "fast-check", | ||
"version": "3.6.1", | ||
"version": "3.6.2", | ||
"description": "Property based testing framework for JavaScript (like QuickCheck)", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
884228
19928