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
Copy file name to clipboardExpand all lines: README.md
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,6 +104,14 @@ We then have a set of mocha unit tests. These tests check that the node loads c
104
104
105
105
To get started, we need to tell the helper where to find the node-red runtime. this is done by calling `helper.init(require.resolve('node-red'))` as shown.
106
106
107
+
The helper takes an optional `userSettings` parameter which is merged with the runtime defaults.
108
+
109
+
```javascript
110
+
helper.init(require.resolve('node-red'), {
111
+
functionGlobalContext: { os:require('os') }
112
+
});
113
+
```
114
+
107
115
## Getting nodes in the runtime
108
116
109
117
The asynchronous `helper.load()` method calls the supplied callback function once the Node-RED server and runtime is ready. We can then call the `helper.getNode(id)` method to get a reference to nodes in the runtime. For more information on these methods see the API section below.
Merges any userSettings with the defaults returned by `RED.settings`. Each invocation of this method will overwrite the previous userSettings to prevent unexpected problems in your tests.
334
+
335
+
This will enable you to replicate your production environment within your tests, for example where you're using the `functionGlobalContext` to enable extra node modules within your functions.
336
+
337
+
```javascript
338
+
// functions can now access os via global.get('os')
Starts a Node-RED server for testing nodes that depend on http or web sockets endpoints like the debug node.
@@ -361,4 +383,4 @@ var logEvents = helper.log().args.filter(function(evt {
361
383
362
384
npm run examples
363
385
364
-
This runs tests on an included lower-case node (as above) as well as snaphots of some of the core nodes' Javascript files to ensure the helper is working as expected.
386
+
This runs tests on an included lower-case node (as above) as well as snaphots of some of the core nodes' Javascript files to ensure the helper is working as expected.
0 commit comments