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

[bug]: Hoppscotch cli doesn't load environment variables #2855

Closed
1 task done
Blackhart opened this issue Nov 16, 2022 · 9 comments
Closed
1 task done

[bug]: Hoppscotch cli doesn't load environment variables #2855

Blackhart opened this issue Nov 16, 2022 · 9 comments
Labels
bug Something isn't working cli Related to Hoppscotch CLI need testing Needs to be tested before merging onto production

Comments

@Blackhart
Copy link

Blackhart commented Nov 16, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Given an exported environment with a "baseUrl" variable in
When I run:
hopp test -e environment.json tests.json
The variable "baseUrl" is not substitued in my tests.

I expect the variable "baseUrl" to be substitued

Steps to reproduce

  1. Open hopscotch
  2. Open the environment panel
  3. Create a new environment
  4. Add 'baseUrl" as a variable of that environment
  5. Create a rest request with 'baseUrl" in it
  6. Export the environment and the test in json format
  7. Install hopp-cli with npm i -g @hoppscotch/cli
  8. Run them with hopp cli

Environment

Release

Version

Local

@Blackhart Blackhart added bug Something isn't working need testing Needs to be tested before merging onto production labels Nov 16, 2022
@Blackhart
Copy link
Author

Blackhart commented Nov 16, 2022

Here is an export of the environment and the tests:

env_and_test_export.zip

Here is the output when calling hopp:

output

@aitchnyu
Copy link
Contributor

aitchnyu commented Dec 5, 2022

The env file format that would be accepted looks like this. Expected format is different from Hoppscotch export format.

{
  "baseurl": "http://postman-echo.com"
}

A file of a different format would parse as a blank env. Sorry about the surprising behavior. We are fixing the code to throw an error and looking at the docs.

This issue will be closed when env file is either loaded correctly or user is informed that the file is malformed.

@aitchnyu
Copy link
Contributor

aitchnyu commented Dec 5, 2022

Updating docs at hoppscotch/docs#96

@praveenpuglia
Copy link

I feel like the cli should interactively ask for which environment I wanna run the collection with as well in case there are multiple of them. Also the format should be up-to-date with the exported format. People primarily use the GUI and then if they have to run everything in a collection together, they use the CLI. for this they export the environment variables form the GUI itself that they would have already made.

Proposal

hopp test -e env-staging.json --env-name staging collection.json

The env-name arg can then be used to pick one of the environments to work with.

Also, there's this bit of code

 if (!(contents && typeof contents === "object" && !Array.isArray(contents))) {
    throw error({ code: "MALFORMED_ENV_FILE", path, data: null });
  }
  const envPairs = [];
  for (const [key, value] of Object.entries(contents)) {
    if (typeof value !== "string") {
      throw error({ code: "MALFORMED_ENV_FILE", path, data: { value } });
    }
    envPairs.push({ key, value });
  }

This should be modified to work with the new data format of GUI.

@cjchand
Copy link

cjchand commented Aug 7, 2023

Reiterating @praveenpuglia's point above that the CLI should support the export format from the GUI. Why would these be different? Wouldn't the GUI be the normal place people craft Collections and Environments together?

While it might seem small when viewed in isolation, this is one of a series of friction points that are driving me away from considering Hoppscotch as a Postman replacement (see also: #3248).

That said, I am very appreciative of all the hard work on this project. It's because I see the promise that I'm providing the feedback. Thanks for the attention.

@liyasthomas liyasthomas added the cli Related to Hoppscotch CLI label Aug 27, 2023
@nids2307
Copy link

nids2307 commented Sep 8, 2023

Any further updates on this ticket. I am in the same boat as cjchand to make a decision considering Hoppscotch as a potential replacement to Postman.

@JamesSFL
Copy link

So here is what happened with me. I had baseurl for the test endpoint set in global and rest of the variables were in development env. Since hoppscotch supports only one env file with cli, I copied the baseurl variable and pasted in development.json env file at the end of the variables array. Now when I run the the cli with this setup, the test cases failed as it wasn't able to read the baseurl which is at the bottom of the variable array. Now when I moved it to the top, all test cases passed. Is this an expected behaviour? Also cli is not able to set value for apikey in authorization as header from variable in environment file.

@jamesgeorge007
Copy link
Member

Hi, Hoppscotch CLI now supports specifying an environment export file via the --env, -e flag. It doesn't support the bulk environments export format. Please find more information here.

So here is what happened with me. I had baseurl for the test endpoint set in global and rest of the variables were in development env. Since hoppscotch supports only one env file with cli, I copied the baseurl variable and pasted in development.json env file at the end of the variables array. Now when I run the the cli with this setup, the test cases failed as it wasn't able to read the baseurl which is at the bottom of the variable array. Now when I moved it to the top, all test cases passed. Is this an expected behaviour? Also cli is not able to set value for apikey in authorization as header from variable in environment file.

@JamesSFL, can you try with the latest version of the CLI? If the issue persists, can you share a sample collection and environment export file to reproduce it?

@JoelJacobStephen
Copy link
Contributor

JoelJacobStephen commented Apr 18, 2024

@Blackhart @JamesSFL I hope the suggestion helped. I will be closing this issue. If you are still facing this issue on the latest builds, please feel free to reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to Hoppscotch CLI need testing Needs to be tested before merging onto production
Projects
None yet
Development

No branches or pull requests

9 participants