mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Improve unit test coverage
This commit is contained in:
@@ -150,6 +150,51 @@ test-module-config`)
|
||||
))
|
||||
})
|
||||
})
|
||||
describe("exportPluginSettings", function() {
|
||||
it("exports plugin settings - default false", function() {
|
||||
plugins.init({ "a-plugin": { a: 123, b:234, c: 345} });
|
||||
plugins.registerPlugin("test-module/test-set","a-plugin",{
|
||||
settings: {
|
||||
a: { exportable: true },
|
||||
b: {exportable: false },
|
||||
d: { exportable: true, value: 456}
|
||||
|
||||
}
|
||||
});
|
||||
var exportedSet = {};
|
||||
plugins.exportPluginSettings(exportedSet);
|
||||
exportedSet.should.have.property("a-plugin");
|
||||
// a is exportable
|
||||
exportedSet["a-plugin"].should.have.property("a",123);
|
||||
// b is explicitly not exportable
|
||||
exportedSet["a-plugin"].should.not.have.property("b");
|
||||
// c isn't listed and default false
|
||||
exportedSet["a-plugin"].should.not.have.property("c");
|
||||
// d has a default value
|
||||
exportedSet["a-plugin"].should.have.property("d",456);
|
||||
})
|
||||
it("exports plugin settings - default true", function() {
|
||||
plugins.init({ "a-plugin": { a: 123, b:234, c: 345} });
|
||||
plugins.registerPlugin("test-module/test-set","a-plugin",{
|
||||
settings: {
|
||||
'*': { exportable: true },
|
||||
a: { exportable: true },
|
||||
b: {exportable: false },
|
||||
d: { exportable: true, value: 456}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
var exportedSet = {};
|
||||
plugins.exportPluginSettings(exportedSet);
|
||||
exportedSet.should.have.property("a-plugin");
|
||||
// a is exportable
|
||||
exportedSet["a-plugin"].should.have.property("a",123);
|
||||
// b is explicitly not exportable
|
||||
exportedSet["a-plugin"].should.not.have.property("b");
|
||||
// c isn't listed, but default true
|
||||
exportedSet["a-plugin"].should.have.property("c");
|
||||
// d has a default value
|
||||
exportedSet["a-plugin"].should.have.property("d",456);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@@ -574,4 +574,41 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getModuleResource', function() {
|
||||
beforeEach(function() {
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({
|
||||
name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"],
|
||||
file: "abc"
|
||||
}
|
||||
},
|
||||
resources: {
|
||||
path: path.join(__dirname, "resources","examples")
|
||||
}
|
||||
});
|
||||
});
|
||||
it('Returns valid resource path', function() {
|
||||
const result = typeRegistry.getModuleResource("test-module","one.json");
|
||||
should.exist(result);
|
||||
result.should.eql(path.join(__dirname, "resources","examples","one.json"))
|
||||
});
|
||||
it('Returns null for path that tries to break out', function() {
|
||||
// Note - this path exists, but we don't allow .. in the resolved path to
|
||||
// avoid breaking out of the resources dir
|
||||
const result = typeRegistry.getModuleResource("test-module","../../index_spec.js");
|
||||
should.not.exist(result);
|
||||
});
|
||||
it('Returns null for path that does not exist', function() {
|
||||
const result = typeRegistry.getModuleResource("test-module","two.json");
|
||||
should.not.exist(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -15,13 +15,61 @@
|
||||
**/
|
||||
|
||||
const should = require("should");
|
||||
const sinon = require("sinon");
|
||||
|
||||
const NR_TEST_UTILS = require("nr-test-utils");
|
||||
const registryUtil = NR_TEST_UTILS.require("@node-red/registry/lib/util");
|
||||
|
||||
// Get the internal runtime api
|
||||
const runtime = NR_TEST_UTILS.require("@node-red/runtime")._;
|
||||
|
||||
const i18n = NR_TEST_UTILS.require("@node-red/util").i18n;
|
||||
|
||||
describe("red/nodes/registry/util",function() {
|
||||
describe("createNodeApi", function() {
|
||||
it.skip("needs tests");
|
||||
let i18n_;
|
||||
let registerType;
|
||||
let registerSubflow;
|
||||
|
||||
before(function() {
|
||||
i18n_ = sinon.stub(i18n,"_").callsFake(function() {
|
||||
return Array.prototype.slice.call(arguments,0);
|
||||
})
|
||||
registerType = sinon.stub(runtime.nodes,"registerType");
|
||||
registerSubflow = sinon.stub(runtime.nodes,"registerSubflow");
|
||||
});
|
||||
after(function() {
|
||||
i18n_.restore();
|
||||
registerType.restore();
|
||||
registerSubflow.restore();
|
||||
})
|
||||
|
||||
it("builds node-specific view of runtime api", function() {
|
||||
registryUtil.init(runtime);
|
||||
var result = registryUtil.createNodeApi({id: "my-node", namespace: "my-namespace"})
|
||||
// Need a better strategy here.
|
||||
// For now, validate the node-custom functions
|
||||
|
||||
var message = result._("message");
|
||||
// This should prepend the node's namespace to the message
|
||||
message.should.eql([ 'my-namespace:message' ]);
|
||||
|
||||
var nodeConstructor = () => {};
|
||||
var nodeOpts = {};
|
||||
result.nodes.registerType("type",nodeConstructor, nodeOpts);
|
||||
registerType.called.should.be.true();
|
||||
registerType.lastCall.args[0].should.eql("my-node")
|
||||
registerType.lastCall.args[1].should.eql("type")
|
||||
registerType.lastCall.args[2].should.eql(nodeConstructor)
|
||||
registerType.lastCall.args[3].should.eql(nodeOpts)
|
||||
|
||||
var subflowDef = {};
|
||||
result.nodes.registerSubflow(subflowDef);
|
||||
registerSubflow.called.should.be.true();
|
||||
registerSubflow.lastCall.args[0].should.eql("my-node")
|
||||
registerSubflow.lastCall.args[1].should.eql(subflowDef)
|
||||
|
||||
});
|
||||
});
|
||||
describe("checkModuleAllowed", function() {
|
||||
function checkList(module, version, allowList, denyList) {
|
||||
|
Reference in New Issue
Block a user