Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fuzzy-testing

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzy-testing - npm Package Compare versions

Comparing version 0.0.1 to 0.0.4

build/examples/exampleAdd.js

82

build/index.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.fuzzFunction = undefined;
exports.fuzzReactComponent = exports.fuzzFunction = undefined;

@@ -153,3 +153,79 @@ var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

// eslint-disable-next-line
exports.fuzzFunction = fuzzFunction;
/**
*
* fuzzReactComponent
*
* fuzzReactComponent takes a function and an object of options and fuzzes the component.
* It returns the results of the fuzz in an array.
*
* options:
* returnTypes: can be an array of types represented by strings, or a function that validates.
* returnFirstError: boolean that does short circuit evaluation if true.
* argumentValues: an array of values that will be tested.
* iterations: the number of times that a function will be run per argument combination.
* canThrowError: whether or not the function can throw an error or not.
*
* @param Component
* @param options
* @returns {Array}
*/
function fuzzReactComponent(Component, options) {
// Ensure that component is a react component
(0, _assert2.default)(Component.prototype && Component.prototype.isReactComponent || typeof Component === 'function', 'Component is not a React Component');
// Process options
options = (0, _assign2.default)({
returnFirstError: true,
iterations: 3,
argumentValues: [],
canThrowError: false,
returnTypes: ['string']
}, options);
// Process props and generate values
if (!Component.propTypes) {
// Component has no props, no need to fuzz.
return [];
}
var randomProps = (0, _utils.objectMap)(Component.propTypes, _utils.propTypesMap);
// An array for keeping track of errors
var errors = [];
// Run the fuzzer on the function multiple times.
for (var iteration = 0; iteration < options.iterations; iteration += 1) {
var randomPropsInst = (0, _utils.objectMap)(randomProps, function (prop) {
return prop();
});
// eslint-disable-next-line no-unused-vars
var comp = new Component(randomPropsInst);
try {
// If returnTypes is an array, look for the type inside the array.
if (Array.isArray(options.returnTypes) && options.returnTypes.indexOf((0, _typeof3.default)(comp.render())) < 0) {
errors.push('arguments ' + randomPropsInst + ' did not return one of ' + options.returnTypes);
if (options.returnFirstError) {
return errors;
}
}
// If returnTypes is a function, execute the validation function on the result.
if (typeof options.returnTypes === 'function' && !options.returnTypes(comp.render())) {
errors.push('arguments ' + randomPropsInst + ' did not satisfy ' + options.returnTypes);
if (options.returnFirstError) {
return errors;
}
}
} catch (e) {
if (!options.canThrowError) {
errors.push('arguments ' + randomPropsInst + ' threw error ' + e);
if (options.returnFirstError) {
return errors;
}
}
}
}
return [];
}
exports.fuzzFunction = fuzzFunction;
exports.fuzzReactComponent = fuzzReactComponent;

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -6,3 +6,10 @@ Object.defineProperty(exports, "__esModule", {

});
exports.combineMultipleLengths = exports.combineMultiple = exports.combineToArray = exports.combine = undefined;
var _assert = require('assert');
var _assert2 = _interopRequireDefault(_assert);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -17,2 +24,6 @@ *

