James Braund
02/22/2023, 10:10 AMafterEach hook.
1. The documentation for the lifecycle seems to be incomplete, as it doesn't mention when the State Handler Teardown step runs. After some trial and error, I believe the following is correct:
BeforeEach -> State Handler Setup -> Request Filter (request phase) -> Execute Provider Test -> Request Filter (response phase) -> AfterEach -> State Handler Teardown
Is this right? Happy to get a PR open to update the docs if this is correct.
2. Are there any constraints around the afterEach hook, such as maximum execution time? In the afterEach hook for our tests, I'm resetting some of the data in our test database, as per one of the use cases described for it in the docs. However, it seems that my afterEach hook does not always finish executing. I've littered it with logging debug statements and try/catch statements to find out exactly where it gets to, and there are no errors being thrown - the logging statements sometimes just stop. What might I be missing?
Any help is appreciated! Thanks in advance šTimothy Jones
02/22/2023, 10:14 AMTimothy Jones
02/22/2023, 10:21 AMafterEach, so ā¦.possibly we havenāt noticed).Timothy Jones
02/22/2023, 10:21 AMTimothy Jones
02/22/2023, 10:21 AMTimothy Jones
02/22/2023, 10:22 AM. However, it seems that my afterEach hook does not always finish executing. Iāve littered it with logging debug statements and try/catch statements to find out exactly where it gets to, and there are no errors being thrown - the logging statements sometimes just stop. What might I be missing?Right. Yes, thereās a bug.
Timothy Jones
02/22/2023, 10:22 AMJames Braund
02/22/2023, 10:25 AMawait?", but didn't see an obvious cause. Again, happy to contribute. Do you have an idea of what the cause is already, or do you need anything else from me to help reproduce?Timothy Jones
02/22/2023, 10:30 AMpact-core).
2) The rust core expects to call setup and teardown hooks on an endpoint running on your provider, but this is clumsy for most users in JS land
2) But, pact-js doesnāt āknowā when the setup and teardown hooks happen.
4) To get around this (and to allow a DSL where you can provide native JS setup and teardown hooks), pact-js runs a proxy server (built with express) that proxies the app that youāre verifying. It catches the request to the setup hook, swallows it, and calls the user provided hook.Timothy Jones
02/22/2023, 10:30 AMTimothy Jones
02/22/2023, 10:31 AMnext more than once
2) Call next and return a promise (or have an async function, which is like returning a promise)Timothy Jones
02/22/2023, 10:32 AMJames Braund
02/22/2023, 10:32 AMTimothy Jones
02/22/2023, 10:32 AMTimothy Jones
02/22/2023, 10:33 AMbeforeEach and afterEach (or similarly named states) should be special states in pact that always happenTimothy Jones
02/22/2023, 10:35 AMTimothy Jones
02/22/2023, 10:35 AMTimothy Jones
02/22/2023, 10:36 AMTimothy Jones
02/22/2023, 10:36 AMTimothy Jones
02/22/2023, 10:36 AMJames Braund
02/22/2023, 10:37 AMnext() to trigger subsequent middleware is happening before the call to the afterEach hook.
Good shout on the "do teardown" state. I'll give that a go as an immediate workaround to unblock me, and then if I get chance, I will have a play about with the middleware execution order.Timothy Jones
02/22/2023, 10:37 AMTimothy Jones
02/22/2023, 10:37 AMasync function that also has a nextTimothy Jones
02/22/2023, 10:38 AMnext first, so that the request would do its thing, then do the teardownTimothy Jones
02/22/2023, 10:38 AMafterEach is only called when the proxy returns.Timothy Jones
02/22/2023, 10:39 AMJames Braund
02/22/2023, 10:39 AMTimothy Jones
02/22/2023, 10:39 AMTimothy Jones
02/22/2023, 10:39 AMTimothy Jones
02/22/2023, 10:39 AMTimothy Jones
02/22/2023, 10:40 AMTimothy Jones
02/22/2023, 10:41 AMexpress or the http-proxy docs (or both)James Braund
02/22/2023, 10:42 AMTimothy Jones
02/22/2023, 10:43 AMTimothy Jones
02/22/2023, 10:43 AMJames Braund
02/22/2023, 10:43 AMTimothy Jones
02/22/2023, 10:44 AMTimothy Jones
02/22/2023, 10:44 AMTimothy Jones
02/22/2023, 10:48 AMTimothy Jones
02/22/2023, 10:53 AMafterEach and it will work. However, itās not quite ready for use yet.Timothy Jones
02/22/2023, 10:53 AMJames Braund
02/22/2023, 10:54 AMTimothy Jones
02/22/2023, 10:56 AMTimothy Jones
02/22/2023, 10:57 AMclearEverything() at the top of each setup state handler. That might be faster, but would fail if youāre using more than one state for the same interaction.Timothy Jones
02/22/2023, 10:58 AMJames Braund
02/22/2023, 10:58 AMgiven(...) in the consumer tests.James Braund
02/22/2023, 10:59 AMTimothy Jones
02/22/2023, 10:59 AMJames Braund
02/22/2023, 10:59 AMTimothy Jones
02/22/2023, 11:00 AM