diff --git a/package-lock.json b/package-lock.json index a4ebb97..42d14e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "@ava/typescript": "^3.0.1", "@changesets/cli": "^2.27.7", "@codspeed/tinybench-plugin": "^3.1.1", + "@fast-check/ava": "^2.0.0", "@tsconfig/node12": "^12.1.3", "@types/command-line-usage": "^5.0.4", "@types/minimist": "^1.2.5", @@ -670,6 +671,28 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@fast-check/ava": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@fast-check/ava/-/ava-2.0.0.tgz", + "integrity": "sha512-3AEjylUuIQmtQ9pECxcRopigxSMB0jDuR0MOROQXEAYA+k3u2JphSstQuDapQQVdSJCZAdLT/aKvPgD+vUqMbg==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "dependencies": { + "fast-check": "^3.0.0" + }, + "peerDependencies": { + "ava": "^4 || ^5 || ^6" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -3058,6 +3081,28 @@ "node": ">=0.6.0" } }, + "node_modules/fast-check": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.20.0.tgz", + "integrity": "sha512-pZIjqLpOZgdSLecec4GKC3Zq5702MZ34upMKxojnNVSWA0K64V3pXOBT1Wdsrc3AphLtzRBbsi8bRWF4TUGmUg==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "dependencies": { + "pure-rand": "^6.1.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -5037,6 +5082,22 @@ "node": ">=6" } }, + "node_modules/pure-rand": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.1.0.tgz", + "integrity": "sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ] + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -6846,6 +6907,15 @@ "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", "dev": true }, + "@fast-check/ava": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@fast-check/ava/-/ava-2.0.0.tgz", + "integrity": "sha512-3AEjylUuIQmtQ9pECxcRopigxSMB0jDuR0MOROQXEAYA+k3u2JphSstQuDapQQVdSJCZAdLT/aKvPgD+vUqMbg==", + "dev": true, + "requires": { + "fast-check": "^3.0.0" + } + }, "@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -8555,6 +8625,15 @@ } } }, + "fast-check": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.20.0.tgz", + "integrity": "sha512-pZIjqLpOZgdSLecec4GKC3Zq5702MZ34upMKxojnNVSWA0K64V3pXOBT1Wdsrc3AphLtzRBbsi8bRWF4TUGmUg==", + "dev": true, + "requires": { + "pure-rand": "^6.1.0" + } + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -9972,6 +10051,12 @@ "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "dev": true }, + "pure-rand": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.1.0.tgz", + "integrity": "sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==", + "dev": true + }, "queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", diff --git a/package.json b/package.json index 87ab3b8..708c842 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@ava/typescript": "^3.0.1", "@changesets/cli": "^2.27.7", "@codspeed/tinybench-plugin": "^3.1.1", + "@fast-check/ava": "^2.0.0", "@tsconfig/node12": "^12.1.3", "@types/command-line-usage": "^5.0.4", "@types/minimist": "^1.2.5", diff --git a/src/__tests__/cli/parseArgs.test.ts b/src/__tests__/cli/parseArgs.test.ts index a71b36e..20c2193 100644 --- a/src/__tests__/cli/parseArgs.test.ts +++ b/src/__tests__/cli/parseArgs.test.ts @@ -1,3 +1,4 @@ +import { fc, testProp } from "@fast-check/ava"; import test from "ava"; import { getUsage, parseArgs } from "../../cli/parseArgs.js"; @@ -12,29 +13,46 @@ const macro = test.macro<[string[]]>({ }, }); -test(macro, []); -test(macro, ["--help"]); -test(macro, ["-h"]); -test(macro, ["--tasks"]); -test(macro, ["--tasks", "true"]); -test(macro, ["--tasks=true"]); -test(macro, ["--tasks", "TRUE"]); -test(macro, ["--tasks", "yes"]); -test(macro, ["--tasks", "1"]); -test(macro, ["--tasks", "false"]); -test(macro, ["--tasks=false"]); -test(macro, ["--tasks", "FALSE"]); -test(macro, ["--tasks", "0"]); -test(macro, ["-T"]); -test(macro, ["-T", "true"]); -test(macro, ["-T", "false"]); -test(macro, ["--tasks-simple"]); -test(macro, ["--tasks-simple", "true"]); -test(macro, ["build", "test", "--light=false"]); -test(macro, ["build", "test", "--", "--light=false"]); -test(macro, ["build", "test", "--", "not-a-task", "--light=false"]); -test(macro, ["--herebyfile", "path/to/Herebyfile.js", "build", "test", "--light=false"]); -test(macro, ["--herebyfile", "path/to/Herebyfile.js", "build", "test", "--light=false", "not-a-task"]); +const argvTests = [ + [], + ["--help"], + ["-h"], + ["--tasks"], + ["--tasks", "true"], + ["--tasks=true"], + ["--tasks", "TRUE"], + ["--tasks", "yes"], + ["--tasks", "1"], + ["--tasks", "false"], + ["--tasks=false"], + ["--tasks", "FALSE"], + ["--tasks", "0"], + ["-T"], + ["-T", "true"], + ["-T", "false"], + ["--tasks-simple"], + ["--tasks-simple", "true"], + ["build", "test", "--light=false"], + ["build", "test", "--", "--light=false"], + ["build", "test", "--", "not-a-task", "--light=false"], + ["--herebyfile", "path/to/Herebyfile.js", "build", "test", "--light=false"], + ["--herebyfile", "path/to/Herebyfile.js", "build", "test", "--light=false", "not-a-task"], +]; + +for (const argv of argvTests) { + test(macro, argv); +} + +testProp( + "fast-check", + [fc.array(fc.string())], + (t, argv) => { + t.true(typeof parseArgs(argv) === "object"); + }, + { + examples: argvTests.map((v) => [v]), + }, +); test.serial("usage", (t) => { t.snapshot(getUsage().replace(/\r/g, ""));