0

Ava test runner in my project has its own env variables defined like this in package.json:

"ava": {
        "require": [
            "esm"
        ],
        "files": [
            "test/unit/**/**/ava-*"
        ],
        "environmentVariables": {
            "SERVER_DEFAULT_TIMEZONE": "Australia/Sydney",
            "PAY_MAX": "false",
            "NODE_ENV": "development"
        },
        "timeout": "20s"
    },

Now when doing a unit test for a certain file it happens that I need to cover this line in the function that I'm testing:

const isPayMax = process.env.PAY_MAX === "true";

So I'm trying to make that condition true so I can cover in my test. However, no matter I tried setting it to "true" or any other value, it still keep the value defined in package.json.

I've also tried using rewire module but it doesn't seem to work as well.

Also tried setting manually the environment variable in my test file like this process.env.PAY_MAX = "true" but no luck as well.

Any thoughts on how to deal with this? Thanks.

quielfala
  • 361
  • 4
  • 18

0 Answers0