I'm developing a node-red node, and I'd like to know the best or intended way to test those nodes. I've been looking at some other nodes, and they look to depend on a peer installation of node-red itself and use the "helper.js" to load those nodes. I was expecting to have a more "unit-level" testing perhaps mocking the node-red.
The Inject node can be used to manual trigger a flow by clicking the node's button within the editor. It can also be used to automatically trigger flows at regular intervals. The message sent by the Inject node can have its payload and topic properties set.
This allows to securely deploy flows from the lab to the real world into production. And yes, Node-RED is stable enough to run in production (and qbee is governing it while doing so). It is also possible to distribute the flows through the APIs and online services such as GitHub.
As with running Node-RED locally, you can use the node-red command to run Node-RED in a terminal. It can then be stopped by pressing Ctrl-C or by closing the terminal window.
If you look at the way that the core nodes are tested, this should give you some ideas.
There is also an effort underway to extract the test harness from core and make it available for everyone. You should also check out the Node-RED WIKI which contains some information on testing.
In general, it looks like you will need to run your node in an embedded version of Node-RED. Running NR using your chosen test tool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With