Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function generate({ type, newPath, newValue, newIndex }) {
let curState;
let path = fromPath(newPath);
if (type === 'remove-item' || type === 'move-item') {
if (paths.length && paths.indexOf(path) !== -1) return;
paths.push(path);
const v = objectPath.get(s2.state, newPath);
curState = v.length;
path += '.length';
} else if (type === 'add-item') {
generate({ type: 'move-item', newPath });
path += `[${newIndex}]`;
curState = stringify(newValue);
} else {
curState = stringify(newValue);
}
// console.log(`expect(store${path}).toEqual(${curState});`);
cb({ path, curState });
}
function generate({ type, newPath, newValue, newIndex }) {
let curState;
let path = fromPath(newPath);
if (type === 'remove-item' || type === 'move-item') {
if (paths.length && paths.indexOf(path) !== -1) return;
paths.push(path);
const v = objectPath.get(s2.state, newPath);
curState = v.length;
path += '.length';
} else if (type === 'add-item') {
generate({ type: 'move-item', newPath });
path += `[${newIndex}]`;
curState = stringify(newValue);
} else {
curState = stringify(newValue);
}
// console.log(`expect(store${path}).toEqual(${curState});`);
cb({ path, curState });
}
function generate({ type, newPath, newValue, newIndex }) {
let curState;
let path = fromPath(newPath);
if (type === 'remove-item' || type === 'move-item') {
if (paths.length && paths.indexOf(path) !== -1) return;
paths.push(path);
const v = objectPath.get(s2.state, newPath);
curState = v.length;
path += '.length';
} else if (type === 'add-item') {
generate({ type: 'move-item', newPath });
path += `[${newIndex}]`;
curState = stringify(newValue);
} else {
curState = stringify(newValue);
}
// console.log(`expect(store${path}).toEqual(${curState});`);
cb({ path, curState });
}
entryExtension = 'tsx';
} else {
entryExtension = 'ts';
}
}
let entry = `./src/index.${entryExtension}`;
if (isHotReact) {
entry = [
'react-hot-loader/patch', // activate HMR for React
`./src/index.${entryExtension}`,
];
}
const baseWebpackTsSupport = _.assignIn(baseWebpack, { entry });
const base = configType === 'webpack' ? baseWebpackTsSupport : {};
return jsStringify(
_.reduce(
configItems,
(acc, currentValue) =>
features[currentValue][configType](acc, configItems),
base
),
stringifyReplacer,
2
);
}
color="light"
underlined
title={showSpaces(unquote(prop.defaultValue.value))}
>
Function
);
} else if (propName === 'shape' || propName === 'object') {
try {
// We eval source code to be able to format the defaultProp here. This
// can be considered safe, as it is the source code that is evaled,
// which is from a known source and safe by default
// eslint-disable-next-line no-eval
const object = eval(`(${prop.defaultValue.value})`);
return (
);
} catch (e) {
// eval will throw if it contains a reference to a property not in the
// local scope. To avoid any breakage we fall back to rendering the
// prop without any formatting
return (
);
}
}
}
const startIdx = i > 0 ? i : 1;
const addAssertions = ({ path, curState }) => {
r += space + assertion({ path, curState }) + '\n';
};
while (actions[i]) {
if (!isVanilla || /^┗?\s?[a-zA-Z0-9_@.\[\]-]+?$/.test(actions[i].action.type)) {
if (isFirst) isFirst = false;
else r += space;
if (!isVanilla || actions[i].action.type[0] !== '@') {
r += dispatcher({
action: !isVanilla ?
this.getAction(actions[i].action) :
this.getMethod(actions[i].action),
prevState: i > 0 ? stringify(computedStates[i - 1].state) : undefined
}) + '\n';
}
if (!isVanilla) {
addAssertions({ path: '', curState: stringify(computedStates[i].state) });
} else {
compare(computedStates[i - 1], computedStates[i], addAssertions, isVanilla && {});
}
}
i++;
if (i > selectedActionId) break;
}
r = r.trim();
if (wrap) {
if (!isVanilla) r = wrap({ name, assertions: r });
else {
}
}
i++;
if (i > selectedActionId) break;
}
r = r.trim();
if (wrap) {
if (!isVanilla) r = wrap({ name, assertions: r });
else {
r = wrap({
name: /^[a-zA-Z0-9_-]+?$/.test(name) ? name : 'Store',
actionName: (selectedActionId === null || selectedActionId > 0) && actions[startIdx] ?
actions[startIdx].action.type.replace(/[^a-zA-Z0-9_-]+/, '') :
'should return the initial state',
initialState: stringify(computedStates[startIdx - 1].state),
assertions: r
});
}
}
return r;
}
getAction(action) {
if (action.type === '@@INIT') return '{}';
return stringify(action);
}
getAction(action) {
if (action.type === '@@INIT') return '{}';
return stringify(action);
}