Skip to content
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

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

Open
oopchi opened this issue May 27, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@oopchi
Copy link

oopchi commented May 27, 2024

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:

  • OS: Windows 11
  • vscode version: v1.89.1
  • node version: v20.8.0
  • extension version: v2.23.9

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

@oopchi oopchi added the bug Something isn't working label May 27, 2024
@rangav
Copy link
Collaborator

rangav commented May 27, 2024

@oopchi

This is expected behavior.

  • Pre-Scripts are run before the Pre-Requests.

@oopchi
Copy link
Author

oopchi commented May 27, 2024

@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
Copy link
Author

oopchi commented May 27, 2024

To summarize my point:

  • Pre-Scripts are run before the Pre-Requests. (true only for the parent request)
  • Pre-Requests are run before the Pre-Scripts. (true only for all recursively pre-requests)

Current workaround that I've found to work:

  • Choose the request that is supposed to be the main request as a sole pre-request of an empty new request, this will make pre-scripts and pre-requests of all recursive pre-requests works the same (Pre-Requests are run before the Pre-Scripts), making it possible to dynamically change the value of the request body of the main request using the side-effects from pre-sequent requests through environment variables.

@rangav
Copy link
Collaborator

rangav commented May 27, 2024

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
Copy link
Author

oopchi commented May 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants