Skip to content

Instantly share code, notes, and snippets.

@JavierGelatti
Created January 17, 2020 23:30
Show Gist options
  • Save JavierGelatti/29c378b2a2beb6222ed0c734d20db957 to your computer and use it in GitHub Desktop.
Save JavierGelatti/29c378b2a2beb6222ed0c734d20db957 to your computer and use it in GitHub Desktop.
Codemod madness
module.exports = (fileInfo, api) => {
const j = api.jscodeshift;
return j(fileInfo.source)
.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'assert',
},
property: { name: 'that' },
},
}
)
.replaceWith(cosa => j.callExpression(j.identifier('expect'), cosa.value.arguments))
.toSource();
};
module.exports = (fileInfo, api) => {
const j = api.jscodeshift;
return j(fileInfo.source)
.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'assert',
},
property: { name: 'isTrue' },
},
}
)
.replaceWith(cosa =>
j.callExpression(
{
type: 'MemberExpression',
object: j.callExpression(j.identifier('expect'), cosa.value.arguments),
property: 'toEqual'
},
[ j.identifier('true') ]
)
)
.toSource();
};
module.exports = (fileInfo, api) => {
const j = api.jscodeshift;
return j(fileInfo.source)
.find(j.Identifier, { name: 'suite' })
.replaceWith(cosa => {
cosa.value.name = "describe"
return cosa.value
})
.toSource();
};
module.exports = (fileInfo, api) => {
const j = api.jscodeshift;
return j(fileInfo.source)
.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
property: { name: 'isEqualTo' },
},
}
)
.replaceWith(cosa => {
cosa.value.callee.property.name = "toEqual"
return cosa.value
})
.toSource();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment