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.
If you provide the code for the node, someone might be able to look at it and help you out.
The test file is located at node-red-nodes/test/parsers/base64/70-base64_spec.js at master · node-red/node-red-nodes · GitHub
Normally, if you have installed dev dependencies, you can run 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 (in parsers/base85
) if somebody wants to take a look.
There is a problem with your regex:
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.
Because it's NR so errors are reported in the log
const logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "base85";
});
Where do I put that? helper.log()
returns undefined
when I add this to my testcase.
e.g.
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();
});
});
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?
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.
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.
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.