Node-red-node-test issues, getting output from node


Trying to automate my testing, with "npm test" scripts, github and Travis-ci. Works fine for the most part, but I somehow cannot get the flow to work and catch output from the verisurenode, that is supposed to fetch data from verisure apis. I'm using mocha to intercept and answer the api calls. I can confirm that the node receives an incoming message, but troubleshooting after that is hard. Bit of newbie on the testing part...

it('should fetch status', function (done) {
    // setup intercepts
      .get('/xbn/2/installation/search?email=' + verEmail)
      .replyWithFile(200, `${__dirname}/sites_reply.json`);
      .replyWithFile(200, `${__dirname}/token_reply.xml`);
      .replyWithFile(200, `${__dirname}/test_site.json`);
    // define flow to test
    var flow = [{ 'id': 'n1', 'type': 'VerisureAlarmNode', 'z': 'f1', 'name': 'Verisure Alarm', 'user': 'nc', 'x': 240, 'y': 240, 'wires': [ ['nh'] ] },
      { 'id': 'nc', 'type': 'VerisureConfig', 'z': 'f1', 'displayName': 'Verisure Site', 'siteName': 'Home', 'username': verEmail, 'password': verPassword },
      { id: 'nh', type: 'helper', 'z': 'f1' },
      { id: 'f1', type: 'tab', label: 'Test flow' }
    // console.log(helper.log());
    helper.load([sureNode, confNode], flow, function () {
      var n1 = helper.getNode('n1');
      var nc = helper.getNode('nc');
      var nh = helper.getNode('nh');'username', verEmail);
      n1.on('call:warn', function (msg) {
        console.log('warning N1: ' + msg);
      nh.on('input', function (msg) {'{"currentStatus":"DISARMED","changed":"false","date":"2018-11-08T06:54:28.000Z","name":"Kristian"}');
        console.log('Test message received NH: ' + msg);
      n1.on('input', function (msg) {
        console.log('Test message received N1: ' + msg.payload);
      n1.receive({ payload: 'test' });
    }); // should fetch status


No one with experience in using test-helper? Seems now my main issue that using .emit() doesnt actually make anything being sent on to the next node...


Hi @ksvan

Test helper is used extensively by the core nodes, and has evolved as the testing requirements of those nodes have evolved. But it isn't used much (yet) out side of that. So there is limited experience in the community for using it.

The best I can suggest is to follow the examples in the core node tests.

When you stay using .emit doesn't do anything... Can you elaborate? I don't see it being used in you code here.


You are calling done() before the test is finished, as the previous functions are asynchronous. You should probably move it to the last line of the last on-input function.


Thanks to both of you for pitching in. Truly believe this is something we should build more experience and share in the community.

Been trying lots of different angles on this. especially including having done() placed right:) Have been through lots of the core tests as well, and after tuning and learning, it seems my issue is that the config node. It doesnt seem to be configured right with credentials however I try it, and then my main node stops early due to lacking credentials. And for some reason I cannot seem to get spying on warn/debug/error to work like the examples, so bit hard to debug.


So this is one of most recent tries:

    var flow = [
    { 'id': 'n1', 'type': 'VerisureAlarmNode', 'z': 'f1', 'name': 'Verisure Alarm', 'user': 'nc', 'x': 240, 'y': 240, 'wires': [['nh']] },
    { 'id': 'nc', 'type': 'VerisureConfig', 'z': 'f1', 'displayName': 'Verisure Site', 'siteName': 'Home', 'credentials': { 'username': verEmail, 'password': verPassword } },
    // { id: 'nh', type: 'debug', 'z': 'f1', 'active': 'true', 'complete': 'payload', 'console': 'true', 'wires': '[]', 'tostatus': 'false', 'tosidebar': 'false' },
    { id: 'nh', type: 'helper', 'z': 'f1' },
    { id: 'f1', type: 'tab', label: 'Test flow' }

  it('should output alarmstatus', function (done) {
    helper.load([sureNode, confNode], flow, function () {
      var nh = helper.getNode('nh');
      var n1 = helper.getNode('n1');
      var nc = helper.getNode('nc');
      nc.credentials.username = verEmail;
      nc.credentials.username = verPassword;
      nh.on('input', function (msg) {
        console.log('!! test');'{"currentStatus":"DISARMED","changed":"false","date":"2018-11-08T06:54:28.000Z","name":"Kristian"}');
      n1.on('call:warn', call => {
        console.log('WARN' + call);
      n1.on('call:error', call => {
        console.log('ERROR:' + call);
      n1.receive('input', { payload: 'test' });
  }); // IT end


Try adding your credentials like this:

var credentials = {nc: {'username': verEmail, 'password': verPassword}};
helper.load([sureNode, confNode], flow, credentials, function () {


Awsome, that seems to work. Now onto making Nock work in this test as well:)