Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: node-red/node-red-node-test-helper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.2.7
Choose a base ref
...
head repository: node-red/node-red-node-test-helper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jun 20, 2022

  1. add setFlows so that node being tested can modify flows

    bumps version to 0.3.0
    adds test in lower-case_spec.js
    updates readme with API and example
    Steve-Mcl committed Jun 20, 2022
    Copy the full SHA
    2a82d32 View commit details
  2. Copy the full SHA
    547980c View commit details

Commits on Jun 21, 2022

  1. Merge pull request #54 from Steve-Mcl/add-setFlows

    add `setFlows` so that node being tested can modify flows
    knolleary authored Jun 21, 2022
    Copy the full SHA
    a04dc2c View commit details
  2. Update changelog

    knolleary committed Jun 21, 2022
    Copy the full SHA
    51e35e5 View commit details

Commits on Mar 14, 2023

  1. Update README.md

    Added a missing parentheses and changed `evt` to `event`
    andreasmarkussen authored Mar 14, 2023
    Copy the full SHA
    ff1d737 View commit details

Commits on Apr 28, 2023

  1. Copy the full SHA
    cdb9c50 View commit details
  2. Merge pull request #63 from node-red/support-async-modules

    Add support for async node modules
    knolleary authored Apr 28, 2023
    Copy the full SHA
    0d7e4c3 View commit details
  3. Bump for 0.3.1 release

    knolleary committed Apr 28, 2023
    Copy the full SHA
    aa56307 View commit details

Commits on Jun 23, 2023

  1. Fix async module loading

    knolleary committed Jun 23, 2023
    Copy the full SHA
    64ecde7 View commit details
  2. Merge pull request #61 from andreasmarkussen/patch-1

    Update README.md
    knolleary authored Jun 23, 2023
    Copy the full SHA
    241fe9b View commit details
  3. Merge pull request #65 from node-red/v032

    Fix async module loading
    knolleary authored Jun 23, 2023
    Copy the full SHA
    5395b27 View commit details
  4. Update changelog

    knolleary committed Jun 23, 2023
    Copy the full SHA
    6009463 View commit details

Commits on Sep 18, 2023

  1. Upgrade semver to avoid CVE

    Pezmc committed Sep 18, 2023
    Copy the full SHA
    1bf26e2 View commit details
  2. Copy the full SHA
    09298c4 View commit details
  3. Use the compatible caret for all dependencies

    Previously downsteam projects must use these exact versions, now they can use anything compatible with the test helpers versions.
    Pezmc committed Sep 18, 2023
    Copy the full SHA
    7c1af1f View commit details

Commits on Sep 19, 2023

  1. Merge pull request #70 from Pezmc/chore-compatibility-flag

    Use compatible versions rather than specific version of dependencies
    knolleary authored Sep 19, 2023
    Copy the full SHA
    6f53b9b View commit details

Commits on Dec 22, 2023

  1. Add plugin stub to runtime

    joepavitt committed Dec 22, 2023
    Copy the full SHA
    e6e1efb View commit details
  2. Merge pull request #73 from joepavitt/master

    Add plugin stub to runtime
    knolleary authored Dec 22, 2023
    Copy the full SHA
    5e7b157 View commit details
  3. Update for new release

    knolleary committed Dec 22, 2023
    Copy the full SHA
    8d82fbf View commit details

Commits on Apr 25, 2024

  1. Update supertest dependency

    fixes #75 
    
    Major version bump drops support for Node <14.16.0 so no need for a big jump as this package is already <14
    hardillb authored Apr 25, 2024
    Copy the full SHA
    835530e View commit details

Commits on May 3, 2024

  1. Merge pull request #76 from hardillb/patch-1

    Update supertest dependency
    knolleary authored May 3, 2024
    Copy the full SHA
    560a3f1 View commit details
  2. Copy the full SHA
    8d54e02 View commit details
  3. Merge pull request #78 from node-red/update-deps

    Update dependencies for 0.3.4
    knolleary authored May 3, 2024
    Copy the full SHA
    fc1d059 View commit details

Commits on Sep 16, 2024

  1. Copy the full SHA
    6d405b9 View commit details
  2. Merge pull request #79 from hardillb/bump-express

    Bump express.js and body-parser
    knolleary authored Sep 16, 2024
    Copy the full SHA
    c20dbdc View commit details

Commits on Oct 28, 2024

  1. feat: enable start/stop server in vitest

    Callback using "done" in vitest was deprecated.
    They recommend using async/await or add a arrow function that returns a promise.
    Since async/await is less verbose, making start/stop server async makes sense.
    AllanOricil committed Oct 28, 2024
    Copy the full SHA
    2514932 View commit details
  2. Merge pull request #81 from AllanOricil/vitest-setup

    feat: enable async start/stop server
    knolleary authored Oct 28, 2024
    Copy the full SHA
    db9a73f View commit details

