I have a NodeJS app. For a long time I've been using Mocha to run tests. I simply had a package.json like
"dev": "node index --env=dev",
"start": "node index",
"test": "mocha './test/**/*.spec' --env=dev"
Now I am switching to Jest for a variety of reasons, and the test script becomes simply
"test":"jest"
Within my test suites, I spin up an instance of my app. In functions throughout my app there are decisions based on the environment. Simplified example:
const ProcessArgs = require("minimist")(process.argv);
export function uploadImage(image){
if(ProcessArgs.env === "dev"){
return writeToLocalTestFolder(image);
}
else {
return uploadToCloud(image);
}
}
So this used to look at the --env=dev
arg, but that's no longer there. (If I try to add --env=dev
to Jest, well that's an entirely different issue). I do in fact properly use Heroku's secrets for my actual important env variables like API keys, etc, but I now seem to be stuck here on how I should tell Jest what env it is in, since it needs env=node
to work properly.