Skip to content

Instantly share code, notes, and snippets.

@umaar
Forked from novemberborn/README.md
Created January 25, 2019 12:22
Show Gist options
  • Save umaar/ac473adff4f3d8846b7f51e22f3b6c15 to your computer and use it in GitHub Desktop.
Save umaar/ac473adff4f3d8846b7f51e22f3b6c15 to your computer and use it in GitHub Desktop.
AVA throwsAsync transform for jscodeshift
module.exports = (fileInfo, {jscodeshift: j}) => {
const ast = j(fileInfo.source)
ast.find(j.CallExpression, {
callee: {
object: {name: 't'},
property: {name: 'throws'}
}
}).filter(p => p.parentPath.value.type === 'AwaitExpression')
.forEach(p => {
p.get('callee').get('property').replace(j.identifier('throwsAsync'))
})
ast.find(j.CallExpression, {
callee: {
object: {name: 't'},
property: {name: 'notThrows'}
}
}).filter(p => p.parentPath.value.type === 'AwaitExpression')
.forEach(p => {
p.get('callee').get('property').replace(j.identifier('notThrowsAsync'))
})
return ast.toSource()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment