Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.

Simplify beforeAll handling. #117

Merged
merged 3 commits into from
Jun 17, 2020
Merged

Simplify beforeAll handling. #117

merged 3 commits into from
Jun 17, 2020

Conversation

MagiMaster
Copy link
Collaborator

Make beforeAll run at the beginning of the block rather than waiting to run it on the first it block encountered. This is simpler, and also consistent with how afterAll works. This is also necessary for adding the context object as now beforeAll will run in the correct context.

This change makes it so that a beforeAll will run even if there are no it blocks to apply it to. It also means that the beforeAll block is no longer tied to a specific it block to report failures through. Instead, it now creates a dummy report node to contain any failures. As a side benefit, the afterAll block can use this same mechanism and report failures now.

Comment on lines 160 to 165
for _, hook in pairs(lifecycleHooks:getAfterAllHooks()) do
runCallback(hook, "afterAll hook: ")
-- errors in an afterAll hook are currently not caught
-- or attributed to a set of child nodes
local success, errorMessage = runCallback(hook, "afterAll hook: ")
if not success then
session:addDummyError("afterAll", errorMessage)
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want to run afterAll when there were errors in beforeAll? Is this behavior we should pin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still run it, since its point is to do cleanup, and you often still need that even if beforeAll failed. However, it deserves some consideration before committing to that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we should keep this. I can't find any documentation on how jest handles this specific case, but I can easily imagine when you'd want this behavior (set up 3 things, but the last fails, you still need to clean up the other two), but I can't think of any reason not to have it.

We should also document the behavior that a failing beforeAll will stop any further code in that block except for the *All blocks at that specific level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like we have any in-depth documentation to add this to at the moment. I'll file that as a separate issue.

@LPGhatguy LPGhatguy merged commit 6fde1cf into Roblox:master Jun 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants