Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: implement auto preview on error #87
feat: implement auto preview on error #87
Changes from 13 commits
e09169f
3a17183
40a8176
dbc47ad
b509be5
444c860
7f50e36
5c676b6
776a05c
ccf6880
335e04c
f27b318
5452734
3b2fbdb
26d2186
fe055bf
c7e5168
9a9c5e4
e301c59
e9cb333
132a72f
8c8e095
99031d7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opportunity to improve: We can write a helper function to detect an async function, that will make TypeScript happy and doesn't require type assertion here. I will add an example below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thanhsonng I'm waiting for your example. You can commit directly as well if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it is not easy to achieve. We need to inspect the return value, i.e. we must call the
callback
function first.On the other hand, checking
callback.constructor.name === 'AsyncFunction'
is not enough IMO. We actually want to check if the function return a Promise.So I propose something like this. We always
await
for callback's return value, regardless of its signature, and we makecallbackWithPreview
always return a Promise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate why we need to check if the function return a Promise, instead of checking the function is an async function?
I did try it before this and it works actually (not well tested yet). However, I have a few opening questions I haven’t had answers yet:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An async function is just syntactic sugar for functions that return a promise. Jest allows user to write functions that return a promise without using async/await syntax, so we must account for that case as well. This link is for reference: https://jestjs.io/docs/tutorial-async.
I believe those are non-issues but you shouldn't take my words for it. I will do some research about these questions. 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lemme do a benchmark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thanhsonng I did a benchmark and the running time is very similar. So I will go with
always async
approach.