thunderclient / thunder-client-support

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

Header not recognized on the initial run #1573

Closed esp0314 closed 1 month ago

esp0314 commented 2 months ago

I am in the process of migrating custom scripts using Import JS Files as the feature is deprecated.
image

I have a pre-run script that will execute an api(tc.runRequest) that returns a token and setting up the baseUrl(tc.SetVar) in local environment. And these values will be used as part of authorization headers and baseUrl in our main endpoints. image

image

When executed, it successfully saved the values in the local environment, but it was not recognized those values on the initial run, causing the main api to fail. image

image

image

Successful on the 2nd run image

Another issue i encountered is “File Path not Found” when the request is executed via CLI. Please note that same setup was used here in the command line. image

I have filed a similar issue before and I encountered again using this version: Thunderclient v2.24.12 CLI v1.16.0 https://github.com/thunderclient/thunder-client-support/issues/1496

rangav commented 2 months ago

Thanks @esp0314 for reporting the bug, Will verify and fix it asap.

rangav commented 2 months ago

@esp0314 looks like await keyword is missing when calling imported function.

  1. use this code - await baseUrl();

  2. also await keyword missing for tc.runRequest("reqId");

esp0314 commented 2 months ago

that works, thanks! image

What about the CLI error? Same request and same settings image

rangav commented 2 months ago

CLI Issue could be file path issue.

try below (added / at the start) const { baseUrl } = "/api-tests/test-import.js

esp0314 commented 2 months ago

Hi @rangav,

I tried with your suggestion but It is not working image

image

Using relative path, only UI works not on CLI image

image

Using full absolute path, CLI and UI is working. But i will be running the api collection in the pipeline(CICD) so i cant use the full absulute path image

image

rangav commented 2 months ago

Are you using git-sync feature right?

right click on the test-imports.js file and select copy relative path and use this path

esp0314 commented 2 months ago

Yes i am using git sync feature. I did and got the same result(right click -> copy relative path) image

Only UI is working image

I am using this command line tc --ws api-tests/connectivity test-poc

and this my api tests structure, this might help analyze the issue image

rangav commented 2 months ago

Issue is with --ws argument

remove the argument and try use the workspace relative path setting - Docs

esp0314 commented 2 months ago

That will work @rangav. image

But what if i have multiple collections separated in different folders. This is the reason why i am using --ws. I created a new folder on my POC project added a new api request, run the api and it is not working.

Using --ws image

Please note that --ws argument is very useful for us since we have multiple collections separated in folders and we are running our api tests in cicd pipeline

esp0314 commented 2 months ago

Btw, i am open for a call to further discuss this

esp0314 commented 1 month ago

Hi @rangav, any update regarding the --ws argument? Thank you

rangav commented 1 month ago

Will verify and get back to you

rangav commented 1 month ago

looks like there is a path issue with CLI then using the --ws argument for importing JS files.

Will try to fix it asap. Alternatively, you have to use the workspace relative path vs code setting

rangav commented 1 month ago

We have published a new version of CLI to fix this issue. Please update CLI to v1.16.2.

Right click on the test-imports.js file and select Copy Relative Path

Please test and let me know your feedback.

esp0314 commented 1 month ago

@rangav, thanks for the fixed. It is working now using v1.16.2 image

rangav commented 1 month ago

Thanks for the confirmation