Skip to content

Commit 318a504

Browse files
committed
more documentation fixes
1 parent 4cb90a0 commit 318a504

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

README.md

+16-21
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22

33
This test-helper module makes the node test framework from the Node-RED core available for node contributors.
44

5-
Using the test-helper, your tests can start the Node-RED runtime, load a flow and receive messages
6-
to ensure your node code is correct.
5+
Using the test-helper, your tests can start the Node-RED runtime, load a flow and receive messages to ensure your node code is correct.
76

87
## Adding to your node project dependencies
98

109
To add unit tests your node project test dependencies, add this test helper as follows:
1110

1211
npm install node-red-node-test-helper --save-dev
1312

14-
This will add this modules to your `package.json` file as a development dependency.
15-
16-
[Mocha](https://mochajs.org/) is a unit test framework for Javascript. [Should](https://shouldjs.github.io/) is an assertion library used in our example unit tests which will also be added to your porject. For more information on these frameworks, see their associated documentation. Depending on your testing needs, you may need to add additional dev dependencies.
17-
18-
Your `project.json` file should now contain something like the following:
13+
This will add the helper module to your `package.json` file as a development dependency:
1914

2015
```json
2116
...
@@ -25,9 +20,11 @@ Your `project.json` file should now contain something like the following:
2520
...
2621
```
2722

23+
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.
24+
2825
## Adding test script to `package.json`
2926

30-
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:
27+
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:
3128

3229
```json
3330
...
@@ -37,15 +34,15 @@ To run your tests you can add a test script to your `package.json` file in the `
3734
...
3835
```
3936

40-
This will allow you to use `npm test` to run your tests.
37+
This will allow you to use `npm test` on the command line.
4138

4239
## Creating unit tests
4340

44-
We recommend putting unit test scripts in the `test/` folder of your project and using the `_spec.js` (for specification) suffix naming convention for your tests.
41+
We recommend putting unit test scripts in the `test/` folder of your project and using the `*_spec.js` (for specification) suffix naming convention.
4542

4643
## Example Unit Test
4744

48-
Here is an example test for testing the lower-case node in the [Node-RED documentation](https://nodered.org/docs/creating-nodes/first-node). Lets name our test script `test/lower-case_spec.js`.
45+
Here is an example test for testing the lower-case node in the [Node-RED documentation](https://nodered.org/docs/creating-nodes/first-node). Here we name our test script `test/lower-case_spec.js`.
4946

5047
### `test/lower-case_spec.js`:
5148

@@ -87,31 +84,29 @@ describe('lower-case Node', function () {
8784
});
8885
```
8986

90-
In this example, we require `should` for assertions, the helper module, as well as the `lower-case` node we want to test.
87+
In this example, we require `should` for assertions, this helper module, as well as the `lower-case` node we want to test, located in the parent directory.
9188

9289
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.
9390

9491
## Getting nodes in the runtime
9592

96-
The asynchronous `helper.load()` method calls the supplied function once the Node-RED server and runtime is read. We can then call helper methods to get a reference to nodes in the runtime. For more information on `helper.load()` see the API section below.
93+
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.
9794

9895
## Receiving messages from nodes
9996

100-
The second test uses a `helper` node in the runtime connected to the output of our `lower-case` node under test.
97+
The second test uses a `helper` node in the runtime connected to the output of our `lower-case` node under test. The `helper` node is a mock node with no functionality. By adding "input" event handlers as in the example, we can check the messages received by the `helper`.
10198

102-
The Helper node is a mock node with no functionality. By adding "input" event handlers as in the example, the helper node can receive a message from the previous `lower-case` node in the flow and check if its contents are as expected.
99+
To send a message into the `lower-case` node `n1` under test we call `n1.receive({ payload: "UpperCase" })` on that node. We can then check that the payload is indeed lower case in the `helper` node input event handler.
103100

104101
## Running your tests
105102

106103
To run your tests:
107104

108-
npm run
109-
110-
Producing the following output (for example):
105+
npm test
111106

112-
>npm test
107+
Producing the following output (for this example):
113108

114-
> [email protected] test /Users/mike/dev/work/node-red-contrib-lower-case
109+
> [email protected] test /dev/work/node-red-contrib-lower-case
115110
> mocha 'test/**/*_spec.js'
116111

117112
lower-case Node
@@ -134,7 +129,7 @@ Loads a flow then starts the flow. This function has the following arguments:
134129

135130
* testNode: (object|array of objects) Module object of a node to be tested returned by require function. This node will be registered, and can be used in testFlows.
136131
* testFlows: (array of objects) Flow data to test a node. If you want to use the flow data exported from Node-RED editor, need to covert it to JavaScript object using JSON.parse().
137-
* testCredentials: (object) Optional node credentials. This argument is optional.
132+
* testCredentials: (object) Optional node credentials.
138133
* cb: (function) Function to call back when testFlows has been started.
139134

140135
### unload()

0 commit comments

Comments
 (0)