Last active
July 5, 2018 14:07
-
-
Save patocallaghan/d257b63dc3db794330d11d9f9f83e910 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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