Commits on Nov 2, 2024

  1. feat: enable load, setFlows to be used with async/await

    this is a continuation of #81
    AllanOricil committed Nov 2, 2024
    Copy the full SHA
    505ccc7 View commit details
  2. Copy the full SHA
    00f3f69 View commit details

Commits on Nov 5, 2024

  1. Merge pull request #82 from AllanOricil/vitest-setup-2

    feat: make load, setFlows async/await (enable vitest)
    knolleary authored Nov 5, 2024
    Copy the full SHA
    949edd2 View commit details
Showing with 258 additions and 61 deletions.
  1. +24 −0 CHANGELOG.md
  2. +40 −3 README.md
  3. +24 −0 examples/lower-case_spec.js
  4. +160 −47 index.js
  5. +10 −11 package.json
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
#### 0.3.4

- Update dependencies

#### 0.3.3

- Add plugin stub to runtime (#73) @joepavitt
- Use compatible versions rather than specific version of dependencies (#70) @Pezmc

#### 0.3.2

- Fix async module loading (#65) @knolleary
- Update README.md (#61) @andreasmarkussen

#### 0.3.1

- Add support for async node modules (#63) @knolleary

#### 0.3.0

- Require node.js >=14
- Add `setFlows` so that node being tested can modify flows (#54) @Steve-Mcl

#### 0.2.7

- Wait for startFlows to resolve before returning from loadFlow call - required with Node-RED 1.3+
- README.md: Update example unit test to report assertion failures
- examples: lower-case_spec.js: Allow proper assertion failure reporting (#45)
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -314,7 +314,44 @@ Loads a flow then starts the flow. This function has the following arguments:
* 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.
* testFlow: (array of objects) Flow data to test a node. If you want to use flow data exported from Node-RED editor, export the flow to the clipboard and paste the content into your test scripts.
* testCredentials: (object) Optional node credentials.
* cb: (function) Function to call back when testFlows has been started.
* cb: (function) Function to call back when testFlows has been started (not required when called wih `await`)

### setFlows(testFlow, type, testCredentials, cb)

Updates the currently loaded flow. This function has the following arguments:

* testFlow: (array of objects) Flow data to test a node. If you want to use flow data exported from Node-RED editor, export the flow to the clipboard and paste the content into your test scripts.
* type: (string) Flow data to test a node. If you want to use flow data exported from Node-RED editor, export the flow to the clipboard and paste the content into your test scripts.
* testCredentials: (object) Optional node credentials.
* cb: (function) Function to call back when testFlows has been loaded (not required when called wih `await`)

#### Example

```js
it('should modify the flow then lower case of payload', async function () {
const flow = [
{ id: "n2", type: "helper" }
]
await helper.load(lowerNode, flow)
const newFlow = [...flow]
newFlow.push( { id: "n1", type: "lower-case", name: "lower-case", wires:[['n2']] },)
await helper.setFlows(newFlow, "nodes") //update flows
const n1 = helper.getNode('n1')
n1.should.have.a.property('name', 'lower-case')
await new Promise((resolve, reject) => {
const n2 = helper.getNode('n2')
n2.on('input', function (msg) {
try {
msg.should.have.property('payload', 'hello');
resolve()
} catch (err) {
reject(err);
}
});
n1.receive({ payload: 'HELLO' });
});
});
```

### unload()

@@ -384,8 +421,8 @@ Return the URL of the helper server including the ephemeral port used when start
Return a spy on the logs to look for events from the node under test. For example:

```javascript
var logEvents = helper.log().args.filter(function(evt {
return evt[0].type == "batch";
var logEvents = helper.log().args.filter(function(event) {
return event[0].type == "batch";
});
```

24 changes: 24 additions & 0 deletions examples/lower-case_spec.js
Original file line number Diff line number Diff line change
@@ -54,4 +54,28 @@ describe('lower-case Node', function () {
n1.receive({ payload: "UpperCase" });
});
});
it('should modify the flow then lower case of payload', async function () {
const flow = [
{ id: "n2", type: "helper" }
]
await helper.load(lowerNode, flow)

const newFlow = [...flow]
newFlow.push( { id: "n1", type: "lower-case", name: "lower-case", wires:[['n2']] },)
await helper.setFlows(newFlow)
const n1 = helper.getNode('n1')
n1.should.have.a.property('name', 'lower-case')
await new Promise((resolve, reject) => {
const n2 = helper.getNode('n2')
n2.on('input', function (msg) {
try {
msg.should.have.property('payload', 'hello');
resolve()
} catch (err) {
reject(err);
}
});
n1.receive({ payload: 'HELLO' });
});
});
});
Loading