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
Comments
Here is an export of the environment and the tests: Here is the output when calling hopp: |
The env file format that would be accepted looks like this. Expected format is different from Hoppscotch export format.
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. |
Updating docs at hoppscotch/docs#96 |
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 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. |
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. |
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. |
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. |
Hi, Hoppscotch CLI now supports specifying an environment export file via the
@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? |
@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. |
Is there an existing issue for this?
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
npm i -g @hoppscotch/cli
Environment
Release
Version
Local
The text was updated successfully, but these errors were encountered: