Skip to content

Commit 0a663e1

Browse files
committed
Optionally preload catch/status/complete nodes in test cases
Fixes #48
1 parent 9adb40d commit 0a663e1

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

index.js

+30-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ function findRuntimePath() {
5757
return path.join(dirpath, pkg.main);
5858
} catch (ignored) {}
5959
}
60+
// case 4: NR & NRNTH are git repos sat alongside each other
61+
try {
62+
const nrpkg = require("../node-red/package.json");
63+
return "../node-red/packages/node_modules/node-red"
64+
} catch(ignored) {}
6065
}
6166

6267

@@ -122,6 +127,14 @@ class NodeTestHelper extends EventEmitter {
122127
this._NodePrototype = require(path.join(prefix, '@node-red/runtime/lib/nodes/Node')).prototype;
123128
this._settings = RED.settings;
124129
this._events = RED.runtime.events;
130+
131+
this._nodeModules = {
132+
'catch': require(path.join(prefix, '@node-red/nodes/core/common/25-catch.js')),
133+
'status': require(path.join(prefix, '@node-red/nodes/core/common/25-status.js')),
134+
'complete': require(path.join(prefix, '@node-red/nodes/core/common/24-complete.js'))
135+
}
136+
137+
125138
}
126139
} catch (ignored) {
127140
console.log(ignored);
@@ -240,13 +253,24 @@ class NodeTestHelper extends EventEmitter {
240253
});
241254
}
242255

243-
if (Array.isArray(testNode)) {
244-
testNode.forEach(fn => {
245-
fn(red);
246-
});
247-
} else {
248-
testNode(red);
256+
let preloadedCoreModules = new Set();
257+
testFlow.forEach(n => {
258+
if (this._nodeModules.hasOwnProperty(n.type)) {
259+
// Go find the 'real' core node module and load it...
260+
this._nodeModules[n.type](red);
261+
preloadedCoreModules.add(this._nodeModules[n.type]);
262+
}
263+
})
264+
265+
if (!Array.isArray(testNode)) {
266+
testNode = [testNode];
249267
}
268+
testNode.forEach(fn => {
269+
if (!preloadedCoreModules.has(fn)) {
270+
fn(red);
271+
}
272+
});
273+
250274
return redNodes.loadFlows()
251275
.then(() => {
252276
redNodes.startFlows();

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-test-helper",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "A test framework for Node-RED nodes",
55
"main": "index.js",
66
"scripts": {
@@ -16,10 +16,10 @@
1616
"express": "4.17.1",
1717
"body-parser": "1.19.0",
1818
"read-pkg-up": "7.0.1",
19-
"semver": "7.3.2",
19+
"semver": "7.3.4",
2020
"should": "^13.2.3",
2121
"should-sinon": "0.0.6",
22-
"sinon": "9.0.2",
22+
"sinon": "9.2.4",
2323
"stoppable": "1.1.0",
2424
"supertest": "4.0.2"
2525
},

0 commit comments

Comments
 (0)