1

I am trying to set up a Node Express server with some basic routes and I have some unit tests to run against them. But when I try to run the tests I get the following error.

'NODE_ENV' is not recognized as an internal or external command,

operable program or batch file.

The npm scripts for the same are

"test": "NODE_ENV=testing jest --forceExit --detectOpenHandles  --silent",
"test-routes": "npm run test -t router",

I am on a Windows machine, using Visual Studio Code with its integrated terminal pointing to Git-Bash.

I thought since I am using git-bash, NODE_ENV=testing should work automatically. But it doesn't.

When I change the script to

"test": "SET NODE_ENV=testing jest --forceExit --detectOpenHandles  --silent",

the error goes away but tests are not running.

$ yarn test-routes
yarn run v1.17.3
$ npm run test -t router

> api-design-v3@1.0.0 test D:\learning_workspace\api-design-node-v3
> set NODE_ENV=testing jest --detectOpenHandles "router"

Done in 1.70s.
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
C V
  • 209
  • 1
  • 3
  • 13
  • 1
    That's not how you set env vars inline on Windows; I'd suggest using https://www.npmjs.com/package/cross-env. Also note you need `--` to pass extra arguments when you use npm run; you can see in the last output that `-t` didn't make it through. – jonrsharpe Sep 16 '19 at 06:57
  • What @jonrsharpe said was true, you can also try https://www.npmjs.com/package/dotenv – Sami Shames El-Deen Sep 16 '19 at 07:30

0 Answers0