Skip to content

Commit

Permalink
test: add fuzz testing (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox authored Oct 13, 2023
1 parent 7d49e7f commit 9abddb5
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/fuzz.test.js
Original file line number Diff line number Diff line change
@@ -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 },
);

0 comments on commit 9abddb5

Please sign in to comment.