Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AVA throwsAsync transform for jscodeshift

Usage:

$ npx jscodeshift -t https://gist.githubusercontent.com/novemberborn/c2cdc94020083a1cafe3f41e8276f983/raw/eaa64c55dfcda8006fc760054055372bb3109d1c/transform.js test.js

See https://github.com/facebook/jscodeshift#usage-cli for further details.

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
You can’t perform that action at this time.