Skip to content

Commit d2508ca

Browse files
committed
removed examples that required additional dependencies
removed node-red as a dependency so it can be used in core assume running in core if ‘node-red’ cannot be required.
1 parent 46a54fe commit d2508ca

13 files changed

+49
-3371
lines changed

README.md

+24-17
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,40 @@ This will add the helper module to your `package.json` file as a development dep
2020
...
2121
```
2222

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 dependency in your project:
28+
29+
```
30+
npm install node-red
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+
2340
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.
2441

25-
## Alternate linking of node project dependencies
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.
2645

27-
Because test-helper depends on Node-RED and express, installing test-helper as a dev dependency to your node project can pull in a large number of packages. To reduce the space on disk you can install your dev dependencies globally and then link them to your node project. This is a better option especially if you are developing more than one node.
46+
See the `package.json` file for the additional dependencies used by test-helper.
2847

29-
Install the unit test packages globally as follows:
48+
For example to install express globally:
3049

31-
npm install -g node-red
32-
npm install -g node-red-node-test-helper
33-
npm install -g should
34-
npm install -g mocha
35-
npm install -g sinon
36-
npm install -g supertest
3750
npm install -g express
3851

39-
In your node project development directory, link the unit test packages as follows:
52+
Then link to it in your project:
4053

41-
npm link node-red
42-
npm link node-red-node-test-helper
43-
npm link should
44-
npm link mocha
45-
npm link sinon
46-
npm link supertest
4754
npm link express
4855

49-
Depending on the nodes in your test flow, you may also need to link in other packages as required. 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.
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.
5057

5158
## Adding test script to `package.json`
5259

index.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,29 @@ var when = require("when");
2020
var request = require('supertest');
2121
var express = require("express");
2222
var http = require('http');
23-
24-
var RED = require("node-red");
25-
var redNodes = require("node-red/red/runtime/nodes");
26-
var flows = require("node-red/red/runtime/nodes/flows");
27-
var credentials = require("node-red/red/runtime/nodes/credentials");
28-
var comms = require("node-red/red/api/editor/comms.js");
29-
var log = require("node-red/red/runtime/log.js");
30-
var context = require("node-red/red/runtime/nodes/context.js");
31-
var events = require('node-red/red/runtime/events');
23+
var path = require('path');
24+
25+
try {
26+
var RED = require('node-red');
27+
var redNodes = require("node-red/red/runtime/nodes");
28+
var flows = require("node-red/red/runtime/nodes/flows");
29+
var credentials = require("node-red/red/runtime/nodes/credentials");
30+
var comms = require("node-red/red/api/editor/comms.js");
31+
var log = require("node-red/red/runtime/log.js");
32+
var context = require("node-red/red/runtime/nodes/context.js");
33+
var events = require('node-red/red/runtime/events');
34+
} catch (err) {
35+
// no node-red in helper-test dependencies so assume we're testing node-red
36+
var nrPath = process.cwd();
37+
var RED = require(nrPath+"/red/red.js");
38+
var redNodes = require(nrPath+"/red/runtime/nodes");
39+
var flows = require(nrPath+"/red/runtime/nodes/flows");
40+
var credentials = require(nrPath+"/red/runtime/nodes/credentials");
41+
var comms = require(nrPath+"/red/api/editor/comms.js");
42+
var log = require(nrPath+"/red/runtime/log.js");
43+
var context = require(nrPath+"/red/runtime/nodes/context.js");
44+
var events = require(nrPath+"/red/runtime/events.js");
45+
}
3246

3347
var app = express();
3448

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
},
1414
"dependencies": {
1515
"express": "4.16.2",
16-
"node-red": "0.18.3",
1716
"mocha": "~3.4.2",
1817
"should": "^8.4.0",
1918
"sinon": "1.17.7",
20-
"supertest": "3.0.0"
19+
"supertest": "3.0.0",
20+
"when": "3.7.8"
2121
},
2222
"devDependencies": {
2323
"hash-sum": "1.0.2"

0 commit comments

Comments
 (0)