Erster Docker-Stand
This commit is contained in:
79
_node_modules/fast-check/lib/esm/check/property/AsyncProperty.generic.js
generated
Normal file
79
_node_modules/fast-check/lib/esm/check/property/AsyncProperty.generic.js
generated
Normal file
@@ -0,0 +1,79 @@
|
||||
import { PreconditionFailure } from '../precondition/PreconditionFailure.js';
|
||||
import { runIdToFrequency } from './IRawProperty.js';
|
||||
import { readConfigureGlobal } from '../runner/configuration/GlobalParameters.js';
|
||||
import { Stream } from '../../stream/Stream.js';
|
||||
import { noUndefinedAsContext, UndefinedContextPlaceholder, } from '../../arbitrary/_internals/helpers/NoUndefinedAsContext.js';
|
||||
import { Error, String } from '../../utils/globals.js';
|
||||
export class AsyncProperty {
|
||||
constructor(arb, predicate) {
|
||||
this.arb = arb;
|
||||
this.predicate = predicate;
|
||||
const { asyncBeforeEach, asyncAfterEach, beforeEach, afterEach } = readConfigureGlobal() || {};
|
||||
if (asyncBeforeEach !== undefined && beforeEach !== undefined) {
|
||||
throw Error('Global "asyncBeforeEach" and "beforeEach" parameters can\'t be set at the same time when running async properties');
|
||||
}
|
||||
if (asyncAfterEach !== undefined && afterEach !== undefined) {
|
||||
throw Error('Global "asyncAfterEach" and "afterEach" parameters can\'t be set at the same time when running async properties');
|
||||
}
|
||||
this.beforeEachHook = asyncBeforeEach || beforeEach || AsyncProperty.dummyHook;
|
||||
this.afterEachHook = asyncAfterEach || afterEach || AsyncProperty.dummyHook;
|
||||
}
|
||||
isAsync() {
|
||||
return true;
|
||||
}
|
||||
generate(mrng, runId) {
|
||||
const value = this.arb.generate(mrng, runId != null ? runIdToFrequency(runId) : undefined);
|
||||
return noUndefinedAsContext(value);
|
||||
}
|
||||
shrink(value) {
|
||||
if (value.context === undefined && !this.arb.canShrinkWithoutContext(value.value_)) {
|
||||
return Stream.nil();
|
||||
}
|
||||
const safeContext = value.context !== UndefinedContextPlaceholder ? value.context : undefined;
|
||||
return this.arb.shrink(value.value_, safeContext).map(noUndefinedAsContext);
|
||||
}
|
||||
async runBeforeEach() {
|
||||
await this.beforeEachHook();
|
||||
}
|
||||
async runAfterEach() {
|
||||
await this.afterEachHook();
|
||||
}
|
||||
async run(v, dontRunHook) {
|
||||
if (!dontRunHook) {
|
||||
await this.beforeEachHook();
|
||||
}
|
||||
try {
|
||||
const output = await this.predicate(v);
|
||||
return output == null || output === true
|
||||
? null
|
||||
: {
|
||||
error: new Error('Property failed by returning false'),
|
||||
errorMessage: 'Error: Property failed by returning false',
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
if (PreconditionFailure.isFailure(err))
|
||||
return err;
|
||||
if (err instanceof Error && err.stack) {
|
||||
return { error: err, errorMessage: err.stack };
|
||||
}
|
||||
return { error: err, errorMessage: String(err) };
|
||||
}
|
||||
finally {
|
||||
if (!dontRunHook) {
|
||||
await this.afterEachHook();
|
||||
}
|
||||
}
|
||||
}
|
||||
beforeEach(hookFunction) {
|
||||
const previousBeforeEachHook = this.beforeEachHook;
|
||||
this.beforeEachHook = () => hookFunction(previousBeforeEachHook);
|
||||
return this;
|
||||
}
|
||||
afterEach(hookFunction) {
|
||||
const previousAfterEachHook = this.afterEachHook;
|
||||
this.afterEachHook = () => hookFunction(previousAfterEachHook);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
AsyncProperty.dummyHook = () => { };
|
||||
16
_node_modules/fast-check/lib/esm/check/property/AsyncProperty.js
generated
Normal file
16
_node_modules/fast-check/lib/esm/check/property/AsyncProperty.js
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
import { assertIsArbitrary } from '../arbitrary/definition/Arbitrary.js';
|
||||
import { tuple } from '../../arbitrary/tuple.js';
|
||||
import { AsyncProperty } from './AsyncProperty.generic.js';
|
||||
import { AlwaysShrinkableArbitrary } from '../../arbitrary/_internals/AlwaysShrinkableArbitrary.js';
|
||||
import { safeForEach, safeMap, safeSlice } from '../../utils/globals.js';
|
||||
function asyncProperty(...args) {
|
||||
if (args.length < 2) {
|
||||
throw new Error('asyncProperty expects at least two parameters');
|
||||
}
|
||||
const arbs = safeSlice(args, 0, args.length - 1);
|
||||
const p = args[args.length - 1];
|
||||
safeForEach(arbs, assertIsArbitrary);
|
||||
const mappedArbs = safeMap(arbs, (arb) => new AlwaysShrinkableArbitrary(arb));
|
||||
return new AsyncProperty(tuple(...mappedArbs), (t) => p(...t));
|
||||
}
|
||||
export { asyncProperty };
|
||||
4
_node_modules/fast-check/lib/esm/check/property/IRawProperty.js
generated
Normal file
4
_node_modules/fast-check/lib/esm/check/property/IRawProperty.js
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
const safeMathLog = Math.log;
|
||||
export function runIdToFrequency(runId) {
|
||||
return 2 + ~~(safeMathLog(runId + 1) * 0.4342944819032518);
|
||||
}
|
||||
46
_node_modules/fast-check/lib/esm/check/property/IgnoreEqualValuesProperty.js
generated
Normal file
46
_node_modules/fast-check/lib/esm/check/property/IgnoreEqualValuesProperty.js
generated
Normal file
@@ -0,0 +1,46 @@
|
||||
import { stringify } from '../../utils/stringify.js';
|
||||
import { PreconditionFailure } from '../precondition/PreconditionFailure.js';
|
||||
function fromSyncCached(cachedValue) {
|
||||
return cachedValue === null ? new PreconditionFailure() : cachedValue;
|
||||
}
|
||||
function fromCached(...data) {
|
||||
if (data[1])
|
||||
return data[0].then(fromSyncCached);
|
||||
return fromSyncCached(data[0]);
|
||||
}
|
||||
function fromCachedUnsafe(cachedValue, isAsync) {
|
||||
return fromCached(cachedValue, isAsync);
|
||||
}
|
||||
export class IgnoreEqualValuesProperty {
|
||||
constructor(property, skipRuns) {
|
||||
this.property = property;
|
||||
this.skipRuns = skipRuns;
|
||||
this.coveredCases = new Map();
|
||||
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
|
||||
this.runBeforeEach = () => this.property.runBeforeEach();
|
||||
this.runAfterEach = () => this.property.runAfterEach();
|
||||
}
|
||||
}
|
||||
isAsync() {
|
||||
return this.property.isAsync();
|
||||
}
|
||||
generate(mrng, runId) {
|
||||
return this.property.generate(mrng, runId);
|
||||
}
|
||||
shrink(value) {
|
||||
return this.property.shrink(value);
|
||||
}
|
||||
run(v, dontRunHook) {
|
||||
const stringifiedValue = stringify(v);
|
||||
if (this.coveredCases.has(stringifiedValue)) {
|
||||
const lastOutput = this.coveredCases.get(stringifiedValue);
|
||||
if (!this.skipRuns) {
|
||||
return lastOutput;
|
||||
}
|
||||
return fromCachedUnsafe(lastOutput, this.property.isAsync());
|
||||
}
|
||||
const out = this.property.run(v, dontRunHook);
|
||||
this.coveredCases.set(stringifiedValue, out);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
79
_node_modules/fast-check/lib/esm/check/property/Property.generic.js
generated
Normal file
79
_node_modules/fast-check/lib/esm/check/property/Property.generic.js
generated
Normal file
@@ -0,0 +1,79 @@
|
||||
import { PreconditionFailure } from '../precondition/PreconditionFailure.js';
|
||||
import { runIdToFrequency } from './IRawProperty.js';
|
||||
import { readConfigureGlobal } from '../runner/configuration/GlobalParameters.js';
|
||||
import { Stream } from '../../stream/Stream.js';
|
||||
import { noUndefinedAsContext, UndefinedContextPlaceholder, } from '../../arbitrary/_internals/helpers/NoUndefinedAsContext.js';
|
||||
import { Error, String } from '../../utils/globals.js';
|
||||
export class Property {
|
||||
constructor(arb, predicate) {
|
||||
this.arb = arb;
|
||||
this.predicate = predicate;
|
||||
const { beforeEach = Property.dummyHook, afterEach = Property.dummyHook, asyncBeforeEach, asyncAfterEach, } = readConfigureGlobal() || {};
|
||||
if (asyncBeforeEach !== undefined) {
|
||||
throw Error('"asyncBeforeEach" can\'t be set when running synchronous properties');
|
||||
}
|
||||
if (asyncAfterEach !== undefined) {
|
||||
throw Error('"asyncAfterEach" can\'t be set when running synchronous properties');
|
||||
}
|
||||
this.beforeEachHook = beforeEach;
|
||||
this.afterEachHook = afterEach;
|
||||
}
|
||||
isAsync() {
|
||||
return false;
|
||||
}
|
||||
generate(mrng, runId) {
|
||||
const value = this.arb.generate(mrng, runId != null ? runIdToFrequency(runId) : undefined);
|
||||
return noUndefinedAsContext(value);
|
||||
}
|
||||
shrink(value) {
|
||||
if (value.context === undefined && !this.arb.canShrinkWithoutContext(value.value_)) {
|
||||
return Stream.nil();
|
||||
}
|
||||
const safeContext = value.context !== UndefinedContextPlaceholder ? value.context : undefined;
|
||||
return this.arb.shrink(value.value_, safeContext).map(noUndefinedAsContext);
|
||||
}
|
||||
runBeforeEach() {
|
||||
this.beforeEachHook();
|
||||
}
|
||||
runAfterEach() {
|
||||
this.afterEachHook();
|
||||
}
|
||||
run(v, dontRunHook) {
|
||||
if (!dontRunHook) {
|
||||
this.beforeEachHook();
|
||||
}
|
||||
try {
|
||||
const output = this.predicate(v);
|
||||
return output == null || output === true
|
||||
? null
|
||||
: {
|
||||
error: new Error('Property failed by returning false'),
|
||||
errorMessage: 'Error: Property failed by returning false',
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
if (PreconditionFailure.isFailure(err))
|
||||
return err;
|
||||
if (err instanceof Error && err.stack) {
|
||||
return { error: err, errorMessage: err.stack };
|
||||
}
|
||||
return { error: err, errorMessage: String(err) };
|
||||
}
|
||||
finally {
|
||||
if (!dontRunHook) {
|
||||
this.afterEachHook();
|
||||
}
|
||||
}
|
||||
}
|
||||
beforeEach(hookFunction) {
|
||||
const previousBeforeEachHook = this.beforeEachHook;
|
||||
this.beforeEachHook = () => hookFunction(previousBeforeEachHook);
|
||||
return this;
|
||||
}
|
||||
afterEach(hookFunction) {
|
||||
const previousAfterEachHook = this.afterEachHook;
|
||||
this.afterEachHook = () => hookFunction(previousAfterEachHook);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Property.dummyHook = () => { };
|
||||
16
_node_modules/fast-check/lib/esm/check/property/Property.js
generated
Normal file
16
_node_modules/fast-check/lib/esm/check/property/Property.js
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
import { assertIsArbitrary } from '../arbitrary/definition/Arbitrary.js';
|
||||
import { tuple } from '../../arbitrary/tuple.js';
|
||||
import { Property } from './Property.generic.js';
|
||||
import { AlwaysShrinkableArbitrary } from '../../arbitrary/_internals/AlwaysShrinkableArbitrary.js';
|
||||
import { safeForEach, safeMap, safeSlice } from '../../utils/globals.js';
|
||||
function property(...args) {
|
||||
if (args.length < 2) {
|
||||
throw new Error('property expects at least two parameters');
|
||||
}
|
||||
const arbs = safeSlice(args, 0, args.length - 1);
|
||||
const p = args[args.length - 1];
|
||||
safeForEach(arbs, assertIsArbitrary);
|
||||
const mappedArbs = safeMap(arbs, (arb) => new AlwaysShrinkableArbitrary(arb));
|
||||
return new Property(tuple(...mappedArbs), (t) => p(...t));
|
||||
}
|
||||
export { property };
|
||||
56
_node_modules/fast-check/lib/esm/check/property/SkipAfterProperty.js
generated
Normal file
56
_node_modules/fast-check/lib/esm/check/property/SkipAfterProperty.js
generated
Normal file
@@ -0,0 +1,56 @@
|
||||
import { PreconditionFailure } from '../precondition/PreconditionFailure.js';
|
||||
function interruptAfter(timeMs, setTimeoutSafe, clearTimeoutSafe) {
|
||||
let timeoutHandle = null;
|
||||
const promise = new Promise((resolve) => {
|
||||
timeoutHandle = setTimeoutSafe(() => {
|
||||
const preconditionFailure = new PreconditionFailure(true);
|
||||
resolve(preconditionFailure);
|
||||
}, timeMs);
|
||||
});
|
||||
return {
|
||||
clear: () => clearTimeoutSafe(timeoutHandle),
|
||||
promise,
|
||||
};
|
||||
}
|
||||
export class SkipAfterProperty {
|
||||
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;
|
||||
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
|
||||
this.runBeforeEach = () => this.property.runBeforeEach();
|
||||
this.runAfterEach = () => this.property.runAfterEach();
|
||||
}
|
||||
}
|
||||
isAsync() {
|
||||
return this.property.isAsync();
|
||||
}
|
||||
generate(mrng, runId) {
|
||||
return this.property.generate(mrng, runId);
|
||||
}
|
||||
shrink(value) {
|
||||
return this.property.shrink(value);
|
||||
}
|
||||
run(v, dontRunHook) {
|
||||
const remainingTime = this.skipAfterTime - this.getTime();
|
||||
if (remainingTime <= 0) {
|
||||
const preconditionFailure = new PreconditionFailure(this.interruptExecution);
|
||||
if (this.isAsync()) {
|
||||
return Promise.resolve(preconditionFailure);
|
||||
}
|
||||
else {
|
||||
return preconditionFailure;
|
||||
}
|
||||
}
|
||||
if (this.interruptExecution && this.isAsync()) {
|
||||
const t = interruptAfter(remainingTime, this.setTimeoutSafe, this.clearTimeoutSafe);
|
||||
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]);
|
||||
propRun.then(t.clear, t.clear);
|
||||
return propRun;
|
||||
}
|
||||
return this.property.run(v, dontRunHook);
|
||||
}
|
||||
}
|
||||
43
_node_modules/fast-check/lib/esm/check/property/TimeoutProperty.js
generated
Normal file
43
_node_modules/fast-check/lib/esm/check/property/TimeoutProperty.js
generated
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Error } from '../../utils/globals.js';
|
||||
const timeoutAfter = (timeMs, setTimeoutSafe, clearTimeoutSafe) => {
|
||||
let timeoutHandle = null;
|
||||
const promise = new Promise((resolve) => {
|
||||
timeoutHandle = setTimeoutSafe(() => {
|
||||
resolve({
|
||||
error: new Error(`Property timeout: exceeded limit of ${timeMs} milliseconds`),
|
||||
errorMessage: `Property timeout: exceeded limit of ${timeMs} milliseconds`,
|
||||
});
|
||||
}, timeMs);
|
||||
});
|
||||
return {
|
||||
clear: () => clearTimeoutSafe(timeoutHandle),
|
||||
promise,
|
||||
};
|
||||
};
|
||||
export class TimeoutProperty {
|
||||
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) {
|
||||
this.runBeforeEach = () => Promise.resolve(this.property.runBeforeEach());
|
||||
this.runAfterEach = () => Promise.resolve(this.property.runAfterEach());
|
||||
}
|
||||
}
|
||||
isAsync() {
|
||||
return true;
|
||||
}
|
||||
generate(mrng, runId) {
|
||||
return this.property.generate(mrng, runId);
|
||||
}
|
||||
shrink(value) {
|
||||
return this.property.shrink(value);
|
||||
}
|
||||
async run(v, dontRunHook) {
|
||||
const t = timeoutAfter(this.timeMs, this.setTimeoutSafe, this.clearTimeoutSafe);
|
||||
const propRun = Promise.race([this.property.run(v, dontRunHook), t.promise]);
|
||||
propRun.then(t.clear, t.clear);
|
||||
return propRun;
|
||||
}
|
||||
}
|
||||
21
_node_modules/fast-check/lib/esm/check/property/UnbiasedProperty.js
generated
Normal file
21
_node_modules/fast-check/lib/esm/check/property/UnbiasedProperty.js
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
export class UnbiasedProperty {
|
||||
constructor(property) {
|
||||
this.property = property;
|
||||
if (this.property.runBeforeEach !== undefined && this.property.runAfterEach !== undefined) {
|
||||
this.runBeforeEach = () => this.property.runBeforeEach();
|
||||
this.runAfterEach = () => this.property.runAfterEach();
|
||||
}
|
||||
}
|
||||
isAsync() {
|
||||
return this.property.isAsync();
|
||||
}
|
||||
generate(mrng, _runId) {
|
||||
return this.property.generate(mrng, undefined);
|
||||
}
|
||||
shrink(value) {
|
||||
return this.property.shrink(value);
|
||||
}
|
||||
run(v, dontRunHook) {
|
||||
return this.property.run(v, dontRunHook);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user