Node-red-node-test-helper does not support multiple upstream output ports?

Repro

  • define a node myNode, with multiple output ports
  • at the end of its node.on('input', ...), call node.send([msg1, msg2, ...]);
  • hook this node up with node-red-node-test-helper, like this
let flow = [
  { id: 'n1', type: 'myNode', wires: [['n2']] },
  { id: 'n2', type: 'helper', wires: [[]] }
];
  • Load the flow and do the regular dance
helper.load(myNodeRuntime, flow, function () {
      var n2 = helper.getNode("n2");
      var n1 = helper.getNode("n1");
      n2.on("input", function (msgs) {
        expect(msgs[0].payload.output).toEqual(msg1.payload.output);
        expect(msgs[1].payload.output).toEqual(msg2.payload.output);
        ...

      });
      n1.receive({ payload: "expected input message to myNode" });
});

Expected

  • The test should pass: n2 should receive a message array of the exact layout as the message array sent from n1.

Observed

  • n2 only receives a single message, which is the first message in the message array sent from n1

Question

Is this by design? How do I properly test a node with multiple output ports?

Looking at your wires array property of n1 you have only wired up n2 to one of the outputs so yes you aren't going to test the other... notice like the send it is an array of arrays. one for each output.

Do you mean I can actually hook up multiple node-red-node-test-helper with different IDs?
I see. That makes sense. I'll try it and report back.

This question was cross-posted as an issue on the test-helper (please don't do that). I've already answered it there: Helper wrongly strips off all but the first message in its input message array · Issue #60 · node-red/node-red-node-test-helper · GitHub

1 Like

@knolleary
Sorry about that. Will not do that again. Thanks for the solution. Works like a charm!

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