Skip to content

Instantly share code, notes, and snippets.

@umaar
Forked from novemberborn/README.md
Created January 25, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

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