The Node-RED Node Test Helper is a comprehensive framework designed for unit testing Node-RED nodes and flows. It enables developers to start a dedicated Node-RED runtime instance within their test environment, load specific test flows, and simulate message injection and reception to verify node behavior. The current stable version is 0.3.6, with regular maintenance updates including dependency bumps and minor feature enhancements. This helper differentiates itself by integrating directly with the Node-RED runtime, providing a realistic testing environment that goes beyond simple JavaScript unit tests, ensuring nodes function correctly within the flow-based programming paradigm. It is an essential tool for maintaining the quality and reliability of custom Node-RED nodes.
npm install node-red-node-test-helperVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic unit test for a custom Node-RED node, loading a flow, injecting messages, and asserting the output, including proper asynchronous handling.
Upgrade your Node.js environment to version 14 or later. For example, use `nvm install 18 && nvm use 18`.
Wrap assertions in `try...catch` blocks and call `done(err)` or `reject(err)` on failure. When using async/await, ensure the promise rejects on error as shown in the quickstart example.
Install both packages together as dev dependencies: `npm install node-red-node-test-helper node-red --save-dev`.
Refactor test setup and teardown hooks (e.g., `beforeEach`, `afterEach`) and test cases to use `async/await` with helper methods where appropriate, as demonstrated in the quickstart.
Run `npm install node-red node-red-node-test-helper --save-dev` to ensure both packages are available in your project.
Wrap assertions in a `try...catch` block and call `done(err)` on error, or `reject(err)` if using promises, to properly report failures and complete the test.
Ensure your test functions (e.g., `beforeEach`, `afterEach`, `it`) are declared `async` and use `await` before calling helper methods like `helper.startServer()`.
Update your Node.js installation to version 14 or newer. You can use a tool like NVM (Node Version Manager) to manage multiple Node.js versions.