Identification of confidential information in mocha tests

I run mocha tests from below script

"test:server": "mocha test/server/  --compilers js:babel-core/register --require ./test/server/init_db.js  --recursive",

init_dbhas variables such as a local database connection string. Since this is sensitive, I would like the connection string to be restored as an environment variable.

I decided to install it this way

"test:server": " DATABASE_URL = "*****" mocha test/server/  --compilers js:babel-core/register --require ./test/server/init_db.js  --recursive"

But this will not solve the problem, since everyone can see the connection string from package.json. For my development, I use dotenvand have a file .envfrom which node reads the connection string and sets it to process.env.DATABASE_URL. but this does not work for mocha, because it is impossible to read the specified file .env.

Is there any other way to set confidential information without putting init_dbin mine .gitignore?

+4
1

, .env mocha,

require('dotenv').config();

0

Source: https://habr.com/ru/post/1651081/


All Articles