Skip to content

Errors in function node code swallowed during testing -- causes test timeout #52

Description

@zachsitka

Errors in function node code are swallowed and cause timeout error in test instead of fail the test.

Since the tests are there to be able to help find and diagnose these issues, these errors would be more helpful if they were thrown up to the test code and handled there.
This also will slow down any tests that are running, since they will hit timeout in order to fail when they could instead fail as soon as the error is hit.

Example test code below 👇

const should = require("should");
const helper = require("node-red-node-test-helper");

const flow = [
    {
        "id": "2487e9dbea5d61b6",
        "type": "helper",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "wires": []
    },
    {
        "id": "f5903684.b7a698",
        "type": "function",
        "name": "inputs",
        // Here is where the error is hit in the function -- should be object undefined error
        "func": "msg.count = msg.property_does_not_exist.array.length;"+
                "return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "wires": [
            [
                "2487e9dbea5d61b6"
            ]
        ]
    }
]

const requiredNodes = [
    require("../../node_modules/@node-red/nodes/core/function/10-function")
]

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

describe("error test", function() {
    before(function(done) {
        helper.startServer(done);
    });

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

    after(function(done) {
        helper.stopServer(done);
    });

    // This currently fails because you cannot test a function node that sets the msg.payload value for some reason
    it.only('should not time out', function(done) {
        helper.load(requiredNodes, flow, function() {
            try {
                var debugNode = helper.getNode("2487e9dbea5d61b6");
                var inputFunctionNode = helper.getNode("f5903684.b7a698");
    
                debugNode.on("input", function(msg) {
                    try {
                        should(1).equal(1);
                        done();
                    } catch (err) {
                        done(err);
                    }
                });
    
                inputFunctionNode.receive({ payload: 'test payload' });
            } catch (err) {
                done(err);
            }
        });
    });
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions