Skip to content

Instantly share code, notes, and snippets.

@patocallaghan
Last active July 5, 2018 14:07
Show Gist options
  • Save patocallaghan/d257b63dc3db794330d11d9f9f83e910 to your computer and use it in GitHub Desktop.
Save patocallaghan/d257b63dc3db794330d11d9f9f83e910 to your computer and use it in GitHub Desktop.
/* eslint-env node */
/*
BEFORE
mockFindAll('email-template-data').withParams({ app_id: 'tx2p130c' });
mockFindAll('message-folder')..withParams({ app_id: 'tx2p130c' }).returns({ models: makeList('message-folder', 3) });
AFTER
mockFindAll('email-template-data');
mockFindAll('message-folder').returns({ models: makeList('message-folder', 3) });
*/
export default function(file, api, options) {
let j = api.jscodeshift;
let printOptions = options.printOptions || { quote: 'single' };
let root = j(file.source);
let mockFindAll = {
callee: {
type: "MemberExpression",
object: {
type: 'CallExpression',
callee: {
type: 'Identifier',
name: 'mockFindAll',
},
},
property: {
type: "Identifier",
name: "withParams"
}
},
};
function withoutParams(args) {
return j.callExpression(
j.identifier('mockFindAll'),
args,
);
}
root.find(j.CallExpression, mockFindAll)
.forEach(p => {
console.log();
return p.replace(withoutParams(p.node.callee.object.arguments));
});
return root.toSource(printOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment