-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
afterEach does not support async operation #1241
Comments
Related to #1068 which discusses the premature execution of |
Thanks for the helpful repro @lhokktyn, I'd be open to a PR to fix this. The problem might be in https://github.com/pact-foundation/pact-js/blob/1a3815ef456dc7e608a02e3cc2b267cac8b1f8ca/src/dsl/verifier/proxy/hooks.ts, but would need further investigation. |
I'm not a maintainer any more, but I'm pretty sure the problem is:
should be:
|
Also that |
Currently a asynchronous afterEach hook will execute concurrently with the underlying express request lifecycle. This fix allows async hooks to complete before allowing the express request to continue through its middleware stack. Fixes pact-foundation#1241
Software versions
Please provide at least OS and version of pact-js
Issue Checklist
Please confirm the following:
Expected behaviour
When defining an async function for
afterEach
, it should pause further execution of the verification tests until that Promise has resolved.We require async behaviour for clearing up state in
afterEach
as part of our verification tests.Actual behaviour
Test execution is not paused, and Promise is not handled cleanly.
Steps to reproduce
npm i -DE @pact-foundation/pact@latest
)provider.spec.js
to configure the provider verifier as so:./node_modules/.bin/jest provider.spec.js
)Given this
afterEach
hook, I would expect test execution to pause for ~2 seconds, but it doesn't and jest does not exit cleanly, giving the warning:Note the timestamps either side of the
executing 'afterEach' hook
log indicate execution on this thread is no paused ...Note that
beforeEach
does appear to support async operation. Here are the equivalent logs when replacingafterEach
withbeforeEach
in the above snippet, which show a ~2 second gap between logs:The text was updated successfully, but these errors were encountered: