goldbergyoni / goldbergyoni/nodejs-testing-best-practices

Discussion: environment setting

Open
#66 3 comments 0 reactions 0 assignees View on GitHub
experiment
Dominant language
JavaScript
Stars
4.4k
Forks
288
PR merge metrics
No merged PRs in 30d

Description

As we arrange some tests with:
`process.env.SEND_MAILS = "true";`

We need to clean this value on end but we cannot simply set it to “false” as it might actually originally be “true”.

Instead we might restore the environment back to its initial state after each run:
```
BeforeAll(() => { defaultEnv = process.env …
AfterEach(() => { process.env = defaultEnv ...
```

On the other hand, let’s assume my local env.SEND_MAILS is set to “false”. When I block all external calls in a test - it will pass on my machine. But if the same test is run on another machine, in which env.SEND_MAILS is set to “true”, it will fail.

Should each test declare a SEND_MAILS value in its setup? in contrast to the previous point.

What should be considered as a good practice here? Maybe tests should be aware whether they test a predefined behaviour, in which we set SEND_MAILS in the beginning. Others should test a concrete deployment behaviour - in which we do not change the environment, and if we do, we use the first practice and restore to default.

Your opinion?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.