Seeing the node-red logs when running node-red-node-test-helper

As I build out a new set of contributed node implementations for Node-RED, I find myself using node-red-node-test-helper for the first time. I'm enjoying the function and all is well for the most part. I am gaining skills on the framework.

In one of my tests, I am invoking a flow and it is not working as expected. I feel that my flow and its corresponding custom node are being invoked but I get the feeling that my own code in my own node may be throwing an exception. This leads me to the question to be posed in this thread:

Is it possible to dump/log the messages generated by the execution of the flow that is invoked by node-red-node-test-helper?

In my test code I have:

const flow = [
  {
    "id": "n1",
    "type": "google-cloud-pubsub out",
    //"topic": "node-red-topic",
    "keyFilename": "/home/kolban/node-red/creds.json",
  }
];
helper.load(pubsubInNode, flow, () => {
  // At this point the flow is "running".  We now need to send in some data.
  const n1 = helper.getNode("n1");

  console.log('About to fire flow');
  n1.receive({payload: text});
  ...

When I call helper.load(), my supposition is that an instance of Node-RED (or some core of it) is loaded and the flow passed to it. If I were running Node-RED from the command line, I would be able to look at its logs. Is it possible to see the logs of Node-RED itself when launched from helper.load()?

1 Like

Soft bump ... I'm quite a fan of the node-red-node-test-helper framework but could really use some technique to see the underlying Node-RED logs when the framework runs flows.

You may need to bump it again on Wednesday when I'm back from holiday and can dig out the code to remember how to do this.

Bumping this as I am wondering the same thing :slight_smile:
Many thanks in advance.

1 Like

So what I found out was this

helper.load([scannerNode, statusBrokerNode], flow, function () {
  console.table(helper.log().args.map(e=>e[0]))
  console.log('Current Log messages (all levels)', helper.log().args)
  console.log('Current Log messages (fatal, error, warn, info)', helper.log().args.filter((event) => event[0].level >= 40))
  var sNode = helper.getNode('dxBarcodeScanner.1');
  sNode.should.have.property('name', 'barcode1');
  helper.settings({ });
  done();
});