function combine(a, b) {
// ensure that arrays were given
(0, _assert2.default)(Array.isArray(a), 'a is not an array.');
(0, _assert2.default)(Array.isArray(b), 'b is not an array.');
var superSet = [];

@@ -37,2 +48,9 @@ a.forEach(function (aElem) {

function combineToArray(a, b) {
// ensure that arrays were given
(0, _assert2.default)(Array.isArray(a), 'a is not an array.');
(0, _assert2.default)(Array.isArray(b), 'b is not an array.');
a.map(function (item) {
return (0, _assert2.default)(Array.isArray(item), 'item in a is not an array.');
});
var superSet = [];

@@ -56,2 +74,6 @@ a.forEach(function (aElem) {

function combineMultiple(a, end) {
// ensure that valid values were given
(0, _assert2.default)(Array.isArray(a), 'a is not an array.');
(0, _assert2.default)(typeof end === 'number', 'end is not an number.');
var collector = [[]];

@@ -74,4 +96,10 @@ for (var i = 0; i < end; i += 1) {

function combineMultipleLengths(a, end, start) {
// ensure that valid values were given
start = start || 0;
(0, _assert2.default)(Array.isArray(a), 'a is not an array.');
(0, _assert2.default)(typeof end === 'number', 'end is not an number.');
(0, _assert2.default)(typeof start === 'number' || !start, 'start is not an number.');
(0, _assert2.default)(end >= start, 'start is greater than end.');
var collector = [[[]]];
start = start || 0;
if (start > 0) {

@@ -78,0 +106,0 @@ collector = [combineMultiple(a, start)];

@@ -34,2 +34,11 @@ 'use strict';

var _objectUtils = require('./objectUtils');
Object.defineProperty(exports, 'objectMap', {
enumerable: true,
get: function get() {
return _objectUtils.objectMap;
}
});
var _typeUtils = require('./typeUtils');

@@ -48,2 +57,8 @@

}
});
Object.defineProperty(exports, 'propTypesMap', {
enumerable: true,
get: function get() {
return _typeUtils.propTypesMap;
}
});

@@ -6,3 +6,3 @@ 'use strict';

});
exports.primitiveTypesMap = exports.typesMap = undefined;
exports.propTypesMap = exports.primitiveTypesMap = exports.typesMap = undefined;

@@ -17,2 +17,6 @@ var _maxSafeInteger = require('babel-runtime/core-js/number/max-safe-integer');

var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _badStrings = require('./strings/badStrings');

@@ -33,2 +37,3 @@

// A map of types to functions that will generate random values of said type.
// eslint-disable-next-line import/no-extraneous-dependencies
var typesMap = {

@@ -44,3 +49,4 @@ boolean: randomBool,

function: randomFunc
}; // Import the list of bad strings
};
// Import the list of bad strings

@@ -50,3 +56,3 @@

string: randomString,
bool: randomBool,
boolean: randomBool,
number: randomNumber,

@@ -158,3 +164,17 @@ int: randomInt,

function propTypesMap(type) {
switch (type) {
case _propTypes2.default.string:
return typesMap.string;
case _propTypes2.default.number:
return typesMap.number;
case _propTypes2.default.shape:
return {};
default:
return typesMap.undefined;
}
}
exports.typesMap = typesMap;
exports.primitiveTypesMap = primitiveTypesMap;
exports.primitiveTypesMap = primitiveTypesMap;
exports.propTypesMap = propTypesMap;

13

package.json
{
"name": "fuzzy-testing",
"version": "0.0.1",
"version": "0.0.4",
"description": "Javascript fuzz testing tools",

@@ -41,6 +41,11 @@ "main": "build/index.js",

"enzyme": "^2.8.2",
"eslint": "^3.12.2",
"eslint-config-kyt": "^0.0.1",
"jest": "^20.0.1"
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.0.1",
"eslint-plugin-react": "^7.1.0",
"jest": "^20.0.1",
"prop-types": "^15.5.10",
"react": "^15.6.1"
}
}

@@ -1,4 +0,48 @@

# Fuzzy
# Fuzzy-Testing
[![CircleCI](https://circleci.com/gh/dkaoster/Fuzzy.svg?style=svg&circle-token=9dd14dcc291ae8308cd25102f95815ad69ce29de)](https://circleci.com/gh/dkaoster/Fuzzy)
Fuzz testing tools for node.
Because javascript is a loosely typed language, it is difficult to prepare for all the different possible types that a function might receive. In order to better build stable javascript applications, fuzzy-testing is a tool that will try many possible combinations of data types within arguments.
To install to your local project, simply run:
```
npm install fuzzy-testing
```
then, call one of the fuzzFunctions from within your testing code. If you're using jest, you can do something like this:
```js
import { fuzzFunction } from 'fuzzy-testing';
expect(fuzzFunction(onlyBools, { maxArgs: 1 })).toEqual([]);
```
## fuzzFunction
`fuzzFunction` is a function that takes a function and an object specifying it's options.
#### options
- returnTypes: can be an array of types represented by strings, or a function that validates.
- returnFirstError: boolean that does short circuit evaluation if true.
- maxArgs: the maximum number of arguments to send to the function.
- minArgs: the minimum number of arguments to send to the function.
- argumentTypes: an array of argument types.
- argumentValues: an array of values that will be tested.
- iterations: the number of times that a function will be run per argument combination.
- canThrowError: whether or not the function can throw an error or not.
## fuzzReactComponent
Fuzzy testing also allows you to fuzz the render method of react component via `fuzzReactComponent`.
#### options
- returnTypes: can be an array of types represented by strings, or a function that validates.
- returnFirstError: boolean that does short circuit evaluation if true.
- argumentValues: an array of values that will be tested.
- iterations: the number of times that a function will be run per argument combination.
- canThrowError: whether or not the function can throw an error or not.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc