Skip to content

Instantly share code, notes, and snippets.

@dbrugne
Created June 15, 2017 07:39
Show Gist options
  • Save dbrugne/043d42c61ac40fcbfb675c6ce58bf741 to your computer and use it in GitHub Desktop.
Save dbrugne/043d42c61ac40fcbfb675c6ce58bf741 to your computer and use it in GitHub Desktop.
jscodeshift to replace it() with test() in .spec.js files
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