Running commands before Jest within configuration

In order to setup my test environment I need to run the following command:

env-cmd ./config/test.env jest --watch --env=node

Within the Jest config panel I see where to add Jest options, but how am I supposed to run env-cmd before jest itself?


You can create a shell script that would run

env-cmd ./config/test.env

command, set it up as external tool in Settings | Tools | External Tools and then add this tool to Before launch section of your Jest run configuration



Thanks Elena!

I did try it, but I get an error message back "Cannot run program "env-cmd" (in directory "~/src/test"): error=2, No such file or directory". This script does work, so I'm clearly messing up the config.

Here is how I config that:


what is "env-cmd"? specify a full path to the executable, seems it's installed locally and thus not added to your $PATH


Yes, that's the correct package! However, I'm not being lucky. If I do specify the full path: "/something/something/app/node_modules/.bin/env-cmd" i get this error: "too few arguments passed...". But if I do pass the path to the config file in the same line, the Program input, then I get the same error as before: "No such file or directory..."


Doesn't work indeed, as it requires a command to run (jest in your case):

Usage: env-cmd [options] [env_file | env_name] command [command options]

it's env-cmd that runs jest in your case... It's a single command, not a commands sequence, that's why it's not possible to run env-cmd before launching jest

I can only suggest specifying your environment vars directly in your run configuration, Environment variables: field


I see. That makes a lot of sense, should have figured out earlier. Thanks for your kind support! I guess I'll follow your suggestion :)



Please sign in to leave a comment.