Created
June 15, 2017 07:39
-
-
Save dbrugne/043d42c61ac40fcbfb675c6ce58bf741 to your computer and use it in GitHub Desktop.
jscodeshift to replace it() with test() in .spec.js files
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
import { parse } from 'path'; | |
/** | |
* Search it() calls and replace with test() in .spec.js files | |
* | |
* Run with: jscodeshift -t itToTestTransform.js lib | |
*/ | |
module.exports = function (file, api) { | |
const j = api.jscodeshift; | |
const { name } = parse(file.path); | |
if (!name.match(/\.spec$/)) { | |
return; | |
} | |
return j(file.source) | |
.find(j.CallExpression, { callee: { name: 'it' } }) | |
.forEach((path) => { | |
path.node.callee.name = 'test'; | |
return node; | |
}) | |
.toSource(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment