Skip to content

Instantly share code, notes, and snippets.

@novemberborn
Last active January 25, 2019 12:22
Show Gist options
  • Save novemberborn/c2cdc94020083a1cafe3f41e8276f983 to your computer and use it in GitHub Desktop.
Save novemberborn/c2cdc94020083a1cafe3f41e8276f983 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