-
Notifications
You must be signed in to change notification settings - Fork 124
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(allure-cypress): missing tests and fixtures when an error occurs in a hook #1123
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Use Cypress types instead of Mocha's universally - Extend Cypress types to change types of references - Remove unused CypressHook.id and isGlobalHook - Rename completeSpecIfNoAfterHooksRemain -> completeSpecIfNoAfterHookLeft - Factor out some logic from index.ts - Add a type for non-callback hook implementation fn
Pass hook info (scope type and position) via the message instead.
delatrie
force-pushed
the
issue1072-cypress-failed-hooks
branch
from
August 28, 2024 04:40
c507b1b
to
016c4f5
Compare
delatrie
force-pushed
the
issue1072-cypress-failed-hooks
branch
from
August 28, 2024 05:15
016c4f5
to
b6a48b6
Compare
baev
approved these changes
Aug 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The changes
Reporting of failed hooks
If a hook fails, Mocha won't emit the
hook end
event. That caused the corresponding fixture to hang in the state until the process finishes instead of being written on disk.Now, we're detecting those cases, and issuing the
cypress_hook_end
message in the Mocha'sfail
event if it corresponds to a hook error.Note
Spec-level after hooks are handled differently. See below.
Reporting of spec-level failed after hooks
In beta 10 we support spec-level
after
hooks by patching theafter
function to introduce two hooks instead of one. The first hook is the original user-defined one, while the second, the Allure-specific one, is responsible for flushing the messages of the original hook to Node.js.That works just fine until the user-defined hook fails. In that case, Mocha skips its Allure-specific counterpart, which essentially precludes the hook from being reported.
With this PR, the mechanism is changed. Now, instead of inserting extra hooks, we wrap the original hook implementation function. The wrapper calls the original hook implementation, then:
after
hook; if it fails, other such hooks will be skipped making the failed hook the last piece of user-defined code being executed and the last place capable of calling a Cypress task).after
hook in the spec file.All three types of functions are supported:
after(() => { /* ... */ });
after(async () => { /* ... */ });
after((done) => { /* the code must eventually call done */ });
That technique also works better with
cypress open
. Previously we tried to complete the spec in Mocha'send
event, which, TBH, never worked in the first place.With
cypress run
we still rely on Cypress'esafter:spec
event because it allows us to attach the video.Reporting of tests skipped because of a failed hook
If a hook fails, Mocha skips the remaining tests from the suite where the hook has been defined. This PR includes them (except those not in the test plan, if any) in the report with the status that depends on the failed hook type:
before
hooks.beforeEach
andafterEach
hooks.Note
There are no skipped tests in case of a failed
after
hook.Fixes #1072
Open issues
There is a problem with failed after-fixture visibility. See #1122 for more details.
Other minor changes
Checklist