thunderclient / thunder-client-support

Thunder Client is a lightweight Rest API Client Extension for VS Code.
https://www.thunderclient.com
Other
3.59k stars 128 forks source link

Incorrect execution order of main request pre-run script when pre-request request(s) are specified #1551

Open oopchi opened 1 month ago

oopchi commented 1 month ago

Describe the bug When a request contains BOTH pre-run script and pre-request requests, the pre-run script of the main (first) request would always be executed first and only then would the pre-request request(s) be executed in the order of their subsequent pre-request requests > pre-run scripts (hence the order of execution of their subsequent pre-run and pre-requests are reversed from the main request).

I think this is a bug because I don't think this is the intended behavior(?)

Because of this issue, it renders users unable to reuse the response from pre-requests using env in the main request because the main request's pre-run script would always be the first one executed before anything else (except collection level scripts).

By the way this also affects the collection-level pre-run scripts. It runs in the correct order only after the main (first) request.

To Reproduce

  1. Create 3 requests, A, B, and C
  2. Request A contains 1 pre-request (request B) and 1 pre-run scripts (just console.log something to track the order of execution).
  3. Request B contains 1 pre-request (request C) and 1 pre-run scripts (just console.log something)
  4. Request C contains 1 pre-run scripts (just console.log something)
  5. Run Request A
  6. console.log from pre-run script request A would appear first
  7. console.log from pre-run script request C would then appear
  8. Request C would then be executed
  9. console.log from pre-run script request B would then appear
  10. Request B would then be executed
  11. Request A would then be executed

Expected behavior

  1. Create 3 requests, A, B, and C
  2. Request A contains 1 pre-request (request B) and 1 pre-run scripts (just console.log something to track the order of execution).
  3. Request B contains 1 pre-request (request C) and 1 pre-run scripts (just console.log something)
  4. Request C contains 1 pre-run scripts (just console.log something)
  5. Run Request A
  6. console.log from pre-run script request C would then appear
  7. Request C would then be executed
  8. console.log from pre-run script request B would then appear
  9. Request B would then be executed
  10. console.log from pre-run script request A would appear first
  11. Request A would then be executed

Platform:

Are you using the free version/paid version/trial: free

rangav commented 1 month ago

@oopchi

This is expected behavior.

oopchi commented 1 month ago

@rangav But currently that's only true for the first request from my observation, look at this tests I've run for example:

image

Above is the main request and it has 1 pre-request (account_sms_login_v22/success) and 1 pre-run script (print logs).

image

Second picture is the pre-request of the first picture and it also has 1 pre-request (request_auth_code/success_register) and 1 pre-run script (print logs).

From the Script Log in the first picture, you can see that the pre-run script runs first (you said this is expected), however if you look below it (still in the first picture), it's "request_auth_code/success_register" that gets executed first before the print logs from the "account_sms_login_v22/success" inside it's pre-run script that gets executed (pre-request of the first pre-request gets executed first before pre-run script of the first pre-request).

Is this still the expected behavior?

oopchi commented 1 month ago

To summarize my point:

Current workaround that I've found to work:

rangav commented 1 month ago

FYI - Request chaining will be a paid feature also from June 3rd. https://github.com/thunderclient/thunder-client-support/releases/tag/v2.24.0

Can you confirm you have read the release notes?

oopchi commented 1 month ago

Okay noted, thank you for the information, however is it still free if I'm only using the version before that?