Friday, 5 May 2017

Environment variables not found during Mocha unit test Node.js

I am trying to run a mocha unit test but one of the modules used by the module I am testing on requires environment variables such as process.env.CLIENT_ID through dotenv. When I run my Mocha test, these environment variables are not found. How can I can include environment variables from a .env file in my mocha unit tests?

test.js:

    var messenger = require(__dirname + "/../routes/messenger.js");
var assert = require("assert") 


describe("Return Hello", function(){
    it('Should return hello',function(done){
        messenger.testFunction(function(value){
            assert(value === "Hello", 'Should return Hello')
            done()
        })
    })
})

Section of file that contains the problem that goes through unit test:

    var express = require("express")
var router = express.Router();

require('dotenv').config()

var plaid = require('plaid');
var mysql = require('mysql');

var fs = require("fs");


const plaidClient = new plaid.Client(
    process.env.PLAID_CLIENT_ID, // these are all not found
    process.env.PLAID_SECRET,
    process.env.PLAID_PUBLIC_KEY,
    plaid.environments.sandbox);



via user1851782

No comments:

Post a Comment