You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This creates a symbolic link to your node module project directory in `~/.node-red/node_modules` so that Node-RED will discover the node when it starts. Any changes to the node's file can be picked up by simply restarting Node-RED.
166
+
This creates a symbolic link to your node module project directory in `~/.node-red/node_modules` so that Node-RED will discover the node when it starts. Any changes to the node's file can be picked up by simply restarting Node-RED. On Windows, again, using npm 5.x or greater:
167
167
168
-
If you are using an older version of npm, you can create a symbolic link manually to your project. For example on Mac or linux systems:
<em>Note</em>: npm 5 will add your module as a dependency in the <code>package.json</code> file located in your user directory. To prevent this, use the npm <code>--no-save</code> option.
175
-
</div>
182
+
<em>Note</em>: npm 5 will add your module as a dependency in the <code>package.json</code> file located in your user directory. If you want to prevent this, use the npm <code>--no-save</code> option.
183
+
</div>
184
+
185
+
### Unit Testing
186
+
187
+
To support unit testing, an npm module called [`node-red-node-test-helper`](https://www.npmjs.com/package/node-red-contrib-test-helper) can be used. The test-helper is a framework built on the Node-RED runtime to make it easier to test nodes.
188
+
189
+
Using this framework, you can create test flows, and then assert that your node properties and output is working as expected. For example, to add a unit test to the lower-case node you can add a `test` folder to your node module package containing a file called `_spec.js`
var flow = [{ id:"n1", type:"lower-case", name:"test name" }];
206
+
helper.load(lowerNode, flow, function () {
207
+
var n1 =helper.getNode("n1");
208
+
n1.should.have.property('name', 'test name');
209
+
done();
210
+
});
211
+
});
212
+
213
+
it('should make payload lower case', function (done) {
214
+
var flow = [{ id:"n1", type:"lower-case", name:"test name",wires:[["n2"]] },
215
+
{ id:"n2", type:"helper" }];
216
+
helper.load(lowerNode, flow, function () {
217
+
var n2 =helper.getNode("n2");
218
+
var n1 =helper.getNode("n1");
219
+
n2.on("input", function (msg) {
220
+
msg.should.have.property('payload', 'uppercase');
221
+
done();
222
+
});
223
+
n1.receive({ payload:"UpperCase" });
224
+
});
225
+
});
226
+
});
227
+
```
228
+
229
+
These tests check to see that the node is loaded into the runtime correctly, and that it correctly changes the payload to lower case as expected.
230
+
231
+
Both tests load the node into the runtime using `helper.load` supplying the node under test and a test flow The first checks that the node in the runtime has the correct name property. The second test uses a helper node to check that the output from the node is, in fact, lower case.
232
+
233
+
The helper module contains other examples of tests taken from the Node-RED core nodes. For more information on the helper module, see the associated README.
0 commit comments