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(test): Add "name", "origin" and "parent" to "Deno.TestContext" #14007
feat(test): Add "name", "origin" and "parent" to "Deno.TestContext" #14007
Changes from 11 commits
2045266
5f0684d
d53f267
4071f36
5b6eb6b
3f7d86c
7e057cd
09dc034
3d243b9
e59a330
cf83e4e
2b81511
222fc0e
0b35c20
99b7d8c
95892ba
59c97f8
07c8e65
ba1c18f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Considering that
import.meta.url
is astring
, I think it makes sense for this to be a string as well.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.
Do we need to consider that
test.teardown
might be called multiple times? This could lead to some very unexpected and hard to debug behaviour with the current implementation.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.
I think we need to consider that case. Is there any good idea for handling that?
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.
how about this? push
teardownFn
and call sequentially after the test.but I'm not sure this is good about the order of calls.
To handle the order problem, we can take another approach.
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.
This is a good point!
I think the second example you gave could be improved in the following ways:
teardown
function to know what the order is.teardown
function or calls it twiceThe issue is that each test has a degree of control over the order of
teardown
calls, essentially democratising the order. This approach probably makes problem#1
unsolvable.How important is it that developers have control over the order of calls? We can still go with your first suggestion and if fine grained control over the order is important, then it will be possible to implement a custom solution:
However, I believe that in 99% of cases this problem would be solved by Deno exposing the following functions in the test context:
These would work similarly to the Jest Setup and Teardown functions and allow for a decent level of control over the order while still being easy to understand.
To summarise, I propose the following:
test.beforeAll - [NOT IN THIS PR] execute a function before any child steps are executed
test.afterAll - [NOT IN THIS PR] execute a function after any child steps are executed
test.beforeEach - [NOT IN THIS PR] execute a function before each child steps is executed
test.afterEach - [NOT IN THIS PR] execute a function after each child steps is executed
test.teardown - [THIS PR] execute a function after the top level parent test has finished executing and all descendant test steps have finished executing
What do you think @hyp3rflow?
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.
Thanks for the kind review!
Yeah, I think it will be okay with my first suggestion in most cases. I was just worried about if there are many third-party libraries using teardown in an order-sensitive way.
I also agree that it will be awesome with APIs like jest setup-teardown functions. but I think we need to hear the maintainers' thoughts about this kind of API.
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.
Definitely agree! And this should not be part of this PR either way. I just mentioned it here as it would address the ordering issue you flagged.
I am not aware of any but it's a valid point.
I agree! Better to keep it simple :D
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.
@bcheidemann I have a question.
What does
top level parent test
means? A single deno test (Deno.test()) or single test module (a.test.ts)?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.
I was thinking a single
Deno.test()
but what do you think is better?For our case (
assertSnapshot
) it probably makes more sense for it to be a single test module (a.test.ts
) but I think generally it makes more sense for this to relate to a singleDeno.test()
instance.