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
+10-38
Original file line number
Diff line number
Diff line change
@@ -6,55 +6,21 @@ Using the test-helper, your tests can start the Node-RED runtime, load a test fl
6
6
7
7
## Adding to your node project dependencies
8
8
9
-
To add unit tests your node project test dependencies, add this test helper as follows:
9
+
Node-RED is required by the helper as a peer dependency, meaning it must be installed along with the helper itself. To create unit tests for your node project, add this test helper and Node-RED as follows:
This will add the helper module to your `package.json` file as a development dependency:
13
+
This will add the helper module to your `package.json` file:
14
14
15
15
```json
16
16
...
17
17
"devDependencies": {
18
+
"node-red":"^0.18.4",
18
19
"node-red-node-test-helper": "^0.1.6"
19
20
}
20
21
...
21
22
```
22
23
23
-
The test-helper requires the node-red runtime to run its tests, but Node-RED is **not** installed as a dependency. The reason for this is that test-helper is (or will be) used in Node-RED core tests, and Node-RED itself has a large number of dependencies that you may not want to download if you already have it installed.
24
-
25
-
You can install the Node-RED runtime available for your unit tests one of two ways:
26
-
27
-
1. as a dev dependency in your project:
28
-
29
-
```
30
-
npm install node-red --save-dev
31
-
```
32
-
33
-
2. or link to Node-RED installed globally (recommended) using:
34
-
35
-
```
36
-
npm install -g node-red
37
-
npm link node-red
38
-
```
39
-
40
-
Both [Mocha](https://mochajs.org/) and [Should](https://shouldjs.github.io/) will be pulled in with the test helper. Mocha is a unit test framework for Javascript; Should is an assertion library. For more information on these frameworks, see their associated documentation.
41
-
42
-
## Linking to additional test dependencies
43
-
44
-
To reduce disk use further, you can install the test-helper and additional dev dependencies globally and then link them to your node project. This may be a better option especially if you are developing more than one node.
45
-
46
-
See the `package.json` file for the additional dependencies used by test-helper.
47
-
48
-
For example to install express globally:
49
-
50
-
npm install -g express
51
-
52
-
Then link to it in your project:
53
-
54
-
npm link express
55
-
56
-
Depending on the nodes in your test flow, you may also want to link to other global packages. If a test indicates that a package cannot be found, and you expect to need it for testing other nodes, consider installing the package globally and then linking it to your node project the same way.
57
-
58
24
## Adding test script to `package.json`
59
25
60
26
To run your tests you can add a test script to your `package.json` file in the `scripts` section. To run all of the files with the `_spec.js` prefix in the test directory for example:
@@ -84,6 +50,8 @@ var should = require("should");
84
50
var helper =require("node-red-node-test-helper");
85
51
var lowerNode =require("../lower-case.js");
86
52
53
+
helper.init(require.resolve('node-red'));
54
+
87
55
describe('lower-case Node', function () {
88
56
89
57
afterEach(function () {
@@ -121,6 +89,10 @@ In this example, we require `should` for assertions, this helper module, as well
121
89
122
90
We then have a set of mocha unit tests. These tests check that the node loads correctly, and ensures it makes the payload string lower case as expected.
123
91
92
+
## Initializing Helper
93
+
94
+
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.
95
+
124
96
## Getting nodes in the runtime
125
97
126
98
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.
0 commit comments