Skip to content

Commit

Permalink
Merge pull request #63 from node-red/support-async-modules
Browse files Browse the repository at this point in the history
Add support for async node modules
  • Loading branch information
knolleary authored Apr 28, 2023
2 parents 51e35e5 + cdb9c50 commit 0d7e4c3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,16 @@ class NodeTestHelper extends EventEmitter {
Object.defineProperty(red, prop, propDescriptor);
});
}
const initPromises = []

let preloadedCoreModules = new Set();
testFlow.forEach(n => {
if (this._nodeModules.hasOwnProperty(n.type)) {
// Go find the 'real' core node module and load it...
this._nodeModules[n.type](red);
const result = this._nodeModules[n.type](red);
if (result?.then) {
initPromises.push(result)
}
preloadedCoreModules.add(this._nodeModules[n.type]);
}
})
Expand All @@ -271,12 +275,17 @@ class NodeTestHelper extends EventEmitter {
}
testNode.forEach(fn => {
if (!preloadedCoreModules.has(fn)) {
fn(red);
const result = fn(red);
if (result?.then) {
initPromises.push(result)
}
}
});

return redNodes.loadFlows()
.then(redNodes.startFlows).then(() => {
return Promise.all(initPromises)
.then(redNodes.loadFlows)
.then(redNodes.startFlows)
.then(() => {
should.deepEqual(testFlow, redNodes.getFlows().flows);
if(cb) cb();
});
Expand Down

0 comments on commit 0d7e4c3

Please sign in to comment.