Skip to content

Commit cdb9c50

Browse files
committed
Add support for async node modules
1 parent 51e35e5 commit cdb9c50

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ class NodeTestHelper extends EventEmitter {
256256
Object.defineProperty(red, prop, propDescriptor);
257257
});
258258
}
259+
const initPromises = []
259260

260261
let preloadedCoreModules = new Set();
261262
testFlow.forEach(n => {
262263
if (this._nodeModules.hasOwnProperty(n.type)) {
263264
// Go find the 'real' core node module and load it...
264-
this._nodeModules[n.type](red);
265+
const result = this._nodeModules[n.type](red);
266+
if (result?.then) {
267+
initPromises.push(result)
268+
}
265269
preloadedCoreModules.add(this._nodeModules[n.type]);
266270
}
267271
})
@@ -271,12 +275,17 @@ class NodeTestHelper extends EventEmitter {
271275
}
272276
testNode.forEach(fn => {
273277
if (!preloadedCoreModules.has(fn)) {
274-
fn(red);
278+
const result = fn(red);
279+
if (result?.then) {
280+
initPromises.push(result)
281+
}
275282
}
276283
});
277284

278-
return redNodes.loadFlows()
279-
.then(redNodes.startFlows).then(() => {
285+
return Promise.all(initPromises)
286+
.then(redNodes.loadFlows)
287+
.then(redNodes.startFlows)
288+
.then(() => {
280289
should.deepEqual(testFlow, redNodes.getFlows().flows);
281290
if(cb) cb();
282291
});

0 commit comments

Comments
 (0)