-
Notifications
You must be signed in to change notification settings - Fork 1
fix oneline tests are not parsed #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix oneline tests are not parsed #1
Conversation
After looking at the source for this package, unfortunately it looks like a bunch of regex, which I believe is a suboptimal way to parse source code. Has there been any consideration for an AST-based implementation? |
Hi @TSMMark thanks for being interested in contributing. Well I did this long ago to create documentation in a micro-services stack we were using. By the time I was creating this I looked into jest's internals, see if I could take advantage of any AST parser, though I was unable to spot anything and I figured a RegExp implementation was perfect for my needs. I'm gonna add this known issue to the documentation. Not expecting to solve it soon though as it seems odd to me having a test implementation in one line. Thank you! |
It's not only one line functions, it's also for test functions that have implicit return (no curly braces) |
Yeah @TSMMark I noticed that and added a disclaimer here referencing your examples. The implicit return multiline is fixable though. I think all we need to do is change here the RegExp to something like: export const getCodeBlockPattern = (fnName) => {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{?[\\n](.*?)[\\n]}?\\)`, 'gims')
} And add tests. Maybe for a |
How valuable is it actually to capture the
Because this PR works — it fixes the parsing to handle those cases. It just comes at the sacrifice of the ability to capture of the |
let me re-take a look during the weekend with fresh eyes! |
Thanks for this library! It looks really handy and I'm definitely going to use it for what I'm trying to do.
I noticed it does not notice test functions which are one line. I reproduced the issue by updating the test fixtures with one-line tests to illustrate that the test still passes, even tho the snapshot does not reflect the one-line tests
I haven't even looked at the source code to try to fix this yet, but I will do that next. Any suggestions would be appreciated