UNPKG

@fast-check/vitest

Version:

Property based testing for Vitest based on fast-check

28 lines (27 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildTestWithPropRunner = buildTestWithPropRunner; const fast_check_1 = require("fast-check"); function wrapProp(prop) { return (...args) => Promise.resolve(prop(...args)); } function buildTestWithPropRunner(testFn, label, arbitraries, prop, params, timeout, fc) { const customParams = { ...params }; if (customParams.seed === undefined) { const seedFromGlobals = (0, fast_check_1.readConfigureGlobal)().seed; if (seedFromGlobals !== undefined) { customParams.seed = seedFromGlobals; } else { customParams.seed = Date.now() ^ (Math.random() * 0x100000000); } } if (customParams.interruptAfterTimeLimit === undefined) { customParams.interruptAfterTimeLimit = fc.readConfigureGlobal().interruptAfterTimeLimit; } const promiseProp = wrapProp(prop); const propertyInstance = fc.asyncProperty(...arbitraries, promiseProp); testFn(`${label} (with seed=${customParams.seed})`, async () => { await fc.assert(propertyInstance, customParams); }, timeout); }