zod-fast-check
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -134,3 +134,6 @@ "use strict"; | ||
maxLength = 2 * minLength + 10; | ||
const unfiltered = fast_check_1.default.string(minLength, maxLength); | ||
const unfiltered = fast_check_1.default.string({ | ||
minLength, | ||
maxLength, | ||
}); | ||
if (hasRegexCheck) { | ||
@@ -161,6 +164,13 @@ return filterArbitraryBySchema(unfiltered, schema, path); | ||
if (isInt) { | ||
return fast_check_1.default.integer(min, max); | ||
return fast_check_1.default.integer({ min, max }); | ||
} | ||
else { | ||
return fast_check_1.default.double(min, max); | ||
return fast_check_1.default.double({ | ||
min, | ||
max, | ||
// fast-check 3 considers NaN to be a Number by default, | ||
// but Zod does not consider NaN to be a Number | ||
// see https://github.com/dubzzz/fast-check/blob/main/packages/fast-check/MIGRATION_2.X_TO_3.X.md#new-floating-point-arbitraries- | ||
noNaN: true, | ||
}); | ||
} | ||
@@ -187,3 +197,6 @@ }, | ||
const maxLength = Math.min((_d = (_c = schema._def.maxLength) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 10, 10); | ||
return fast_check_1.default.array(recurse(schema._def.type, path + "[*]"), minLength, maxLength); | ||
return fast_check_1.default.array(recurse(schema._def.type, path + "[*]"), { | ||
minLength, | ||
maxLength, | ||
}); | ||
}, | ||
@@ -204,3 +217,3 @@ ZodObject(schema, path, recurse) { | ||
ZodTuple(schema, path, recurse) { | ||
return fast_check_1.default.genericTuple(schema._def.items.map((item, index) => recurse(item, `${path}[${index}]`))); | ||
return fast_check_1.default.tuple(...schema._def.items.map((item, index) => recurse(item, `${path}[${index}]`))); | ||
}, | ||
@@ -217,6 +230,9 @@ ZodRecord(schema, path, recurse) { | ||
var _a, _b, _c, _d; | ||
const minSize = (_b = (_a = schema._def.minSize) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0; | ||
const maxSize = Math.min((_d = (_c = schema._def.maxSize) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 10, 10); | ||
const minLength = (_b = (_a = schema._def.minSize) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0; | ||
const maxLength = Math.min((_d = (_c = schema._def.maxSize) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 10, 10); | ||
return fast_check_1.default | ||
.set(recurse(schema._def.valueType, path + ".(value)"), minSize, maxSize) | ||
.uniqueArray(recurse(schema._def.valueType, path + ".(value)"), { | ||
minLength, | ||
maxLength, | ||
}) | ||
.map((members) => new Set(members)); | ||
@@ -293,3 +309,3 @@ }, | ||
return recurse(schema.unwrap(), path); | ||
} | ||
}, | ||
}; | ||
@@ -296,0 +312,0 @@ class ZodFastCheckError extends Error { |
{ | ||
"name": "zod-fast-check", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Generate fast-check arbitraries from Zod schemas.", | ||
@@ -9,3 +9,3 @@ "main": "dist/zod-fast-check.js", | ||
"build": "tsc", | ||
"test": "jest", | ||
"test": "prettier --check src && jest", | ||
"prepare": "npm run build", | ||
@@ -41,3 +41,3 @@ "prepublishOnly": "npm test", | ||
"@types/jest": "^28.1.6", | ||
"fast-check": "^2.24.0", | ||
"fast-check": "^3.0.0", | ||
"jest": "^26.6.3", | ||
@@ -50,5 +50,5 @@ "prettier": "^2.2.1", | ||
"peerDependencies": { | ||
"fast-check": "^2.0.0", | ||
"fast-check": "^2.23.0", | ||
"zod": "^3.18.0" | ||
} | ||
} |
21744
395