# Condition for differentiating testing with a helper node

**URL:** <https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366>\
**Category:** Developing Nodes\
**Created:** [8 November 2021 10:23 UTC](https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366 "2021-11-08T10:23:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![midhun](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@midhun](https://discourse.nodered.org/u/midhun)\
**Post date:** [8 November 2021 10:23 UTC](https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366/1 "2021-11-08T10:23:04Z")

</div>

How can we differentiate the normal usage and testing, at runtime based on some condition?  
Something similar to :

`if (process.env.NODE_ENV === 'test') {`

So that we can prevent some initialization which may cause error while testing using **npm run test**.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [9 November 2021 21:59 UTC](https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366/2 "2021-11-09T21:59:33Z")

</div>

Why not use that?

I sometimes add other tests at least temporarily, often to a small function that wraps console so that I can carry on dumping a gazillion log statements without worrying whether I left some in when I published the code 🙂

---

<div class="post-metadata">

**Author:** ![midhun](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@midhun](https://discourse.nodered.org/u/midhun)\
**Post date:** [10 November 2021 13:01 UTC](https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366/3 "2021-11-10T13:01:34Z")

</div>

Thank you for the response. I have used it. But I thought there would some difference when we start a test with helper node.

Seems it is a dumb question. 😆

btw, could you please show me an example on what you have told about the temporary tests? That will be really helpful.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 November 2021 13:06 UTC](https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366/4 "2021-11-10T13:06:51Z")

</div>

I have this dirty code in one of my helper libraries:

```auto
const mylog = (process.env.TI_ENV === 'debug') ? console.log : function() {}

```

and this:

```auto
    /** Dump process memory use to console
     * @param {string} prefix Text to output before the memory info
     */
    dumpMem: (prefix) => {
        let mem = process.memoryUsage()
        const formatMem = (m) => ( m/1048576 ).toFixed(2)
        mylog(`${prefix} Memory Use (MB): RSS=${formatMem(mem.rss)}. Heap: Used=${formatMem(mem.heapUsed)}, Tot=${formatMem(mem.heapTotal)}. Ext C++=${formatMem(mem.external)}`)
    },

```

So I can use those in my code without much worry. I've occasionally used an IP address check as well during development of editor or front-end code such that running on localhost (e.g. my development environment) outputs copious information but running from the server doesn't. Lets me do UAT type tests without the noise.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 November 2021 13:07 UTC](https://discourse.nodered.org/t/condition-for-differentiating-testing-with-a-helper-node/53366/5 "2021-11-24T13:07:02Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
