Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass settings as optional parameter to helper.load() #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function findRuntimePath() {
}
}


// As we have prerelease tags in development version, they need stripping off
// before semver will do a sensible comparison with a range.
function checkSemver(localVersion,testRange) {
Expand Down Expand Up @@ -118,7 +117,30 @@ class NodeTestHelper extends EventEmitter {
}
}

load(testNode, testFlow, testCredentials, cb) {
/**
* Loads a flow then starts the flow.
*
* @param {Object|Object[]} testNode - Module object of a node to be tested returned by require function. This node will be registered, and can be used in testFlows.
* @param {Object[]} testFlow - 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.
* @param {Object} [testCredentials] - Optional node credentials. (Not optional when testSettings parameter is supplied, but may be undefined.)
* @param {Object} [testSettings] - Optional settings.
* @param {function} cb - Function to call back when testFlows has been started.
*/
load(testNode, testFlow, testCredentials, testSettings, cb) {
if (arguments.length === 3) {
// function call was: load(testNode, testFlow, cb)
cb = testCredentials;
testSettings = { available: function() { return false; } };
testCredentials = {};
} else if (arguments.length === 4) {
// function call was: load(testNode, testFlow, testCredentials, cb)
cb = testSettings;
testSettings = { available: function() { return false; } };
} else if (testCredentials === undefined) {
// function call was: load(testNode, testFlow, undefined, testSettings, cb)
testCredentials = {};
}

const log = this._log;
const logSpy = this._logSpy = this._sandbox.spy(log, 'log');
logSpy.FATAL = log.FATAL;
Expand All @@ -143,23 +165,12 @@ class NodeTestHelper extends EventEmitter {
});
});



if (typeof testCredentials === 'function') {
cb = testCredentials;
testCredentials = {};
}

var storage = {
getFlows: function () {
return when.resolve({flows:testFlow,credentials:testCredentials});
}
};

var settings = {
available: function() { return false; }
};

var red = {
_: v => v
};
Expand All @@ -173,7 +184,7 @@ class NodeTestHelper extends EventEmitter {
const redNodes = this._redNodes;
redNodes.init({
events: this._events,
settings: settings,
settings: testSettings,
storage: storage,
log: this._log
});
Expand Down