redux-devtools-test-generator
Advanced tools
Comparing version 0.0.3 to 0.0.4
115
lib/index.js
@@ -5,4 +5,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = require('react'); | ||
@@ -12,2 +10,6 @@ | ||
var _es6template = require('es6template'); | ||
var _es6template2 = _interopRequireDefault(_es6template); | ||
var _reactCodemirror = require('react-codemirror'); | ||
@@ -27,2 +29,8 @@ | ||
var style = { | ||
display: 'flex', | ||
flexFlow: 'column nowrap', | ||
height: 'calc(100% - 3.5em)' | ||
}; | ||
var TestGenerator = function (_Component) { | ||
@@ -51,5 +59,41 @@ _inherits(TestGenerator, _Component); | ||
TestGenerator.prototype.generateTest = function generateTest() { | ||
var _props = this.props; | ||
var computedStates = _props.computedStates; | ||
var actions = _props.actions; | ||
var selectedActionId = _props.selectedActionId; | ||
var startActionId = _props.startActionId; | ||
if (!actions || !computedStates || computedStates.length === 0) return ''; | ||
var _props2 = this.props; | ||
var wrap = _props2.wrap; | ||
var assertion = _props2.assertion; | ||
if (typeof assertion === 'string') assertion = _es6template2.default.compile(assertion); | ||
if (typeof wrap === 'string') wrap = _es6template2.default.compile(wrap); | ||
var r = ''; | ||
var i = void 0; | ||
if (startActionId !== null) i = startActionId;else if (selectedActionId !== null) i = selectedActionId;else i = computedStates.length - 1; | ||
do { | ||
r += assertion({ | ||
action: JSON.stringify(actions[i].action), | ||
prevState: i > 0 ? JSON.stringify(computedStates[i - 1].state) : undefined, | ||
curState: JSON.stringify(computedStates[i].state) | ||
}) + '\n'; | ||
i++; | ||
} while (i <= selectedActionId); | ||
r = r.trim(); | ||
if (wrap) r = wrap({ assertions: r }); | ||
return r; | ||
}; | ||
TestGenerator.prototype.render = function render() { | ||
if (!this.props.expect) { | ||
return this.props.noTestWarning || _react2.default.createElement( | ||
var testComponent = void 0; | ||
if (!this.props.assertion) { | ||
testComponent = this.props.noTestWarning || _react2.default.createElement( | ||
'div', | ||
@@ -59,36 +103,28 @@ { style: { margin: '10px' } }, | ||
); | ||
} else { | ||
var code = this.generateTest(); | ||
if (!this.props.useCodemirror) { | ||
testComponent = _react2.default.createElement('textarea', { | ||
style: { padding: '10px', width: '100%', height: '100%' }, | ||
defaultValue: code | ||
}); | ||
} else { | ||
testComponent = _react2.default.createElement(_reactCodemirror2.default, { | ||
value: code, | ||
options: this.options | ||
}); | ||
} | ||
} | ||
return _react2.default.createElement(_reactCodemirror2.default, { | ||
value: this.generateTest, | ||
options: this.options | ||
}); | ||
var header = this.props.header; | ||
return _react2.default.createElement( | ||
'div', | ||
{ style: style }, | ||
header, | ||
testComponent | ||
); | ||
}; | ||
_createClass(TestGenerator, [{ | ||
key: 'generateTest', | ||
get: function get() { | ||
var _props = this.props; | ||
var computedStates = _props.computedStates; | ||
var actions = _props.actions; | ||
var selectedActionId = _props.selectedActionId; | ||
var startActionId = _props.startActionId; | ||
var wrap = _props.wrap; | ||
var expect = _props.expect; | ||
var r = ''; | ||
var i = void 0; | ||
if (startActionId !== null) i = startActionId;else if (selectedActionId !== null) i = selectedActionId;else i = computedStates.length - 1; | ||
do { | ||
r += expect(JSON.stringify(actions[i].action), i > 0 ? JSON.stringify(computedStates[i - 1].state) : undefined, JSON.stringify(computedStates[i].state)) + '\n'; | ||
i++; | ||
} while (i <= selectedActionId); | ||
r = r.trim(); | ||
if (wrap) r = wrap(r); | ||
return r; | ||
} | ||
}]); | ||
return TestGenerator; | ||
@@ -105,6 +141,13 @@ }(_react.Component); | ||
startActionId: _react.PropTypes.number, | ||
wrap: _react.PropTypes.func, | ||
expect: _react.PropTypes.func, | ||
wrap: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]), | ||
assertion: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]), | ||
useCodemirror: _react.PropTypes.bool, | ||
theme: _react.PropTypes.string, | ||
header: _react.PropTypes.element, | ||
noTestWarning: _react.PropTypes.element | ||
}; | ||
TestGenerator.defaultProps = { | ||
selectedActionId: null, | ||
startActionId: null | ||
}; |
{ | ||
"name": "redux-devtools-test-generator", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Generate tests for redux devtools.", | ||
@@ -13,2 +13,3 @@ "main": "lib/index.js", | ||
"lint": "eslint src test", | ||
"test": "BABEL_ENV=commonjs mocha --compilers js:babel-register --require enzyme/withDom.js --recursive", | ||
"prepublish": "npm run lint && npm run clean && npm run build" | ||
@@ -45,2 +46,3 @@ }, | ||
"babel-preset-stage-0": "^6.5.0", | ||
"enzyme": "^2.3.0", | ||
"eslint": "^2.13.1", | ||
@@ -51,2 +53,6 @@ "eslint-config-airbnb": "^9.0.1", | ||
"eslint-plugin-react": "^5.2.2", | ||
"expect": "^1.20.1", | ||
"mocha": "^2.5.3", | ||
"react-addons-test-utils": "^15.1.0", | ||
"react-dom": "^15.1.0", | ||
"rimraf": "^2.5.2", | ||
@@ -57,2 +63,3 @@ "webpack": "^1.13.1" | ||
"codemirror": "^5.16.0", | ||
"es6template": "^1.0.4", | ||
"react": "^15.1.0", | ||
@@ -59,0 +66,0 @@ "react-codemirror": "^0.2.6" |
@@ -27,5 +27,8 @@ Redux DevTools Test Generator | ||
<Inspector | ||
customTabs={{ | ||
'Test': <TestGenerator expect={mochaTemplate.expect} wrap={mochaTemplate.wrap} /> | ||
}} | ||
customTabs={[ | ||
{ | ||
name: 'Test', | ||
component: <TestGenerator expect={mochaTemplate.expect} wrap={mochaTemplate.wrap} useCodemirror /> | ||
} | ||
]} | ||
/> | ||
@@ -37,3 +40,3 @@ ); | ||
Also include `codemirror/lib/codemirror.css` style and optionally themes from `codemirror/theme/`. | ||
If `useCodemirror` specified, include `codemirror/lib/codemirror.css` style and optionally themes from `codemirror/theme/`. | ||
@@ -44,5 +47,6 @@ ### Props | ||
------------- | ------------- | ||
`expect` | Function with `action`, `prevState`, `curState` arguments, which returns a string representing the assertion ([see the example](https://github.com/zalmoxisus/redux-devtools-test-generator/blob/master/src/redux/mocha.js#L1-L3)). | ||
[`wrap`] | Optional function which gets `expects` argument and returns a string ([see the example](https://github.com/zalmoxisus/redux-devtools-test-generator/blob/master/src/redux/mocha.js#L5-L14)). | ||
[`theme`] | Name of [the codemirror theme](https://codemirror.net/demo/theme.html) as a string. | ||
`assertion` | String template or function with an object argument containing `action`, `prevState`, `curState` keys, which returns a string representing the assertion (see the [function](https://github.com/zalmoxisus/redux-devtools-test-generator/blob/master/src/redux/mocha/index.js#L1-L3) or [template](https://github.com/zalmoxisus/redux-devtools-test-generator/blob/master/src/redux/mocha/template.js#L1)). | ||
[`wrap`] | Optional string template or function which gets `assertions` argument and returns a string (see the example [function](https://github.com/zalmoxisus/redux-devtools-test-generator/blob/master/src/redux/mocha/index.js#L5-L14) or [template](https://github.com/zalmoxisus/redux-devtools-test-generator/blob/master/src/redux/mocha/template.js#L3-L12)). | ||
[`useCodemirror`] | Boolean. If specified will use codemirror styles. | ||
[`theme`] | String. Name of [the codemirror theme](https://codemirror.net/demo/theme.html). | ||
@@ -49,0 +53,0 @@ ### License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12458
9
143
57
4
20
+ Addedes6template@^1.0.4
+ Addedes6-template-regex@0.1.1(transitive)
+ Addedes6template@1.0.5(transitive)
+ Addedextend-shallow@2.0.1(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedsliced@1.0.1(transitive)