My node unit test always times out

I'm trying to follow node-red-node-test-helper's doc to unittest a custom node.
However, although the node loads OK, the functional test always times out.

See my mocha spec below:

var should = require('should');
var helper = require("node-red-node-test-helper");
var targetNode = require("../node.js");

helper.init(require.resolve('node-red'));

describe('Dummy Node', function () {
//  this.timeout(10000);

  beforeEach(function (done) {
      helper.startServer(done);
  });

  afterEach(function (done) {
      helper.unload();
      helper.stopServer(done);
  });

  it('should be loaded', function (done) {
    var flow = [{ id: "n1", type: "dummy", name: "dummy node" }];
    helper.load(targetNode, flow, function () {
      var n1 = helper.getNode("n1");
      try {
        n1.should.have.property('name', 'dummy node');
        done();
      } catch (e) {
        done(e)
      }
    });
  });

  it('should make payload lower case', function (done) {
    var flow = [
	    { id: "n1", type: "dummy", name: "dummy node", wires:[["n2"]] },
	    { id: "n2", type: "helper" }
	];
    helper.load(targetNode, flow, function () {
      var n2 = helper.getNode("n2");
      var n1 = helper.getNode("n1");
      n2.on("input", function (msg) {
        try {
	        msg.should.have.property('payload', {'name': 'TOUPPER'});
	        done();
	    } catch (e) {
	        done(e);
	    }
      });
      n1.receive({ topic: "", payload: {'name': "toupper"} });
    });
  });
});

The test result:

(.venv) (14:36) me@my-mac:~/Desktop/dummy/node 
$ npm test

> dummy@0.1.0 test /Users/me/Desktop/dummy/node
> mocha --exit "test/*_spec.js"



  Dummy Node
    ✔ should be loaded
    1) should make payload lower case


  1 passing (2s)
  1 failing

  1) Dummy Node
       should make payload lower case:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/me/Desktop/dummy/node/test/flow_spec.js)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)



npm ERR! Test failed.  See above for more details.

Tweaking the timeout value does not help.
I can't figure out where I did wrong. Please help.

Solved it myself.

Somewhere in the node implementation the backend has a popup prompt that blocks the test. After removing it the problem is solved.

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