1

I am trying to use Wallaby in conjunction with the dotenv-flow package. I currently have my wallaby.js config file setup like below:

require("dotenv-flow").config()
module.exports = function (wallaby) {
  return {
    files: [
      'api/*',
      'controllers/*',
      'config/*',
      'firebase/*',
      'helpers/*',
      'models/*',
      'services/*',
      'smtp/*',
      'sockets/*'
    ],

    tests: [
      "test/**/*.test.mjs"
    ],

    testFramework: "mocha",

    env: {
      type: "node",
      params: {
        env: "NODE_ENV=test"
      }
    }
  };
};

I've tried a few other ways of writing the file including in esm module format. However, my tests run and my sequelize code complains that it wasn't passed environment variables to use for connecting to the development DB.

jps_dot_dev
  • 65
  • 1
  • 13

1 Answers1

0

You are loading your .env file but then never using it's contents. Another problem is that wallaby doesn't understand the dotenv output so you have to massage it a little bit.

const environment = Object.entries(
             require("dotenv-flow").config()['parsed']).
             map( x =>  `${x[0]}=${x[1]}`).join(';'),

Then change your environment to something like this

env: {
  runner: 'node',
  params: {
     env: environment
  }
}
Vlad
  • 9,180
  • 5
  • 48
  • 67