# Debugging help wanted

**URL:** https://discourse.nodered.org/t/debugging-help-wanted/93104
**Category:** Developing Nodes
**Created:** [12 November 2024 20:28 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104 "2024-11-12T20:28:00Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![MatthiasU](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matthiasu/32/63073_2.png) [@MatthiasU](https://discourse.nodered.org/u/MatthiasU)
#### Post date: [12 November 2024 20:28 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/1 "2024-11-12T20:28:01Z")

</div>

Hello,  
so I am copying the existing base64 node (to add base85).

My problem is that the tests I hacked together fail and I have no idea about the how to use NodeJS tooling, specifically

- how do I ask grunt to run a single test script only?
- I get an error `Fatal error: Cannot read properties of null (reading 'emit')`. How do I figure out which line this occurs on, or the stacktrace, or …?

FYI I'm a command line type of person.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [12 November 2024 20:35 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/2 "2024-11-12T20:35:45Z")

</div>

If you provide the code for the node, someone might be able to look at it and help you out.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [12 November 2024 20:46 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/3 "2024-11-12T20:46:50Z")

</div>

The test file is located at [node-red-nodes/test/parsers/base64/70-base64\_spec.js at master · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/blob/master/test/parsers/base64/70-base64_spec.js)

Normally, if you have installed dev dependencies, you can run `npx mocha path-to-test-file`

---

<div class="post-metadata">

### Author: ![MatthiasU](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matthiasu/32/63073_2.png) [@MatthiasU](https://discourse.nodered.org/u/MatthiasU)
#### Post date: [12 November 2024 21:28 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/4 "2024-11-12T21:28:37Z")

</div>

> [@GogoVega](#):
>
> `npx mocha path-to-test-file`

That helped (somewhat). Seems that a test node with `"type":"base85"` doesn't work and returns `null` for some reason.

My code is [here](https://github.com/smurfix/node-red-nodes/tree/test) (in `parsers/base85`) if somebody wants to take a look.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [13 November 2024 09:06 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/5 "2024-11-13T09:06:33Z")

</div>

There is a problem with your regex:

 ![Capture d’écran 2024-11-13 à 10.06.09](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/547871c41cb9cd35b5fe06a68f07eef9f27b7ed9.png)

---

<div class="post-metadata">

### Author: ![MatthiasU](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matthiasu/32/63073_2.png) [@MatthiasU](https://discourse.nodered.org/u/MatthiasU)
#### Post date: [13 November 2024 12:00 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/6 "2024-11-13T12:00:53Z")

</div>

Yeah. I found that now, after an hour of single stepping.

May I ask how to get `npx mocha -b test/parsers/base85/70-base85_spec.js`to actually _show_ this error? It seems somewhat inconceivable to me that a test system should be allowed to suppress such messages, but apparently that's why I don't usually code in Node/JS.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [13 November 2024 12:09 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/7 "2024-11-13T12:09:14Z")

</div>

Because it's NR so errors are reported in the log

```js
const logEvents = helper.log().args.filter(function (evt) {
  return evt[0].type == "base85";
});

```

---

<div class="post-metadata">

### Author: ![MatthiasU](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matthiasu/32/63073_2.png) [@MatthiasU](https://discourse.nodered.org/u/MatthiasU)
#### Post date: [13 November 2024 12:20 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/8 "2024-11-13T12:20:15Z")

</div>

Where do I put that? `helper.log()` returns `undefined` when I add this to my testcase.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [13 November 2024 12:22 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/9 "2024-11-13T12:22:22Z")

</div>

e.g.

```js
it("should be loaded with correct defaults", function(done) {
        var flow = [{"id":"n1", "type":"base85", "name":"base851", "wires":[[]]}];
        helper.load(testNode, flow, function() {
            const logEvents = helper.log().args.filter(function (evt) {
                return evt[0].type == "base85";
            });
            var n1 = helper.getNode("n1");
            n1.should.have.property("name", "base851");
            n1.should.have.property("charset", "btoa");
            done();
        });
    });

```

---

<div class="post-metadata">

### Author: ![MatthiasU](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matthiasu/32/63073_2.png) [@MatthiasU](https://discourse.nodered.org/u/MatthiasU)
#### Post date: [13 November 2024 12:26 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/10 "2024-11-13T12:26:28Z")

</div>

Unfortunately that's not helpful, because when I put it there it executes after the code that's actually failing.

Isn't there an option to just print the unfiltered log to stderr or something?

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [13 November 2024 12:30 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/11 "2024-11-13T12:30:10Z")

</div>

I don't know 😕

If you want to test your code, start NR you will have the errors directly. Then modify your test unit files.

---

<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: [13 November 2024 13:49 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/12 "2024-11-13T13:49:35Z")

</div>

> [@MatthiasU](#):
>
> Isn't there an option to just print the unfiltered log to stderr or something?

Depends how you start Node-RED. If you start it manually, the log will be right there on the terminal. Better still though, run it with the node.js debugger - or use the debugger node. Put a breakpoint into the settings.js and you should be able to see everything happening in real-time. You also get the benefit of seeing the log in a browser dev-tools view which is much nicer to work with.

---

<div class="post-metadata">

### Author: ![MatthiasU](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matthiasu/32/63073_2.png) [@MatthiasU](https://discourse.nodered.org/u/MatthiasU)
#### Post date: [13 November 2024 16:22 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/13 "2024-11-13T16:22:01Z")

</div>

I don't plan to start a Node-RED server at all at this point. This is the test suite of the `node-red-nodes` package.

In any case the problem appears to be that NR doesn't propagate errors from flows to the runtime, which is good, except that it also does this when unit testing, which is bad. I'm preparing a pull request to fix this.

---

<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: [11 February 2025 16:22 UTC](https://discourse.nodered.org/t/debugging-help-wanted/93104/14 "2025-02-11T16:22:28Z")

</div>

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