diff --git a/package-lock.json b/package-lock.json index 0dacfa3..1042ec4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.1", "license": "MIT", "devDependencies": { + "@fast-check/ava": "^1.1.6", "@insurgentlab/conventional-changelog-preset": "7.0.0", "@semantic-release/changelog": "6.0.3", "@semantic-release/git": "10.0.1", @@ -251,6 +252,28 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@fast-check/ava": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@fast-check/ava/-/ava-1.1.6.tgz", + "integrity": "sha512-xshsWNumcefyXFyfxREFcz/mrOay3ITRJh8My7bpEPK3YEJ7Rg/QHExVCUMRqeMjxj5ChQz6ngZxNCnxkOWq+w==", + "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.0.0" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.11", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz", @@ -4744,6 +4767,28 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "node_modules/fast-check": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.13.1.tgz", + "integrity": "sha512-Xp00tFuWd83i8rbG/4wU54qU+yINjQha7bXH2N4ARNTkyOimzHtUBJ5+htpdXk7RMaCOD/j2jxSjEt9u9ZPNeQ==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "dependencies": { + "pure-rand": "^6.0.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", @@ -11068,6 +11113,22 @@ "node": ">=6" } }, + "node_modules/pure-rand": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.0.4.tgz", + "integrity": "sha512-LA0Y9kxMYv47GIPJy6MI84fqTd2HmYZI83W/kM/SkKfDlajnZYfmXFTxkbY+xSBPkLJxltMa9hIkmdc29eguMA==", + "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", diff --git a/package.json b/package.json index 8255051..8af406d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,11 @@ "node": ">=16.20" }, "scripts": { - "test": "c8 ava && tsd --files tests/**/*.test-d.ts", + "test": "c8 npm run test:all", + "test:all": "npm run test:ava && npm run test:fuzz && npm run test:tsd", + "test:ava": "ava tests/e2e.test.js", + "test:fuzz": "NODE_OPTIONS=--no-warnings ava tests/fuzz.test.js", + "test:tsd": "tsd --files tests/**/*.test-d.ts", "lint": "xo", "lint:fix": "xo --fix" }, @@ -37,6 +41,7 @@ "path" ], "devDependencies": { + "@fast-check/ava": "^1.1.6", "@insurgentlab/conventional-changelog-preset": "7.0.0", "@semantic-release/changelog": "6.0.3", "@semantic-release/git": "10.0.1", diff --git a/tests/test.js b/tests/e2e.test.js similarity index 100% rename from tests/test.js rename to tests/e2e.test.js diff --git a/tests/fuzz.test.js b/tests/fuzz.test.js new file mode 100644 index 0000000..51b5007 --- /dev/null +++ b/tests/fuzz.test.js @@ -0,0 +1,27 @@ +// Hack while waiting for https://github.com/ossf/scorecard/issues/3567 to be resolved +// eslint-disable-next-line no-unused-vars, import/order +import _fc from 'fast-check'; + +import { fc, testProp } from '@fast-check/ava'; +import importFrom from '../index.js'; + +testProp( + 'should return loaded module and not error unexpectedly', [fc.string(), fc.string()], async (t, a, b) => { + t.timeout(60_000); + let result; + + try { + const loaded = await importFrom(a, b); + result = Boolean(loaded); + // If (result) { + // console.debug('successfully loaded', a, ' | ', b); + // console.debug(loaded); + // } + } catch (error) { + result = error.code === 'MODULE_NOT_FOUND'; + } + + t.true(result); + }, + { numRuns: 100_000 }, +);