1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge master to 0.18

This commit is contained in:
Nick O'Leary 2017-12-03 22:31:26 +00:00
commit 64191e8303
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
61 changed files with 3078 additions and 1013 deletions

30
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,30 @@
## Before you hit that Submit button....
This issue tracker is for problems with the Node-RED runtime, the editor or the core nodes.
If your issue is:
- a general 'how-to' type question,
- a feature request or suggestion for a change,
- or problems with 3rd party (`node-red-contrib-`) nodes
please use the [mailing list](https://groups.google.com/forum/#!forum/node-red), [slack team](https://nodered.org/slack) or ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/node-red) and tag it `node-red`.
That way the whole Node-RED user community can help, rather than rely on the core development team.
## So you have a real issue to raise...
To help us understand the issue, please fill-in as much of the following information as you can:
### What are the steps to reproduce?
### What happens?
### What do you expect to happen?
### Please tell us about your environment:
- [ ] Node-RED version:
- [ ] node.js version:
- [ ] npm version:
- [ ] Platform/OS:
- [ ] Browser:

30
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,30 @@
## Before you hit that Submit button....
Please read our [contribution guidelines](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
before submitting a pull-request.
## Types of changes
What types of changes does your code introduce?
_Put an `x` in the boxes that apply_
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
If you want to raise a pull-request with a new feature, or a refactoring
of existing code, it **may well get rejected** if it hasn't been discussed on
the [mailing list](https://groups.google.com/forum/#!forum/node-red) or
[slack team](https://nodered.org/slack) first.
## Proposed changes
Describe the nature of this change. What problem does it address?
## Checklist
_Put an `x` in the boxes that apply_
- [ ] I have read the [contribution guidelines](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
- [ ] For non-bugfix PRs, I have discussed this change on the mailing list/slack team.
- [ ] I have run `grunt` to verify the unit tests pass
- [ ] I have added suitable unit tests to cover the new/changed functionality

View File

@ -99,7 +99,7 @@
this.uiSelect = this.elementDiv.wrap( "<div>" ).parent();
var attrStyle = this.element.attr('style');
var m;
if ((m = /width\s*:\s*(\d+(%|px))/i.exec(attrStyle)) !== null) {
if ((m = /width\s*:\s*(calc\s*\(.*\)|\d+(%|px))/i.exec(attrStyle)) !== null) {
this.element.css('width','100%');
this.uiSelect.width(m[1]);
this.uiWidth = null;

View File

@ -1961,12 +1961,12 @@ RED.editor = (function() {
tabs.addTab({
id: 'expression-help',
label: 'Function reference',
label: RED._('expressionEditor.functionReference'),
content: $("#node-input-expression-tab-help")
});
tabs.addTab({
id: 'expression-tests',
label: 'Test',
label: RED._('expressionEditor.test'),
content: $("#node-input-expression-tab-test")
});
testDataEditor = RED.editor.createEditor({

View File

@ -21,7 +21,7 @@ RED.palette = (function() {
var categoryContainers = {};
function createCategoryContainer(category, label){
function createCategoryContainer(category, label) {
label = (label || category).replace(/_/g, " ");
var catDiv = $('<div id="palette-container-'+category+'" class="palette-category palette-close hide">'+
'<div id="palette-header-'+category+'" class="palette-header"><i class="expanded fa fa-angle-down"></i><span>'+label+'</span></div>'+
@ -325,14 +325,26 @@ RED.palette = (function() {
}
}
}
function hideNodeType(nt) {
var nodeTypeId = escapeNodeType(nt);
$("#palette_node_"+nodeTypeId).hide();
var paletteNode = $("#palette_node_"+nodeTypeId);
paletteNode.hide();
var categoryNode = paletteNode.closest(".palette-category");
var cl = categoryNode.find(".palette_node");
var c = 0;
for (var i = 0; i < cl.length; i++) {
if ($(cl[i]).css('display') === 'none') { c += 1; }
}
if (c === cl.length) { categoryNode.hide(); }
}
function showNodeType(nt) {
var nodeTypeId = escapeNodeType(nt);
$("#palette_node_"+nodeTypeId).show();
var paletteNode = $("#palette_node_"+nodeTypeId);
var categoryNode = paletteNode.closest(".palette-category");
categoryNode.show();
paletteNode.show();
}
function refreshNodeTypes() {
@ -396,7 +408,6 @@ RED.palette = (function() {
RED.events.on('registry:node-type-removed', function(nodeType) {
removeNodeType(nodeType);
});
RED.events.on('registry:node-set-enabled', function(nodeSet) {
for (var j=0;j<nodeSet.types.length;j++) {
showNodeType(nodeSet.types[j]);
@ -427,7 +438,6 @@ RED.palette = (function() {
}
});
$("#palette > .palette-spinner").show();
$("#palette-search input").searchBox({

View File

@ -255,16 +255,19 @@ RED.typeSearch = (function() {
var commonCount = 0;
var item;
for(i=0;i<common.length;i++) {
item = {
type: common[i],
common: true,
def: RED.nodes.getType(common[i])
};
item.label = getTypeLabel(item.type,item.def);
if (i === common.length-1) {
item.separator = true;
var itemDef = RED.nodes.getType(common[i]);
if (itemDef) {
item = {
type: common[i],
common: true,
def: itemDef
};
item.label = getTypeLabel(item.type,item.def);
if (i === common.length-1) {
item.separator = true;
}
searchResults.editableList('addItem', item);
}
searchResults.editableList('addItem', item);
}
for(i=0;i<Math.min(5,recentlyUsed.length);i++) {
item = {

View File

@ -171,7 +171,7 @@ RED.utils = (function() {
}
function formatNumber(element,obj,sourceId,path,cycle,initialFormat) {
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path]) || initialFormat || "dec";
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path] && formattedPaths[sourceId][path]['number']) || initialFormat || "dec";
if (cycle) {
if (format === 'dec') {
if ((obj.toString().length===13) && (obj<=2147483647000)) {
@ -187,10 +187,12 @@ RED.utils = (function() {
format = 'dec';
}
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
formattedPaths[sourceId][path] = format;
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
formattedPaths[sourceId][path]['number'] = format;
} else if (initialFormat !== undefined){
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
formattedPaths[sourceId][path] = format;
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
formattedPaths[sourceId][path]['number'] = format;
}
if (format === 'dec') {
element.text(""+obj);
@ -204,7 +206,7 @@ RED.utils = (function() {
}
function formatBuffer(element,button,sourceId,path,cycle) {
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path]) || "raw";
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path] && formattedPaths[sourceId][path]['buffer']) || "raw";
if (cycle) {
if (format === 'raw') {
format = 'string';
@ -212,7 +214,8 @@ RED.utils = (function() {
format = 'raw';
}
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
formattedPaths[sourceId][path] = format;
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
formattedPaths[sourceId][path]['buffer'] = format;
}
if (format === 'raw') {
button.text('raw');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
editor/vendor/ace/mode-python.js vendored Executable file
View File

@ -0,0 +1 @@
ace.define("ace/mode/python_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("./text_highlight_rules").TextHighlightRules,s=function(){var e="and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield",t="True|False|None|NotImplemented|Ellipsis|__debug__",n="abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|float|list|raw_input|unichr|callable|format|locals|reduce|unicode|chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|__import__|complex|hash|min|set|apply|delattr|help|next|setattr|buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern",r=this.createKeywordMapper({"invalid.deprecated":"debugger","support.function":n,"constant.language":t,keyword:e},"identifier"),i="(?:r|u|ur|R|U|UR|Ur|uR)?",s="(?:(?:[1-9]\\d*)|(?:0))",o="(?:0[oO]?[0-7]+)",u="(?:0[xX][\\dA-Fa-f]+)",a="(?:0[bB][01]+)",f="(?:"+s+"|"+o+"|"+u+"|"+a+")",l="(?:[eE][+-]?\\d+)",c="(?:\\.\\d+)",h="(?:\\d+)",p="(?:(?:"+h+"?"+c+")|(?:"+h+"\\.))",d="(?:(?:"+p+"|"+h+")"+l+")",v="(?:"+d+"|"+p+")",m="\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})";this.$rules={start:[{token:"comment",regex:"#.*$"},{token:"string",regex:i+'"{3}',next:"qqstring3"},{token:"string",regex:i+'"(?=.)',next:"qqstring"},{token:"string",regex:i+"'{3}",next:"qstring3"},{token:"string",regex:i+"'(?=.)",next:"qstring"},{token:"constant.numeric",regex:"(?:"+v+"|\\d+)[jJ]\\b"},{token:"constant.numeric",regex:v},{token:"constant.numeric",regex:f+"[lL]\\b"},{token:"constant.numeric",regex:f+"\\b"},{token:r,regex:"[a-zA-Z_$][a-zA-Z0-9_$]*\\b"},{token:"keyword.operator",regex:"\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|="},{token:"paren.lparen",regex:"[\\[\\(\\{]"},{token:"paren.rparen",regex:"[\\]\\)\\}]"},{token:"text",regex:"\\s+"}],qqstring3:[{token:"constant.language.escape",regex:m},{token:"string",regex:'"{3}',next:"start"},{defaultToken:"string"}],qstring3:[{token:"constant.language.escape",regex:m},{token:"string",regex:"'{3}",next:"start"},{defaultToken:"string"}],qqstring:[{token:"constant.language.escape",regex:m},{token:"string",regex:"\\\\$",next:"qqstring"},{token:"string",regex:'"|$',next:"start"},{defaultToken:"string"}],qstring:[{token:"constant.language.escape",regex:m},{token:"string",regex:"\\\\$",next:"qstring"},{token:"string",regex:"'|$",next:"start"},{defaultToken:"string"}]}};r.inherits(s,i),t.PythonHighlightRules=s}),ace.define("ace/mode/folding/pythonic",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"],function(e,t,n){"use strict";var r=e("../../lib/oop"),i=e("./fold_mode").FoldMode,s=t.FoldMode=function(e){this.foldingStartMarker=new RegExp("([\\[{])(?:\\s*)$|("+e+")(?:\\s*)(?:#.*)?$")};r.inherits(s,i),function(){this.getFoldWidgetRange=function(e,t,n){var r=e.getLine(n),i=r.match(this.foldingStartMarker);if(i)return i[1]?this.openingBracketBlock(e,i[1],n,i.index):i[2]?this.indentationBlock(e,n,i.index+i[2].length):this.indentationBlock(e,n)}}.call(s.prototype)}),ace.define("ace/mode/python",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/python_highlight_rules","ace/mode/folding/pythonic","ace/range"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("./text").Mode,s=e("./python_highlight_rules").PythonHighlightRules,o=e("./folding/pythonic").FoldMode,u=e("../range").Range,a=function(){this.HighlightRules=s,this.foldingRules=new o("\\:"),this.$behaviour=this.$defaultBehaviour};r.inherits(a,i),function(){this.lineCommentStart="#",this.getNextLineIndent=function(e,t,n){var r=this.$getIndent(t),i=this.getTokenizer().getLineTokens(t,e),s=i.tokens;if(s.length&&s[s.length-1].type=="comment")return r;if(e=="start"){var o=t.match(/^.*[\{\(\[:]\s*$/);o&&(r+=n)}return r};var e={pass:1,"return":1,raise:1,"break":1,"continue":1};this.checkOutdent=function(t,n,r){if(r!=="\r\n"&&r!=="\r"&&r!=="\n")return!1;var i=this.getTokenizer().getLineTokens(n.trim(),t).tokens;if(!i)return!1;do var s=i.pop();while(s&&(s.type=="comment"||s.type=="text"&&s.value.match(/^\s+$/)));return s?s.type=="keyword"&&e[s.value]:!1},this.autoOutdent=function(e,t,n){n+=1;var r=this.$getIndent(t.getLine(n)),i=t.getTabString();r.slice(-i.length)==i&&t.remove(new u(n,r.length-i.length,n,r.length))},this.$id="ace/mode/python"}.call(a.prototype),t.Mode=a})

File diff suppressed because one or more lines are too long

1
editor/vendor/ace/snippets/python.js vendored Executable file
View File

@ -0,0 +1 @@
ace.define("ace/snippets/python",["require","exports","module"],function(e,t,n){"use strict";t.snippetText='snippet #!\n #!/usr/bin/env python\nsnippet imp\n import ${1:module}\nsnippet from\n from ${1:package} import ${2:module}\n# Module Docstring\nsnippet docs\n \'\'\'\n File: ${1:FILENAME:file_name}\n Author: ${2:author}\n Description: ${3}\n \'\'\'\nsnippet wh\n while ${1:condition}:\n ${2:# TODO: write code...}\n# dowh - does the same as do...while in other languages\nsnippet dowh\n while True:\n ${1:# TODO: write code...}\n if ${2:condition}:\n break\nsnippet with\n with ${1:expr} as ${2:var}:\n ${3:# TODO: write code...}\n# New Class\nsnippet cl\n class ${1:ClassName}(${2:object}):\n """${3:docstring for $1}"""\n def __init__(self, ${4:arg}):\n ${5:super($1, self).__init__()}\n self.$4 = $4\n ${6}\n# New Function\nsnippet def\n def ${1:fname}(${2:`indent(\'.\') ? \'self\' : \'\'`}):\n """${3:docstring for $1}"""\n ${4:# TODO: write code...}\nsnippet deff\n def ${1:fname}(${2:`indent(\'.\') ? \'self\' : \'\'`}):\n ${3:# TODO: write code...}\n# New Method\nsnippet defs\n def ${1:mname}(self, ${2:arg}):\n ${3:# TODO: write code...}\n# New Property\nsnippet property\n def ${1:foo}():\n doc = "${2:The $1 property.}"\n def fget(self):\n ${3:return self._$1}\n def fset(self, value):\n ${4:self._$1 = value}\n# Ifs\nsnippet if\n if ${1:condition}:\n ${2:# TODO: write code...}\nsnippet el\n else:\n ${1:# TODO: write code...}\nsnippet ei\n elif ${1:condition}:\n ${2:# TODO: write code...}\n# For\nsnippet for\n for ${1:item} in ${2:items}:\n ${3:# TODO: write code...}\n# Encodes\nsnippet cutf8\n # -*- coding: utf-8 -*-\nsnippet clatin1\n # -*- coding: latin-1 -*-\nsnippet cascii\n # -*- coding: ascii -*-\n# Lambda\nsnippet ld\n ${1:var} = lambda ${2:vars} : ${3:action}\nsnippet .\n self.\nsnippet try Try/Except\n try:\n ${1:# TODO: write code...}\n except ${2:Exception}, ${3:e}:\n ${4:raise $3}\nsnippet try Try/Except/Else\n try:\n ${1:# TODO: write code...}\n except ${2:Exception}, ${3:e}:\n ${4:raise $3}\n else:\n ${5:# TODO: write code...}\nsnippet try Try/Except/Finally\n try:\n ${1:# TODO: write code...}\n except ${2:Exception}, ${3:e}:\n ${4:raise $3}\n finally:\n ${5:# TODO: write code...}\nsnippet try Try/Except/Else/Finally\n try:\n ${1:# TODO: write code...}\n except ${2:Exception}, ${3:e}:\n ${4:raise $3}\n else:\n ${5:# TODO: write code...}\n finally:\n ${6:# TODO: write code...}\n# if __name__ == \'__main__\':\nsnippet ifmain\n if __name__ == \'__main__\':\n ${1:main()}\n# __magic__\nsnippet _\n __${1:init}__${2}\n# python debugger (pdb)\nsnippet pdb\n import pdb; pdb.set_trace()\n# ipython debugger (ipdb)\nsnippet ipdb\n import ipdb; ipdb.set_trace()\n# ipython debugger (pdbbb)\nsnippet pdbbb\n import pdbpp; pdbpp.set_trace()\nsnippet pprint\n import pprint; pprint.pprint(${1})${2}\nsnippet "\n """\n ${1:doc}\n """\n# test function/method\nsnippet test\n def test_${1:description}(${2:self}):\n ${3:# TODO: write code...}\n# test case\nsnippet testcase\n class ${1:ExampleCase}(unittest.TestCase):\n \n def test_${2:description}(self):\n ${3:# TODO: write code...}\nsnippet fut\n from __future__ import ${1}\n#getopt\nsnippet getopt\n try:\n # Short option syntax: "hv:"\n # Long option syntax: "help" or "verbose="\n opts, args = getopt.getopt(sys.argv[1:], "${1:short_options}", [${2:long_options}])\n \n except getopt.GetoptError, err:\n # Print debug info\n print str(err)\n ${3:error_action}\n\n for option, argument in opts:\n if option in ("-h", "--help"):\n ${4}\n elif option in ("-v", "--verbose"):\n verbose = argument\n',t.scope="python"})

View File

@ -138,7 +138,7 @@ module.exports = function(RED) {
value = value.substring(0,debuglength)+"...";
}
} else if (value && value.constructor) {
if (value.constructor.name === "Buffer") {
if (value.type === "Buffer") {
value.__encoded__ = true;
value.length = value.data.length;
if (value.length > debuglength) {

View File

@ -75,12 +75,20 @@
<dt>payload <span class="property-type">string</span></dt>
<dd>the standard output of the command.</dd>
</dl>
<dl class="message-properties">
<dt>rc <span class="property-type">object</span></dt>
<dd>exec mode only, a copy of the return code object (also available on port 3)</dd>
</dl>
</li>
<li>Standard error
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the standard error of the command.</dd>
</dl>
<dl class="message-properties">
<dt>rc <span class="property-type">object</span></dt>
<dd>exec mode only, a copy of the return code object (also available on port 3)</dd>
</dl>
</li>
<li>Return code
<dl class="message-properties">

View File

@ -125,14 +125,15 @@ module.exports = function(RED) {
if (node.append.trim() !== "") { cl += " "+node.append; }
/* istanbul ignore else */
if (RED.settings.verbose) { node.log(cl); }
child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
child = exec(cl, {encoding:'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
var msg2, msg3;
delete msg.payload;
if (stderr) {
msg2 = RED.util.cloneMessage(msg);
msg2.payload = stderr;
}
msg.payload = Buffer.from(stdout,"binary");
if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); }
var msg2 = null;
if (stderr) {
msg2 = {payload: stderr};
}
var msg3 = null;
node.status({});
//console.log('[exec] stdout: ' + stdout);
//console.log('[exec] stderr: ' + stderr);
@ -142,10 +143,15 @@ module.exports = function(RED) {
if (error.code === null) { node.status({fill:"red",shape:"dot",text:"killed"}); }
else { node.status({fill:"red",shape:"dot",text:"error:"+error.code}); }
node.log('error:' + error);
} else if (node.oldrc === "false") {
}
else if (node.oldrc === "false") {
msg3 = {payload:{code:0}};
}
if (!msg3) { node.status({}); }
else {
msg.rc = msg3.payload;
if (msg2) { msg2.rc = msg3.payload; }
}
node.send([msg,msg2,msg3]);
if (child.tout) { clearTimeout(child.tout); }
delete node.activeProcesses[child.pid];

View File

@ -24,9 +24,10 @@ module.exports = function(RED) {
* Custom Mustache Context capable to resolve message property and node
* flow and global context
*/
function NodeContext(msg, nodeContext,parent) {
function NodeContext(msg, nodeContext, parent, escapeStrings) {
this.msgContext = new mustache.Context(msg,parent);
this.nodeContext = nodeContext;
this.escapeStrings = escapeStrings;
}
NodeContext.prototype = new mustache.Context();
@ -36,6 +37,14 @@ module.exports = function(RED) {
try {
var value = this.msgContext.lookup(name);
if (value !== undefined) {
if (this.escapeStrings && typeof value === "string") {
value = value.replace(/\\/g, "\\\\");
value = value.replace(/\n/g, "\\n");
value = value.replace(/\t/g, "\\t");
value = value.replace(/\r/g, "\\r");
value = value.replace(/\f/g, "\\f");
value = value.replace(/[\b]/g, "\\b");
}
return value;
}
@ -75,7 +84,11 @@ module.exports = function(RED) {
try {
var value;
if (node.syntax === "mustache") {
value = mustache.render(node.template,new NodeContext(msg, node.context()));
if (node.outputFormat === "json") {
value = mustache.render(node.template,new NodeContext(msg, node.context(), null, true));
} else {
value = mustache.render(node.template,new NodeContext(msg, node.context(), null, false));
}
} else {
value = node.template;
}

View File

@ -102,7 +102,7 @@
<dt class="optional">delay <span class="property-type">number</span></dt>
<dd>Sets the delay, in milliseconds, to be applied to the message. This
option only applies if the node is configured to allow the message to
provide the delay interval.</dd>
override the configured default delay interval.</dd>
<dt class="optional">reset</dt>
<dd>If the received message has this property set to any value, all
outstanding messages held by the node are cleared without being sent.</dd>
@ -260,7 +260,7 @@
$("#delay-details-for").show();
$("#random-details").hide();
} else if (this.value === "delayv") {
$("#delay-details-for").hide();
$("#delay-details-for").show();
$("#random-details").hide();
} else if (this.value === "random") {
$("#delay-details-for").hide();

View File

@ -105,7 +105,10 @@ module.exports = function(RED) {
}
else if (node.pauseType === "delayv") {
node.on("input", function(msg) {
var delayvar = Number(msg.delay || 0);
var delayvar = Number(node.timeout);
if (msg.hasOwnProperty("delay") && !isNaN(parseFloat(msg.delay))) {
delayvar = parseFloat(msg.delay);
}
if (delayvar < 0) { delayvar = 0; }
var id = setTimeout(function() {
node.idList.splice(node.idList.indexOf(id),1);
@ -113,7 +116,7 @@ module.exports = function(RED) {
node.send(msg);
}, delayvar);
node.idList.push(id);
if ((delayvar >= 1) && (node.idList.length !== 0)) {
if ((delayvar >= 0) && (node.idList.length !== 0)) {
node.status({fill:"blue",shape:"dot",text:delayvar/1000+"s"});
}
if (msg.hasOwnProperty("reset")) { clearDelayList(); }

View File

@ -92,7 +92,7 @@
<p>If set to a <i>string</i> type, the node supports the mustache template syntax.</p>
<p>If the node receives a message with a <code>reset</code> property, or a <code>payload</code>
that matches that configured in the node, any timeout or repeat currently in
progress will be cleared and no message triggered.</o>
progress will be cleared and no message triggered.</p>
<p>The node can be configured to resend a message at a regular interval until it
is reset by a received message.</p>
</script>

View File

@ -29,6 +29,7 @@ RED.debug = (function() {
var messagesByNode = {};
var sbc;
var activeWorkspace;
var numMessages = 100; // Hardcoded number of message to show in debug window scrollback
var filterVisible = false;
@ -369,9 +370,24 @@ RED.debug = (function() {
})
menuOptionMenu.show();
}
function handleDebugMessage(o) {
var msg = document.createElement("div");
var stack = [];
var busy = false;
function handleDebugMessage(o) {
if (o) { stack.push(o); }
if (!busy && (stack.length > 0)) {
busy = true;
processDebugMessage(stack.shift());
setTimeout(function() {
busy = false;
handleDebugMessage();
}, 15); // every 15mS = 66 times a second
if (stack.length > numMessages) { stack = stack.splice(-numMessages); }
}
}
function processDebugMessage(o) {
var msg = document.createElement("div");
var sourceNode = o._source;
msg.onmouseenter = function() {
@ -497,7 +513,7 @@ RED.debug = (function() {
}
}
if (messages.length === 100) {
if (messages.length === numMessages) {
m = messages.shift();
if (view === "list") {
m.el.remove();
@ -511,7 +527,6 @@ RED.debug = (function() {
return {
init: init,
refreshMessageList:refreshMessageList,
handleDebugMessage: handleDebugMessage,
handleDebugMessage: handleDebugMessage
}
})();

View File

@ -205,7 +205,7 @@
"for": "For",
"delaymsg": "Delay each message",
"delayfixed": "Fixed delay",
"delayvarmsg": "Set delay with msg.delay",
"delayvarmsg": "Override delay with msg.delay",
"randomdelay": "Random delay",
"limitrate": "Rate Limit",
"limitall": "All messages",

View File

@ -0,0 +1,846 @@
{
"common": {
"label": {
"payload": "内容",
"topic": "主题",
"name": "名称",
"username": "用户名",
"password": "密码"
},
"status": {
"connected": "已连接",
"not-connected": "未连接",
"disconnected": "已断开",
"connecting": "连接中",
"error": "错误",
"ok": "确认"
},
"notification": {
"error": "<strong>错误</strong>: __message__",
"errors": {
"not-deployed": "节点未部署",
"no-response": "服务器无反应",
"unexpected": "发生意外错误 (__status__) __message__"
}
},
"errors": {
"nooverride": "警告: 信息的属性已经不可以改写节点的属性. 详情参考 bit.ly/nr-override-msg-props"
}
},
"inject": {
"inject": "注入",
"repeat": "重复 = __repeat__",
"crontab": "crontab = __crontab__",
"stopped": "停止",
"failed": "注入失败: __error__",
"label": {
"repeat": "重复"
},
"timestamp": "时间戳",
"none": "空白",
"interval": "间隔",
"interval-time": "特定时间内间隔",
"time": "特定时间",
"seconds": "秒",
"minutes": "分钟",
"hours": "小时",
"between": "介于",
"previous": "之前数值",
"at": "在",
"and": "之间",
"every": "每个",
"days": [
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期天"
],
"on": "在",
"onstart": "运行时注入?",
"tip": "<b>注意:</b> \"特定时间内间隔\" 和 \"特定时间\" 会用cron系统.<br/> 详情擦看信息页.",
"success": "成功注入: __label__",
"errors": {
"failed": "注入失败, 请查看日志"
}
},
"catch": {
"catch": "检测异常",
"catchNodes": "检测到 (__number__)",
"label": {
"source": "检测错误来自",
"node": "节点",
"type": "类型",
"selectAll": "全选",
"sortByLabel": "按名称排序",
"sortByType": "按类型排序"
},
"scope": {
"all": "所有节点",
"selected": "已选节点"
}
},
"status": {
"status": "状态 (所有)",
"statusNodes": "状态显示 (__number__)",
"label": {
"source": "状态报告来自",
"node": "节点",
"type": "类型",
"selectAll": "全选",
"sortByLabel": "按名称排序",
"sortByType": "按类型排序"
},
"scope": {
"all": "所有节点",
"selected": "已选节点"
}
},
"debug": {
"output": "输出",
"msgprop": "信息属性",
"msgobj": "完整信息",
"to": "目标",
"debtab": "调试窗口",
"tabcon": "调试窗口及终端控制台",
"notification": {
"activated": "成功激活: __label__",
"deactivated": "成功取消: __label__"
},
"sidebar": {
"label": "调试窗口",
"name": "名称",
"filterAll": "所有节点",
"filterSelected": "已选节点",
"filterCurrent": "目前流程",
"debugNodes": "调试节点",
"clearLog": "清理日志",
"openWindow": "在新窗口打开"
},
"messageMenu": {
"collapseAll": "折叠所有路径",
"clearPinned": "清理已固定路径",
"filterNode": "过滤此节点",
"clearFilter": "清除已设过滤"
}
},
"link": {
"linkIn": "连接入口",
"linkOut": "连接出口",
"label": {
"event": "事件名称",
"node": "节点名称",
"type": "流程",
"sortByFlow":"根据流程排序",
"sortByLabel": "根据名称排序"
}
},
"tls": {
"tls": "TLS设置",
"label": {
"use-local-files": "使用本地密匙及证书文件",
"upload": "上传",
"cert": "证书",
"key": "私钥",
"ca": "CA证书",
"verify-server-cert":"验证服务器证书"
},
"placeholder": {
"cert":"证书路径 (PEM 格式)",
"key":"私匙路径 (PEM 格式)",
"ca":"CA证书路径 (PEM 格式)"
},
"error": {
"missing-file": "无证书/密匙文件提供"
}
},
"exec": {
"label": {
"command": "命令",
"append": "追加",
"timeout": "超时",
"timeoutplace": "可选填",
"return": "输出",
"seconds": "秒"
},
"placeholder": {
"extraparams": "额外的输入参数"
},
"opt": {
"exec": "当命令任务完成时 - exec 模式",
"spawn": "当命令任务进行时 - spawn 模式"
},
"oldrc": "使用旧式输出模式 (传统模式)"
},
"function": {
"label": {
"function": "函数",
"outputs": "输出"
},
"error": {
"inputListener":"无法在函数里面加入对‘注入’事件的监视",
"non-message-returned":"函数节点尝试返回类型为 __type__ 的信息"
},
"tip": "可从信息页面查看更多关于如何编写函数的帮助"
},
"template": {
"label": {
"template": "模版",
"property": "设定属性",
"format": "语法高亮",
"syntax": "格式",
"output": "输出为",
"mustache": "Mustache 模版",
"plain": "纯文本",
"json": "解析JSON",
"none": "无"
},
"templatevalue": "This is the payload: {{payload}} !"
},
"delay": {
"action": "行为设置",
"for": "时长",
"delaymsg": "延迟每一条信息",
"delayfixed": "固定延迟时间",
"delayvarmsg": "用 msg.delay 改写延迟时长",
"randomdelay": "随机延迟",
"limitrate": "信息速度限制",
"limitall": "所有信息",
"limittopic": "每一个 msg.topic",
"fairqueue": "轮流发每一个主题",
"timedqueue": "发所有主题",
"milisecs": "毫秒",
"secs": "秒",
"sec": "秒",
"mins": "分",
"min": "分",
"hours": "小时",
"hour": "小时",
"days": "日",
"day": "日",
"between": "介于",
"and": "和",
"rate": "速度",
"msgper": "信息 每",
"dropmsg": "不传输中间信息",
"label": {
"delay": "延迟",
"variable": "变量",
"limit": "限制",
"limitTopic": "限制主题",
"random": "随机",
"units" : {
"second": {
"plural" : "秒",
"singular": "秒"
},
"minute": {
"plural" : "分钟",
"singular": "分钟"
},
"hour": {
"plural" : "小时",
"singular": "小时"
},
"day": {
"plural" : "日",
"singular": "日"
}
}
},
"error": {
"buffer": "缓冲超过了 1000 条信息",
"buffer1": "缓冲超过了 10000 条信息"
}
},
"trigger": {
"send": "发送",
"then": "然后",
"then-send": "然后发送",
"output": {
"string": "字符串",
"number": "数字",
"existing": "现有信息对象",
"original": "原本信息对象",
"latest": "最新信息对象",
"nothing": "无"
},
"wait-reset": "等待至重置",
"wait-for": "等待",
"wait-loop": "重发每",
"duration": {
"ms": "毫秒",
"s": "秒",
"m": "分钟",
"h": "小时"
},
"extend": " 如有新信息,延长延迟",
"label": {
"trigger": "触发",
"trigger-block": "出发并阻止",
"trigger-loop": "重发每",
"reset": "重置触发节点条件 如果:",
"resetMessage":"msg.reset 已设置",
"resetPayload":"msg.payload 等于",
"resetprompt": "可选填"
}
},
"comment": {
"label": {
"title": "标题",
"body": "主体"
},
"tip": "提示: 主题内容可以添加格式化为 <a href=\"https://help.github.com/articles/markdown-basics/\" target=\"_blank\">Github 风格 Markdown</a>"
},
"unknown": {
"label": {
"unknown": "未知"
},
"tip": "<p>此节点是您安装但Node-RED所不知道的类型。</p><p><i>如果在此状态下部署节点,那么它的配置将被保留,但是流程将不会启动,直到安装缺少的类型。</i></p><p>有关更多帮助,请参阅信息侧栏</p>"
},
"mqtt": {
"label": {
"broker": "服务端",
"example": "e.g. localhost",
"qos": "QoS",
"clientid": "客户端ID",
"port": "端口",
"keepalive": "存货定时器(秒)",
"cleansession": "使用新的会话",
"use-tls": "使用安全连接 (SSL/TLS)",
"tls-config":"TLS 设置",
"verify-server-cert":"验证服务器证书",
"compatmode": "使用旧式 MQTT 3.1 支持"
},
"tabs-label": {
"connection": "连接",
"security": "安全",
"will": "终结信息",
"birth": "初始信息"
},
"placeholder": {
"clientid": "留空白将会自动生成",
"clientid-nonclean":"如非新会话必须设置客户端ID",
"will-topic": "留空白将禁止终止信息",
"birth-topic": "留空白将禁止初始信息"
},
"state": {
"connected": "已连接到服务端: __broker__",
"disconnected": "已断开与服务端 __broker__ 的链接",
"connect-failed": "与服务端 __broker__ 的连接失败"
},
"retain": "保留",
"true": "是",
"false": "否",
"tip": "提示: 如果你想用msg属性来设置主题qos 或者是否保存,请将这几个区域留空",
"errors": {
"not-defined": "主题未设置",
"missing-config": "未设置服务端",
"invalid-topic": "主题无效",
"nonclean-missingclientid": "客户端ID未设定使用新会话"
}
},
"httpin": {
"label": {
"method": "方法",
"url": "URL",
"doc": "文档",
"return": "返回",
"upload": "接受文件上传?",
"status": "状态码",
"headers": "头子段",
"other": "其他"
},
"setby": "- 用 msg.method 设定 -",
"basicauth": "基本认证",
"use-tls": "使用安全连接 (SSL/TLS) ",
"tls-config":"TLS 设置",
"utf8": "UTF-8 字符串",
"binary": "二进制缓冲模块",
"json": "解析JSON对象",
"tip": {
"in": "相对URL",
"res": "发送到此节点的消息<b>必须</b>来自 <i>http input</i> 节点",
"req": "提示如果JSON解析失败则获取的字符串将按原样返回."
},
"httpreq": "http 请求",
"errors": {
"not-created": "当httpNodeRoot为否时无法创建 http-in 节点",
"missing-path": "无路径",
"no-response": "无响应对象",
"json-error": "JSON 解析错误",
"no-url": "未设定 URL",
"deprecated-call":"__method__ 方法已弃用",
"invalid-transport":"非HTTP传输请求"
},
"status": {
"requesting": "请求中"
}
},
"websocket": {
"label": {
"type": "类型",
"path": "路径",
"url": "URL"
},
"listenon": "监听",
"connectto": "连接",
"payload": "发送/接受 有效载荷",
"message": "发送/接受 完整信息",
"tip": {
"path1": "默认情况下,<code> payload </code>将包含要发送或从Websocket接收的数据。侦听器可以配置为以JSON格式的字符串发送或接收整个消息对象.",
"path2": "这条路径将相对于 ",
"url1": "URL 应该使用 ws:&#47;&#47; 或者 wss:&#47;&#47; 方案并指向现有的websocket侦听器.",
"url2": "默认情况下,<code> payload </code>将包含要发送或从Websocket接收的数据。可以将客户端配置为以JSON格式的字符串发送或接收整个消息对象."
},
"errors": {
"connect-error": "ws连接发生了错误: ",
"send-error": "发送时发生了错误: ",
"missing-conf": "未设置服务器"
}
},
"watch": {
"label": {
"files": "文件(s)",
"recursive": "递归查看文件夹"
},
"placeholder": {
"files": "逗号分开文件或文件夹"
},
"tip": "在Windows上请务必使用双斜杠 \\\\ 来隔开文件夹名字"
},
"tcpin": {
"label": {
"type": "类型",
"output": "输出",
"port": "端口",
"host": "主服务器",
"payload": "有效载荷(s)",
"delimited": "分隔符号",
"close-connection": "是否在成功发送每条信息后断开连接?",
"decode-base64": "用 Base64 解码信息?",
"server": "服务器",
"return": "返回",
"ms": "毫秒",
"chars": "字符"
},
"type": {
"listen": "监听",
"connect": "连接",
"reply": "回应到 TCP"
},
"output": {
"stream": "字串流",
"single": "单一",
"buffer": "缓冲模块",
"string": "字符串",
"base64": "Base64 字符串"
},
"return": {
"timeout": "在固定时间超时后",
"character": "当收到某个字符时",
"number": "固定数目的字符",
"never": "永不 - 保持连接",
"immed": "马上 - 不需要等待回复"
},
"status": {
"connecting": "正在连接到 __host__:__port__",
"connected": "已经连接到 __host__:__port__",
"listening-port": "监听端口 __port__",
"stopped-listening": "已停止监听端口",
"connection-from": "连接来自 __host__:__port__",
"connection-closed": "连接已关闭 __host__:__port__",
"connections": "__count__ 段连接",
"connections_plural": "__count__ 段连接"
},
"errors": {
"connection-lost": "连接中断 __host__:__port__",
"timeout": "超时关闭套接字连接,端口 __port__",
"cannot-listen": "无法监听端口 __port__, 错误: __error__",
"error": "错误: __error__",
"socket-error": "套接字连接错误来自 __host__:__port__",
"no-host": "主服务器和/或者端口未设定",
"connect-timeout": "连接超时",
"connect-fail": "连接失败"
}
},
"udp": {
"label": {
"listen": "监听",
"onport": "端口",
"using": "使用",
"output": "输出",
"group": "组",
"interface": "本地IP",
"interfaceprompt": "(可选填)本地 IP 绑定到",
"send": "发送一个",
"toport": "到端口",
"address": "地址",
"decode-base64": "是否解码编码为Base64的信息?"
},
"placeholder": {
"interface": "可选填eth0 的 ip 地址",
"address": "目的地 ip 地址"
},
"udpmsgs": "udp 信息",
"mcmsgs": "组播信息",
"udpmsg": "udp 信息",
"bcmsg": "广播信息",
"mcmsg": "组播信息",
"output": {
"buffer": "缓冲模块",
"string": "字符串",
"base64": "Base64编码字符串"
},
"bind": {
"random": "绑定到任意本地端口",
"local": "绑定到本地端口",
"target": "绑定到目标端口"
},
"tip": {
"in": "提示:确保您的防火墙将允许数据进入",
"out": "提示:如果要使用<code> msg.ip </code>和<code> msg.port </code>设置,请将地址和端口留空",
"port": "端口已在使用: "
},
"status": {
"listener-at": "udp 监听器正在监听 __host__:__port__",
"mc-group": "udp 组播到 __group__",
"listener-stopped": "udp 监听器已停止",
"output-stopped": "udp 输出已停止",
"mc-ready": "udp 组播已准备好: __outport__ -> __host__:__port__",
"bc-ready": "udp 广播已准备好: __outport__ -> __host__:__port__",
"ready": "udp 已准备好: __outport__ -> __host__:__port__",
"ready-nolocal": "udp 已准备好: __host__:__port__"
},
"errors": {
"access-error": "UDP 访问错误, 你可能需要root权限才能接入1024以下的端口",
"error": "错误: __error__",
"bad-mcaddress": "无效的组播地址",
"interface": "必须是需要接口的 ip 地址",
"ip-notset": "udp: ip 地址未设定",
"port-notset": "udp: 端口未设定",
"port-invalid": "udp: 无效端口号码",
"alreadyused": "udp: 端口已经在使用"
}
},
"switch": {
"label": {
"property": "属性",
"rule": "规矩"
},
"and": "和",
"checkall": "全选所有规则",
"stopfirst": "接受第一条匹配信息后停止",
"ignorecase": "忽视大小写",
"rules": {
"btwn":"在之间",
"cont":"包含",
"regex":"匹配正则表达式",
"true":"为真",
"false":"为假",
"null":"为空值",
"nnull":"非空值",
"else":"除此以外"
},
"errors": {
"invalid-expr": "无效 JSONata 表达: __error__"
}
},
"change": {
"label": {
"rules": "规矩",
"rule": "规矩",
"set": "设定 __property__",
"change": "改变 __property__",
"delete": "删除 __property__",
"move": "移动 __property__",
"changeCount": "改变: __count__ 条规矩",
"regex": "用正则表达式"
},
"action": {
"set": "设定",
"change": "更改",
"delete": "删除",
"move": "转移",
"to": "到",
"search": "搜索",
"replace": "更改为"
},
"errors": {
"invalid-from": "无效来源 from 属性: __error__",
"invalid-json": "无效 to 属性",
"invalid-expr": "无效 JSONata 表示: __error__"
}
},
"range": {
"label": {
"action": "行为作用",
"inputrange": "映射输入数据范围",
"resultrange": "至目标范围",
"from": "从",
"to": "到",
"roundresult": "取最接近整数?"
},
"placeholder": {
"min": "e.g. 0",
"maxin": "e.g. 99",
"maxout": "e.g. 255"
},
"scale": {
"payload": "按比例 msg.payload",
"limit": "按比例并设定界限至目标范围",
"wrap": "按比例并包含在目标范围内"
},
"tip": "提示: 此节点仅对数字有效",
"errors": {
"notnumber": "不是一个数"
}
},
"csv": {
"label": {
"columns": "列",
"separator": "分隔符号",
"c2o": "CSV 至对象选项",
"o2c": "对象至 to CSV 选项",
"input": "输入",
"firstrow": "第一行包含列名",
"output": "输出",
"includerow": "包含列名行",
"newline": "新的一行"
},
"placeholder": {
"columns": "用逗号分割列名"
},
"separator": {
"comma": "逗号",
"tab": "Tab",
"space": "空格",
"semicolon": "分号",
"colon": "冒号",
"hashtag": "井号",
"other": "其他..."
},
"output": {
"row": "每行包含一条信息",
"array": "一条单独信息 [数组]"
},
"newline": {
"linux": "Linux (\\n)",
"mac": "Mac (\\r)",
"windows": "Windows (\\r\\n)"
},
"errors": {
"csv_js": "此节点仅处理 CSV 字符串或 js 对象",
"obj_csv": "对象 -> CSV 转换未设定列模版"
}
},
"html": {
"label": {
"select": "选取项",
"output": "输出"
},
"output": {
"html": "选定元素的 html 内容",
"text": "选定元素的纯文本内容",
"attr": "选定元素的所有属性对象"
},
"format": {
"single": "由一个单独信息包含一个数组",
"multi": "由多条信息,每一条包含一个元素"
}
},
"json": {
"errors": {
"dropped-object": "忽略非对象格式的有效负载",
"dropped": "忽略不支持格式的有效负载类型",
"dropped-error": "转换有效负载失败"
},
"label": {
"o2j": "对象至 JSON 选项",
"pretty": "格式化 JSON 字符串"
}
},
"yaml": {
"errors": {
"dropped-object": "忽略非对象格式的有效负载",
"dropped": "忽略不支持格式的有效负载类型",
"dropped-error": "转换有效负载失败"
}
},
"xml": {
"label": {
"represent": "XML标签属性的属性名称",
"prefix": "标签文本内容的属性名称",
"advanced": "高级选项",
"x2o": "XML到对象选项"
},
"errors": {
"xml_js": "此节点仅处理XML字符串或JS对象."
}
},
"rpi-gpio": {
"label": {
"gpiopin": "GPIO",
"selectpin": "选择引脚",
"resistor": "电阻?",
"readinitial": "在部署/重新启动时读取引脚的初始状态?",
"type": "类型",
"initpin": "初始化引脚状态?",
"debounce": "去抖动",
"freq": "频率",
"button": "按钮",
"pimouse": "Pi 鼠标",
"pikeyboard": "Pi 键盘",
"left": "左",
"right": "右",
"middle": "中"
},
"resistor": {
"none": "无",
"pullup": "上拉电阻",
"pulldown": "下拉电阻"
},
"digout": "数字输出",
"pwmout": "PWM 输出",
"servo": "伺服输出",
"initpin0": "初始引脚电平 - 低 (0)",
"initpin1": "初始引脚电平 - 高 (1)",
"left": "左",
"right": "右",
"middle": "中",
"any": "任何",
"pinname": "引脚",
"alreadyuse": "已经在用",
"alreadyset": "已经设定为",
"tip": {
"pin": "<b>引脚在使用</b>: ",
"in": "提示: 仅接受数字输入 - 输出必须为 0 或 1.",
"dig": "提示: 如用数字输出 - 输入必须为 0 或 1.",
"pwm": "提示: 如用PWM输出 - 输入必须为0至100之间; 如用高频率可能会比预期占用更多CPU资源.",
"ser": "<b>提示</b>: 如用伺服输出 - 输入必须为0至100之间. 50为中间值."
},
"types": {
"digout": "数字输出",
"input": "输入",
"pullup": "含有上拉电阻的输入",
"pulldown": "含有下拉电阻的输入",
"pwmout": "PWM 输出",
"servo": "伺服输出"
},
"status": {
"stopped": "已停止",
"closed": "已关闭",
"not-running": "不运行"
},
"errors": {
"ignorenode": "忽略树莓派的特定节点",
"version": "版本命令失败",
"sawpitype": "查看Pi类型",
"libnotfound": "找不到树莓派 RPi.GPIO python库",
"alreadyset": "GPIO 引脚 __pin__ 已经被设定为类型: __type__",
"invalidpin": "无效 GPIO 引脚",
"invalidinput": "无效输入",
"needtobeexecutable": "__command__ 需要为可运行命令",
"mustbeexecutable": "nrgpio 需要为可运行",
"commandnotfound": "nrgpio 命令不存在",
"commandnotexecutable": "nrgpio 命令无法运行",
"error": "错误: __error__",
"pythoncommandnotfound": "nrpgio python 命令不运行"
}
},
"tail": {
"label": {
"filename": "文件名",
"type": "文件类型",
"splitlines": "拆分线 \\n?"
},
"action": {
"text": "文本 - 返回字符串",
"binary": "二进制 - 返回缓冲区"
},
"errors": {
"windowsnotsupport": "Windows目前不支持."
}
},
"file": {
"label": {
"filename": "文件名",
"action": "行为",
"addnewline": "向每个有效载荷添加换行符(\\ n?",
"createdir": "创建目录(如果不存在)?",
"outputas": "输出",
"breakchunks": "分拆成块",
"breaklines": "分拆成行",
"filelabel": "文件",
"sendError": "发生错误时发送消息(传统模式)",
"deletelabel": "删除 __file__"
},
"action": {
"append": "追加至文件",
"overwrite": "改写文件",
"delete": "删除文件"
},
"output": {
"utf8": "一条单独 utf8 字符串",
"buffer": "一条单独缓冲区对象",
"lines": "每行一条信息",
"stream": "缓冲区流"
},
"status": {
"wrotefile": "写入至文件: __file__",
"deletedfile": "删除文件: __file__",
"appendedfile": "追加至文件: __file__"
},
"errors": {
"nofilename": "未指定文件名",
"invaliddelete": "警告:无效删除。请在配置对话框中使用特定的删除选项",
"deletefail": "无法删除文件: __error__",
"writefail": "无法写入文件: __error__",
"appendfail": "无法追加到文件: __error__",
"createfail": "文件创建失败: __error__"
},
"tip": "提示: 文件名应该是绝对路径否则它将相对于Node-RED进程的工作目录。"
},
"split": {
"intro":"分裂 <code>msg.payload</code> 基于类型:",
"object":"<b>对象</b>",
"objectSend":"发送每个键/值对的消息",
"strBuff":"<b>字符串</b> / <b>缓冲区</b>",
"array":"<b>数组</b>",
"splitUsing":"拆分使用",
"splitLength":"固定长度",
"stream":"处理为消息流",
"addname":" 复制键到 "
},
"join":{
"mode":{
"mode":"模式",
"auto":"自动",
"custom":"手动"
},
"combine":"结合每一个",
"create":"创建输出",
"type":{
"string":"字符串",
"array":"数组",
"buffer":"缓冲区",
"object":"键/值对象",
"merged":"合并对象"
},
"using":"使用数值",
"key":"当作键",
"joinedUsing":"合并符号",
"send":"发送信息:",
"afterCount":"当达到一定数目的信息部件时",
"count":"数目",
"subsequent":"和每个后续的消息",
"afterTimeout":"第一条消息的超时后",
"seconds":"秒",
"complete":"在使用<code> msg.complete </ code>属性设置的消息后",
"tip":"此模式假定此节点与 <i>split</i> 或者接收到的消息将具有正确配置的 <code>msg.parts</code> 属性."
}
}

View File

@ -29,7 +29,7 @@
<dt>Delete</dt>
<dd>delete a property.</dd>
<dt>Move</dt>
<dd>move or rename a property.</dt>
<dd>move or rename a property.</dd>
</dl>
<p>The "expression" type uses the <a href="http://jsonata.org/" target="_new">JSONata</a>
query and expression language.

View File

@ -129,9 +129,9 @@ module.exports = function(RED) {
if (rule.fromt === 'msg' || rule.fromt === 'flow' || rule.fromt === 'global') {
if (rule.fromt === "msg") {
fromValue = RED.util.getMessageProperty(msg,rule.from);
} else if (rule.tot === 'flow') {
} else if (rule.fromt === 'flow') {
fromValue = node.context().flow.get(rule.from);
} else if (rule.tot === 'global') {
} else if (rule.fromt === 'global') {
fromValue = node.context().global.get(rule.from);
}
if (typeof fromValue === 'number' || fromValue instanceof Number) {
@ -201,7 +201,7 @@ module.exports = function(RED) {
} else if (rule.t === 'set') {
target.set(property,value);
} else if (rule.t === 'change') {
current = target.get(msg,property);
current = target.get(property);
if (typeof current === 'string') {
if ((fromType === 'num' || fromType === 'bool' || fromType === 'str') && current === fromValue) {
// str representation of exact from number/boolean

View File

@ -54,7 +54,7 @@
<dt>payload<span class="property-type">object | string | array | buffer</span></dt>
<dd>The behaviour of the node is determined by the type of <code>msg.payload</code>:
<ul>
<li><b>string</b>/<b>buffer</b> - the message is split using the specified character (default: <code>\n</code>), buffer sequence or into fixed lengths.
<li><b>string</b>/<b>buffer</b> - the message is split using the specified character (default: <code>\n</code>), buffer sequence or into fixed lengths.</li>
<li><b>array</b> - the message is split into either individual array elements, or arrays of a fixed-length.</li>
<li><b>object</b> - a message is sent for each key/value pair of the object.</li>
</ul>

View File

@ -300,6 +300,9 @@ module.exports = function(RED) {
}
RED.util.setMessageProperty(group.msg,node.property,group.payload.join(groupJoinChar));
} else {
if (node.propertyType === 'full') {
group.msg = RED.util.cloneMessage(group.msg);
}
RED.util.setMessageProperty(group.msg,node.property,group.payload);
}
if (group.msg.hasOwnProperty('parts') && group.msg.parts.hasOwnProperty('parts')) {

View File

@ -78,9 +78,11 @@ module.exports = function(RED) {
}
ou = "";
for (var p in msg.payload[0]) {
/* istanbul ignore else */
if (msg.payload[0].hasOwnProperty(p)) {
/* istanbul ignore else */
if (typeof msg.payload[0][p] !== "object") {
var q = msg.payload[0][p];
var q = "" + msg.payload[0][p];
if (q.indexOf(node.quo) !== -1) { // add double quotes if any quotes
q = q.replace(/"/g, '""');
ou += node.quo + q + node.quo + node.sep;
@ -100,9 +102,8 @@ module.exports = function(RED) {
ou += node.sep;
}
else {
// aaargh - resorting to eval here - but fairly contained front and back.
var p = RED.util.ensureString(eval("msg.payload[s]."+node.template[t]));
var p = RED.util.ensureString(RED.util.getMessageProperty(msg,"payload["+s+"]['"+node.template[t]+"']"));
/* istanbul ignore else */
if (p === "undefined") { p = ""; }
if (p.indexOf(node.quo) !== -1) { // add double quotes if any quotes
p = p.replace(/"/g, '""');

View File

@ -89,7 +89,7 @@ function login(req,res) {
} else if (settings.adminAuth.type === "strategy") {
response = {
"type":"strategy",
"prompts":[{type:"button",label:settings.adminAuth.strategy.label, url:"/auth/strategy"}]
"prompts":[{type:"button",label:settings.adminAuth.strategy.label, url: settings.httpAdminRoot + "auth/strategy"}]
}
if (settings.adminAuth.strategy.icon) {
response.prompts[0].icon = settings.adminAuth.strategy.icon;
@ -186,12 +186,12 @@ module.exports = {
adminApp.get('/auth/strategy', passport.authenticate(strategy.name));
adminApp.get('/auth/strategy/callback',
passport.authenticate(strategy.name, {session:false, failureRedirect: '/' }),
passport.authenticate(strategy.name, {session:false, failureRedirect: settings.httpAdminRoot }),
function(req, res) {
var tokens = req.user.tokens;
delete req.user.tokens;
// Successful authentication, redirect home.
res.redirect('/?access_token='+tokens.accessToken);
res.redirect(settings.httpAdminRoot + '?access_token='+tokens.accessToken);
}
);

View File

@ -429,8 +429,10 @@
},
"expressionEditor": {
"functions": "Functions",
"functionReference": "Function reference",
"insert": "Insert",
"title": "JSONata Expression editor",
"test": "Test",
"data": "Example message",
"result": "Result",
"format": "format expression",

View File

@ -423,11 +423,13 @@
},
"expressionEditor": {
"functions": "関数",
"functionReference": "関数リファレンス",
"insert": "挿入",
"title": "JSONata式エディタ",
"test": "テスト",
"data": "メッセージ例",
"result": "結果",
"format": "",
"format": "形",
"compatMode": "互換モードが有効になっています",
"compatModeDesc": "<h3>JSONata互換モード</h3><p> 入力された式では <code>msg</code> を参照しているため、互換モードで評価します。このモードは将来廃止予定のため、式で <code>msg</code> を使わないよう修正してください。</p><p> JSONataをNode-REDで最初にサポートした際には、 <code>msg</code> オブジェクトの参照が必要でした。例えば <code>msg.payload</code> がペイロードを参照するために使われていました。</p><p> 直接メッセージに対して式を評価するようになったため、この形式は使えなくなります。ペイロードを参照するには、単に <code>payload</code> にしてください。</p>",
"noMatch": "一致した結果なし",

View File

@ -95,6 +95,10 @@
"args": "",
"desc": "0以上、1未満の疑似乱数を返します。"
},
"$millis": {
"args": "",
"desc": "Unixエポック(1 January, 1970 UTC)からの経過ミリ秒を数値として返します。評価対象式に含まれる `$millis()` の呼び出しは、全て同じ値を返します。"
},
"$sum": {
"args": "array",
"desc": "数値の配列 `array` の合計値を返します。 `array` が数値でない要素を含む場合、エラーになります。"
@ -159,6 +163,10 @@
"args": "object",
"desc": "key/valueのペアを持つオブジェクトを、各要素が1つのkey/valueのペアを持つオブジェクトの配列に分割します。引数がオブジェクトの配列の場合、結果の配列は各オブジェクトから得た各key/valueのペアのオブジェクトを持ちます。"
},
"$merge": {
"args": "array&lt;object&gt;",
"desc": "`object` の配列を1つの `object` へマージします。 マージ結果のオブジェクトは入力配列内の各オブジェクトのkey/valueペアを含みます。入力のオブジェクトが同じキーを持つ場合、戻り値の `object` には配列の最後のオブジェクトのkey/value値が格納されます。入力の配列がオブジェクトでない要素を含む場合、エラーとなります。"
},
"$sift": {
"args": "object, function",
"desc": "引数 `object` が持つkey/valueのペアのうち、関数 `function` によってふるい分けたオブジェクトのみを返します。\n\n関数 `function` は、以下の引数を持つ必要があります。\n\n`function(value [, key [, object]])`"

View File

@ -2,7 +2,7 @@
"common": {
"label": {
"name": "姓名",
"ok": "Ok",
"ok": "确认",
"done": "完成",
"cancel": "取消",
"delete": "删除",
@ -28,8 +28,8 @@
"menu": {
"label": {
"view": {
"view": "示",
"showGrid": "示网格",
"view": "示",
"showGrid": "示网格",
"snapGrid": "对齐网格",
"gridSize": "网格尺寸",
"textDir": "文本方向",
@ -42,7 +42,7 @@
"show": "显示侧边栏"
},
"userSettings": "设定",
"displayStatus": "示节点状态",
"displayStatus": "示节点状态",
"displayConfig": "配置节点设定",
"import": "导入",
"export": "导出",
@ -256,7 +256,7 @@
"social": "社交",
"storage": "存储",
"analysis": "分析",
"advanced": "高级"
"advanced": "高级"
},
"event": {
"nodeAdded": "添加到面板中的节点:",
@ -381,7 +381,7 @@
"str": "文字列",
"num": "数字",
"re": "正则表达式",
"bool": "真伪判断",
"bool": "布尔",
"json": "JSON",
"date": "时间戳"
}

View File

@ -0,0 +1,23 @@
{
"info": {
"tip0" : "您可以用 {{core:delete-selection}} 删除选择的节点或链接。",
"tip1" : "{{core:search}} 可以在流程内搜索节点。",
"tip2": "{{core:toggle-sidebar}} 可以显示或隐藏边栏。",
"tip3": "您可以在 {{core:manage-palette}} 中管理节点的控制面板。",
"tip4": "边栏中会列出流程中所有的配置节点。您可以通过菜单或者 {{core:show-config-tab}} 来访问这些节点。",
"tip5": "您可以在设定中选择显示或隐藏这些提示。",
"tip6": "您可以用[left] [up] [down] [right]键来移动被选中的节点。按住[shift]可以更快地移动节点。",
"tip7": "把节点拖到连接上可以向连接中插入节点。",
"tip8": "您可以用 {{core:show-export-dialog}} 来导出被选中的节点或标签页中的流程。",
"tip9": "您可以将流程的json文件拖入编辑框或 {{core:show-import-dialog}} 来导入流程。",
"tip10": "按住[shift]后单击并拖动节点可以将该节点的多个连接一并移动到其他节点的端口。",
"tip11": "{{core:show-info-tab}} 可以显示「信息」标签页。 {{core:show-debug-tab}} 可以显示「调试」标签页。",
"tip12": "按住[ctrl]的同时点击工作界面可以在节点的对话栏中快速添加节点。",
"tip13": "按住[ctrl]的同时点击节点的端口或后续节点可以快速连接多个节点。",
"tip14": "按住[shift]的同时点击节点会选中所有被连接的节点。",
"tip15": "按住[ctrl]的同时点击节点可以在选中或取消选中节点。",
"tip16": "{{core:show-previous-tab}} 和 {{core:show-next-tab}} 可以切换标签页。",
"tip17": "您可以在节点的属性配置画面中通过 {{core:confirm-edit-tray}} 来更改设置,或者用 {{core:cancel-edit-tray}} 来取消更改。",
"tip18": "您可以通过点击 {{core:edit-selected-node}} 来显示被选中节点的属性设置画面。"
}
}

View File

@ -97,6 +97,7 @@ module.exports = {
settings:runtime.settings,
util: runtime.util,
version: runtime.version,
events: runtime.events,
comms: api.comms,
library: api.library,

View File

@ -137,7 +137,8 @@
"empty": "Existing __type__ file is empty",
"invalid": "Existing __type__ file is not valid json",
"restore": "Restoring __type__ file backup : __path__",
"restore-fail": "Restoring __type__ file backup failed : __message__"
"restore-fail": "Restoring __type__ file backup failed : __message__",
"fsync-fail": "Flushing file __path__ to disk failed : __message__"
}
}
}

View File

@ -28,7 +28,14 @@ function createContext(id,seed) {
util.setMessageProperty(data,key,value);
}
obj.keys = function() {
return Object.keys(data);
var keysData = Object.keys(data);
if (seed == null) {
return keysData;
} else {
return keysData.filter(function (key) {
return key !== "set" && key !== "get" && key !== "keys";
});
}
}
return obj;
}

View File

@ -114,8 +114,13 @@ function writeFile(path,content) {
return when.promise(function(resolve,reject) {
var stream = fs.createWriteStream(path);
stream.on('open',function(fd) {
stream.end(content,'utf8',function() {
fs.fsync(fd,resolve);
stream.write(content,'utf8',function() {
fs.fsync(fd,function(err) {
if (err) {
log.warn(log._("storage.localfilesystem.fsync-fail",{path: path, message: err.toString()}));
}
stream.end(resolve);
});
});
});
stream.on('error',function(err) {

View File

@ -78,7 +78,7 @@ module.exports = {
//nodesDir: '/home/nol/.node-red/nodes',
// By default, the Node-RED UI is available at http://localhost:1880/
// The following property can be used to specifiy a different root path.
// The following property can be used to specify a different root path.
// If set to false, this is disabled.
//httpAdminRoot: '/admin',

View File

@ -100,6 +100,34 @@ describe('debug node', function() {
});
});
it('should publish complete message to console', function(done) {
var flow = [{id:"n1", type:"debug", complete: "true", console: "true" }];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload:"test"});
}, function(msg) {
JSON.parse(msg).should.eql({
topic:"debug",
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"}
});
}, function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "debug";
});
logEvents.should.have.length(1);
var tstmp = logEvents[0][0].timestamp;
logEvents[0][0].should.eql({level:helper.log().INFO, id:"n1",type:"debug",msg:'\n{ payload: \'test\' }',timestamp:tstmp});
done();
} catch(err) {
done(err);
}
});
});
});
it('should publish other property', function(done) {
var flow = [{id:"n1", type:"debug", complete: "foo" }];
helper.load(debugNode, flow, function() {
@ -156,6 +184,20 @@ describe('debug node', function() {
});
});
it('should publish a number', function(done) {
var flow = [{id:"n1", type:"debug", console:"true" }];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: 7});
}, function(msg) {
JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:"7",property:"payload",format:"number"}
});
}, done);
});
});
it('should publish with no payload', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
@ -170,6 +212,20 @@ describe('debug node', function() {
});
});
it('should publish a null', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: null});
}, function(msg) {
JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:'(undefined)',property:"payload",format:"null"}
});
}, done);
});
});
it('should publish an object', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
@ -222,6 +278,60 @@ describe('debug node', function() {
});
});
it('should publish an object to console', function(done) {
var flow = [{id:"n1", type:"debug", console: "true"}];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: {type:'foo'}});
}, function(msg) {
JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"}
});
}, function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "debug";
});
logEvents.should.have.length(1);
var tstmp = logEvents[0][0].timestamp;
logEvents[0][0].should.eql({level:helper.log().INFO,id:"n1",type:"debug",msg:'\n{ type: \'foo\' }',timestamp:tstmp});
done();
} catch(err) {
done(err);
}
});
});
});
it('should publish a string after a newline to console if the string contains \\n', function(done) {
var flow = [{id:"n1", type:"debug", console: "true"}];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: "test\ntest"});
}, function(msg) {
JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:"test\ntest",property:"payload",format:"string[9]"}
});
}, function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "debug";
});
logEvents.should.have.length(1);
var tstmp = logEvents[0][0].timestamp;
logEvents[0][0].should.eql({level:helper.log().INFO,id:"n1",type:"debug",msg:"\ntest\ntest",timestamp:tstmp});
done();
} catch(err) {
done(err);
}
});
});
});
it('should truncate a long message', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
@ -243,6 +353,130 @@ describe('debug node', function() {
});
});
it('should truncate a long string in the object', function(done) {
var flow = [{id:"n1", type:"debug"}];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: {foo: Array(1002).join("X")}});
}, function(msg) {
var a = JSON.parse(msg);
a.should.eql({
topic:"debug",
data:{
id:"n1",
msg:'{\n "foo": "'+Array(1001).join("X")+'..."\n}',
property:"payload",
format:"Object"
}
});
}, done);
});
});
it('should truncate a large array', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: Array(1001).fill("X")});
}, function(msg) {
var a = JSON.parse(msg);
a.should.eql({
topic:"debug",
data:{
id:"n1",
msg:JSON.stringify({
__encoded__: true,
type: "array",
data: Array(1000).fill("X"),
length: 1001
},null," "),
property:"payload",
format:"array[1001]"
}
});
}, done);
});
});
it('should truncate a large array in the object', function(done) {
var flow = [{id:"n1", type:"debug"}];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: {foo: Array(1001).fill("X")}});
}, function(msg) {
var a = JSON.parse(msg);
a.should.eql({
topic:"debug",
data:{
id:"n1",
msg:JSON.stringify({
foo:{
__encoded__: true,
type: "array",
data: Array(1000).fill("X"),
length: 1001
}
},null," "),
property:"payload",
format:"Object"
}
});
}, done);
});
});
it('should truncate a large buffer', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: Buffer(501).fill("\"")});
}, function(msg) {
var a = JSON.parse(msg);
a.should.eql({
topic:"debug",
data:{
id:"n1",
msg: Array(1001).join("2"),
property:"payload",
format:"buffer[501]"
}
});
}, done);
});
});
it('should truncate a large buffer in the object', function(done) {
var flow = [{id:"n1", type:"debug"}];
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: {foo: Buffer(1001).fill("X")}});
}, function(msg) {
var a = JSON.parse(msg);
a.should.eql({
topic:"debug",
data:{
id:"n1",
msg:JSON.stringify({
foo:{
type: "Buffer",
data: Array(1000).fill(88),
__encoded__: true,
length: 1001
}
},null," "),
property:"payload",
format:"Object"
}
});
}, done);
});
});
it('should convert Buffer to hex', function(done) {
var flow = [{id:"n1", type:"debug" }];
helper.load(debugNode, flow, function() {
@ -324,6 +558,18 @@ describe('debug node', function() {
});
});
describe('get', function() {
it('should return the view.html', function(done) {
var flow = [{id:"n1", type:"debug"}];
helper.load(debugNode, flow, function() {
helper.request()
.get('/debug/view/view.html')
.expect(200)
.end(done);
});
});
});
});
function websocket_test(open_callback, message_callback, done_callback) {

View File

@ -0,0 +1,118 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var linkNode = require("../../../../nodes/core/core/60-link.js");
var helper = require("../../helper.js");
describe('link Node', function() {
before(function(done) {
helper.startServer(done);
});
afterEach(function() {
helper.unload();
});
it('should be loaded (link in)', function(done) {
var flow = [{id:"n1", type:"link in", name: "link-in" }];
helper.load(linkNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('name', 'link-in');
done();
});
});
it('should be loaded (link out)', function(done) {
var flow = [{id:"n1", type:"link out", name: "link-out" }];
helper.load(linkNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('name', 'link-out');
done();
});
});
it('should be linked', function(done) {
var flow = [{id:"n1", type:"link out", name: "link-out", links:["n2"]},
{id:"n2", type:"link in", name: "link-in", wires:[["n3"]]},
{id:"n3", type:"helper"}];
helper.load(linkNode, flow, function() {
var n1 = helper.getNode("n1");
var n3 = helper.getNode("n3");
n3.on("input", function(msg) {
try {
msg.should.have.property('payload', 'hello');
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"hello"});
});
});
it('should be linked to multiple nodes', function(done) {
var flow = [{id:"n1", type:"link out", name: "link-out", links:["n2", "n3"]},
{id:"n2", type:"link in", name: "link-in0", wires:[["n4"]]},
{id:"n3", type:"link in", name: "link-in1", wires:[["n4"]]},
{id:"n4", type:"helper"} ];
helper.load(linkNode, flow, function() {
var n1 = helper.getNode("n1");
var n4 = helper.getNode("n4");
var count = 0;
n4.on("input", function (msg) {
try {
msg.should.have.property('payload', 'hello');
count++;
if(count == 2) {
done();
}
} catch(err) {
done(err);
}
});
n1.receive({payload:"hello"});
});
});
it('should be linked from multiple nodes', function(done) {
var flow = [{id:"n1", type:"link out", name: "link-out0", links:["n3"]},
{id:"n2", type:"link out", name: "link-out1", links:["n3"]},
{id:"n3", type:"link in", name: "link-in", wires:[["n4"]]},
{id:"n4", type:"helper"} ];
helper.load(linkNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var n4 = helper.getNode("n4");
var count = 0;
n4.on("input", function(msg) {
try {
msg.should.have.property('payload', 'hello');
count++;
if(count == 2) {
done();
}
} catch(err) {
done(err);
}
});
n1.receive({payload:"hello"});
n2.receive({payload:"hello"});
});
});
});

View File

@ -76,11 +76,15 @@ describe('exec node', function() {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("echo");
msg.should.have.property("rc");
msg.rc.should.have.property("code",0);
msg = messages[1];
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("ECHO");
msg.should.have.property("rc");
msg.rc.should.have.property("code",0);
msg = messages[2];
msg.should.have.property("payload");
@ -88,7 +92,8 @@ describe('exec node', function() {
child_process.exec.restore();
done();
} catch(err) {
}
catch(err) {
child_process.exec.restore();
done(err);
}
@ -136,20 +141,23 @@ describe('exec node', function() {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("echo and more");
msg.should.have.property("rc");
msg.rc.should.have.property("code",0);
msg = messages[1];
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("ECHO AND MORE");
msg.should.have.property("rc");
msg.rc.should.have.property("code",0);
child_process.exec.restore();
done();
} catch(err) {
}
catch(err) {
child_process.exec.restore();
done(err);
}
};
n2.on("input", function(msg) {
messages[0] = msg;
completeTest();
@ -169,7 +177,7 @@ describe('exec node', function() {
function(arg1, arg2, arg3, arg4) {
//console.log(arg1);
// arg3(error,stdout,stderr);
arg3("error",new Buffer([0x01,0x02,0x03,0x88]));
arg3("error",new Buffer([0x01,0x02,0x03,0x88]),new Buffer([0x01,0x02,0x03,0x88]));
});
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
@ -199,33 +207,11 @@ describe('exec node', function() {
// Although Windows timeout command is equivalent to sleep, this cannot be used because it promptly outputs a message.
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"ping", addpay:false, append:"192.0.2.0 -n 1 -w 1000 > NUL", timer:"0.3", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
} else {
}
else {
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"sleep", addpay:false, append:"1", timer:"0.3", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
}
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.have.property("signal","SIGTERM");
done();
});
n1.receive({});
});
});
it('should be able to kill a long running command', function(done) {
var flow;
if (osType === "Windows_NT") {
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"ping", addpay:false, append:"192.0.2.0 -n 1 -w 1000 > NUL", timer:"2", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
} else {
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"sleep", addpay:false, append:"1", timer:"2", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
}
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
@ -236,9 +222,42 @@ describe('exec node', function() {
msg.should.have.property("payload");
msg.payload.should.have.property("signal","SIGTERM");
done();
} catch(err) {
done(err);
}
catch(err) { done(err); }
});
n1.receive({});
});
});
it('should be able to kill a long running command', function(done) {
var flow;
if (osType === "Windows_NT") {
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"ping", addpay:false, append:"192.0.2.0 -n 1 -w 1000 > NUL", timer:"2", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
}
else {
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"sleep", addpay:false, append:"1", timer:"2", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
}
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
try {
msg.should.have.property("rc");
msg.rc.should.have.property("code",null);
msg.rc.should.have.property("signal","SIGTERM");
} catch(err) { done(err); }
});
n4.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.have.property("signal","SIGTERM");
done();
}
catch(err) { done(err); }
});
setTimeout(function() {
n1.receive({kill:""});
@ -262,14 +281,19 @@ describe('exec node', function() {
var n2 = helper.getNode("n2");
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
try {
msg.should.have.property("rc");
msg.rc.should.have.property("code",null);
msg.rc.should.have.property("signal","SIGINT");
} catch(err) { done(err); }
});
n4.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.have.property("signal",sig);
done();
} catch(err) {
done(err);
}
} catch(err) { done(err); }
});
setTimeout(function() {
n1.receive({kill:"SIGINT"});
@ -278,7 +302,6 @@ describe('exec node', function() {
});
});
it('should return the rc for a failing command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"error", addpay:false, append:"", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
@ -305,6 +328,9 @@ describe('exec node', function() {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("error");
msg.should.have.property("rc");
msg.rc.should.have.property("code",1);
msg.rc.should.have.property("message",undefined);
msg = messages[1];
msg.should.have.property("payload");
@ -317,7 +343,8 @@ describe('exec node', function() {
child_process.exec.restore();
done();
} catch(err) {
}
catch(err) {
child_process.exec.restore();
done(err);
}
@ -369,9 +396,8 @@ describe('exec node', function() {
msg.payload.should.be.a.String();
msg.payload.should.equal(expected);
done();
} catch(err) {
done(err);
}
catch(err) { done(err); }
});
n1.receive({payload:"hello world"});
});
@ -397,10 +423,13 @@ describe('exec node', function() {
var n4 = helper.getNode("n4");
n2.on("input", function(msg) {
//console.log(msg);
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal(expected);
done();
try {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal(expected);
done();
}
catch(err) { done(err); }
});
n1.receive({payload:12345});
});
@ -431,9 +460,8 @@ describe('exec node', function() {
msg.payload.length.should.equal(7);
}
done();
} catch(err) {
done(err);
}
catch(err) { done(err); }
});
n1.receive({payload:new Buffer([0x01,0x02,0x03,0x88])});
});
@ -474,12 +502,12 @@ describe('exec node', function() {
should.exist(msg.payload);
msg.payload.should.have.property("code",0);
done();
} catch(err) {
}
catch(err) {
done(err);
}
};
n2.on("input", function(msg) {
messages[0] = msg;
completeTest();
@ -501,10 +529,13 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.have.property("code");
msg.payload.code.should.be.below(0);
done();
try {
msg.should.have.property("payload");
msg.payload.should.have.property("code");
msg.payload.code.should.be.below(0);
done();
}
catch(err) { done(err); }
});
n1.receive({payload:null});
});
@ -513,6 +544,7 @@ describe('exec node', function() {
it('should return an error for a failing command', function(done) {
var flow;
var expected;
var expectedFound = false;
if (osType === "Windows_NT") {
// Cannot use mkdir because Windows mkdir command automatically creates non-existent directories.
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"ping /foo/bar/doo/dah", addpay:false, append:"", useSpawn:"true", oldrc:"false"},
@ -521,7 +553,7 @@ describe('exec node', function() {
} else {
flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"mkdir /foo/bar/doo/dah", addpay:false, append:"", useSpawn:"true", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
expected = "mkdir: /foo/bar/doo: No such file or directory\n";
expected = ' directory';
}
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
@ -529,14 +561,26 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n3.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal(expected);
try {
msg.should.have.property("payload");
msg.payload.should.be.a.String();
if (msg.payload.indexOf(expected) >= 0) {
// The error text on the stderr stream might get sent in more than one piece.
// We only need to know that it occurred before the return code is sent,
// as checked below in node n4.
expectedFound = true;
}
}
catch(err) { done(err); }
});
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.have.property("code",1);
done();
try {
expectedFound.should.be.true;
msg.should.have.property("payload");
msg.payload.should.have.property("code",1);
done();
}
catch(err) { done(err); }
});
n1.receive({payload:null});
});
@ -557,10 +601,13 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.have.property("code",null);
msg.payload.should.have.property("signal","SIGTERM");
done();
try {
msg.should.have.property("payload");
msg.payload.should.have.property("code",null);
msg.payload.should.have.property("signal","SIGTERM");
done();
}
catch(err) { done(err); }
});
n1.receive({});
});
@ -581,9 +628,12 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.have.property("signal","SIGTERM");
done();
try {
msg.should.have.property("payload");
msg.payload.should.have.property("signal","SIGTERM");
done();
}
catch(err) { done(err); }
});
setTimeout(function() {
n1.receive({kill:""});
@ -608,9 +658,12 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.have.property("signal",sig);
done();
try {
msg.should.have.property("payload");
msg.payload.should.have.property("signal",sig);
done();
}
catch(err) { done(err); }
});
setTimeout(function() {
n1.receive({kill:"SIGINT"});

View File

@ -52,6 +52,21 @@ describe('function node', function() {
});
});
it('should send returned message using send()', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"node.send(msg);"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should pass through _topic', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"return msg;"},
{id:"n2", type:"helper"}];
@ -160,6 +175,22 @@ describe('function node', function() {
});
});
it('should get keys in global context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=global.keys();return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().global.set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', ['count']);
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
function testNonObjectMessage(functionText,done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:functionText},
{id:"n2", type:"helper"}];
@ -228,6 +259,251 @@ describe('function node', function() {
}
});
});
it('should handle node.on()', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"node.on('close',function(){node.log('closed')});"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
n1.receive({payload:"foo",topic: "bar"});
helper.getNode("n1").close();
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().INFO);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
msg.should.have.property('msg', 'closed');
done();
} catch(err) {
done(err);
}
});
});
it('should set node context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0');return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
n1.context().get("count").should.equal("0");
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get node context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=context.get('count');return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', '0');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get keys in node context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=context.keys();return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', ['count']);
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should set flow context', function(done) {
var flow = [{id:"n1",type:"function",z:"flowA",wires:[["n2"]],func:"flow.set('count','0');return msg;"},
{id:"n2", type:"helper",z:"flowA"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
n2.context().flow.get("count").should.equal("0");
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get flow context', function(done) {
var flow = [{id:"n1",type:"function",z:"flowA",wires:[["n2"]],func:"msg.payload=flow.get('count');return msg;"},
{id:"n2", type:"helper",z:"flowA"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().flow.set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', '0');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get flow context', function(done) {
var flow = [{id:"n1",type:"function",z:"flowA",wires:[["n2"]],func:"msg.payload=context.flow.get('count');return msg;"},
{id:"n2", type:"helper",z:"flowA"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().flow.set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', '0');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get keys in flow context', function(done) {
var flow = [{id:"n1",type:"function",z:"flowA",wires:[["n2"]],func:"msg.payload=flow.keys();return msg;"},
{id:"n2", type:"helper",z:"flowA"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().flow.set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', ['count']);
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should set global context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"global.set('count','0');return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
n2.context().global.get("count").should.equal("0");
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get global context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=global.get('count');return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().global.set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', '0');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should get global context', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=context.global.get('count');return msg;"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().global.set("count","0");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', '0');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should handle setTimeout()', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"setTimeout(function(){node.send(msg);},1000);"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
var endTime = process.hrtime(startTime);
var nanoTime = endTime[0] * 1000000000 + endTime[1];
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
if (900000000 < nanoTime && nanoTime < 1100000000) {
done();
} else {
try {
should.fail(null, null, "Delayed time was not between 900 and 1100 ms");
} catch (err) {
done(err);
}
}
});
var startTime = process.hrtime();
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should handle setInterval()', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"setInterval(function(){node.send(msg);},100);"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var count = 0;
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
count++;
if (count > 2) {
done();
}
});
n1.receive({payload:"foo",topic: "bar"});
});
});
it('should handle clearInterval()', function(done) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"var id=setInterval(null,100);setTimeout(function(){clearInterval(id);node.send(msg);},1000);"},
{id:"n2", type:"helper"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
describe('Logger', function () {
it('should log an Info Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.log('test');"}];

View File

@ -88,6 +88,18 @@ describe('template node', function() {
});
});
it('should handle escape characters in Mustache format and JSON output mode', function(done) {
var flow = [{id:"n1", type:"template", field:"payload", syntax:"mustache", template:"{\"data\":\"{{payload}}\"}", output:"json", wires:[["n2"]]},{id:"n2",type:"helper"}];
helper.load(templateNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.payload.should.have.property('data', 'line\t1\nline\\2\r\nline\b3\f');
done();
});
n1.receive({payload:"line\t1\nline\\2\r\nline\b3\f"});
});
});
it('should modify payload in plain text mode', function(done) {
var flow = [{id:"n1", type:"template", field:"payload", syntax:"plain", template:"payload={{payload}}",wires:[["n2"]]},{id:"n2",type:"helper"}];

View File

@ -347,7 +347,7 @@ describe('delay Node', function() {
* @param delay - the variable delay: milliseconds
*/
function variableDelayTest(aTimeoutFrom, aTimeoutTo, aTimeoutUnit, delay, done) {
var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delayv","timeout":5,"timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":aTimeoutFrom,"randomLast":aTimeoutTo,"randomUnits":aTimeoutUnit,"drop":false,"wires":[["helperNode1"]]},
var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delayv","timeout":0.5,"timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":aTimeoutFrom,"randomLast":aTimeoutTo,"randomUnits":aTimeoutUnit,"drop":false,"wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(delayNode, flow, function() {
var delayNode1 = helper.getNode("delayNode1");
@ -400,12 +400,16 @@ describe('delay Node', function() {
variableDelayTest("200", "300", "milliseconds", 250, done);
});
it('variable delay is zero if msg.delay not specified', function(done) {
variableDelayTest("0", "50", "milliseconds", null, done);
it('variable delay is the default if msg.delay not specified', function(done) {
variableDelayTest("450", "550", "milliseconds", null, done);
});
it('variable delay is zero if msg.delay is zero', function(done) {
variableDelayTest("0", "20", "milliseconds", 0, done);
});
it('variable delay is zero if msg.delay is negative', function(done) {
variableDelayTest("0", "50", "milliseconds", -250, done);
variableDelayTest("0", "20", "milliseconds", -250, done);
});
/**

View File

@ -0,0 +1,249 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var fs = require("fs");
var path = require("path");
var should = require("should");
var helper = require("../../helper.js");
var watchNode = require("../../../../nodes/core/io/23-watch.js");
describe('watch Node', function() {
this.timeout(5000);
var resourcesDir = path.join(__dirname,"..","..","..","resources");
var baseDir = path.join(resourcesDir, "23-watch-test-dir");
var dirToWatch = undefined;
var subDirToWatch = undefined;
var file0ToWatch = undefined;
var file1ToWatch = undefined;
var file2ToWatch = undefined;
var count = 0;
function prepareDir() {
dirToWatch = path.join(baseDir, "base"+count);
file0ToWatch = path.join(dirToWatch, "file0.txt");
file1ToWatch = path.join(dirToWatch, "file1.txt");
subDirToWatch = path.join(dirToWatch, "subdir");
file2ToWatch = path.join(subDirToWatch, "file2.txt");
fs.mkdirSync(dirToWatch);
count++;
}
function wait(msec, func) {
setTimeout(func, msec);
}
function rmdir(dir_path, done) {
function collect(dir_path, files, dirs) {
var elems = fs.readdirSync(dir_path);
elems.forEach(function(elem) {
var elem_path = path.join(dir_path, elem);
var stat = fs.lstatSync(elem_path);
if(stat.isDirectory()) {
var r = collect(elem_path, files, dirs);
files = r[0];
dirs = r[1];
} else {
files.push(elem_path);
}
});
dirs.push(dir_path);
return [files, dirs];
}
function seq(func, list, cont) {
if(list.length > 0) {
var elem = list.shift();
func(elem, function(err) {
if(err) {
throw err;
}
seq(func, list, cont);
});
}
else {
cont();
}
}
var r = collect(dir_path, [], []);
var files = r[0];
var dirs = r[1];
seq(fs.unlink, files,
function() {
seq(fs.rmdir, dirs, done);
});
}
before(function(done) {
fs.mkdirSync(baseDir);
done();
});
after(function(done) {
rmdir(baseDir, done);
});
beforeEach(function(done) {
prepareDir();
done();
});
afterEach(function(done) {
helper.unload();
done();
});
function testWatch(flow, change_func, results, done) {
var processed = {};
helper.load(watchNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var count = 0;
var len = Object.keys(results).length;
n2.on("input", function(msg) {
msg.should.have.property('file');
var file = msg.file;
if(file in processed) {
// multiple messages come in rare case
return;
}
processed[file] = true;
(file in results).should.be.true;
var result = results[file];
msg.should.have.property('payload', result.payload);
msg.should.have.property('type', result.type);
if('size' in result) {
msg.should.have.property('size', result.size);
}
count++;
if(count === len) {
n1.close();
// wait for close
wait(500, done);
}
});
// wait for preparation
wait(500, change_func);
});
}
it('should watch a file to be changed', function(done) {
fs.writeFileSync(file0ToWatch, '');
var flow = [{id:"n1", type:"watch", name: "watch",
files: file0ToWatch, recursive: false,
wires:[["n2"]]},
{id:"n2", type:"helper"}];
var results = {
'file0.txt' : {
'payload' : file0ToWatch,
'topic': file0ToWatch,
'type': 'file',
'size': 5
}
};
testWatch(flow, function() {
fs.appendFileSync(file0ToWatch, "ABCDE");
}, results, done);
});
it('should watch multiple files to be changed', function(done) {
fs.writeFileSync(file0ToWatch, '');
fs.writeFileSync(file1ToWatch, '');
var files = file0ToWatch +","+file1ToWatch;
var flow = [{id:"n1", type:"watch", name: "watch",
files: files, recursive: false,
wires:[["n2"]]},
{id:"n2", type:"helper"}];
var results = {
'file0.txt' : {
'payload' : file0ToWatch,
'topic': file0ToWatch,
'type': 'file',
'size': 5
},
'file1.txt' : {
'payload' : file1ToWatch,
'topic': file1ToWatch,
'type': 'file',
'size': 3
}
};
testWatch(flow, function() {
fs.appendFileSync(file0ToWatch, "ABCDE");
fs.appendFileSync(file1ToWatch, "123");
}, results, done);
});
it('should watch attribute of a file to be changed', function(done) {
fs.writeFileSync(file0ToWatch, '');
fs.chmodSync(file0ToWatch, 0o444);
var flow = [{id:"n1", type:"watch", name: "watch",
files: file0ToWatch, recursive: false,
wires:[["n2"]]},
{id:"n2", type:"helper"}];
var results = {
'file0.txt' : {
'payload' : file0ToWatch,
'topic': file0ToWatch,
'type': 'file',
'size': 0
}
};
testWatch(flow, function() {
fs.chmodSync(file0ToWatch, 0o777);
}, results, done);
});
it('should watch a file in a directory to be changed', function(done) {
fs.writeFileSync(file0ToWatch, '');
var flow = [{id:"n1", type:"watch", name: "watch",
files: dirToWatch, recursive: true,
wires:[["n2"]]},
{id:"n2", type:"helper"}];
var results = {
'file0.txt' : {
'payload' : file0ToWatch,
'topic': file0ToWatch,
'type': 'file',
'size': 5
}
};
testWatch(flow, function() {
fs.appendFileSync(file0ToWatch, "ABCDE");
}, results, done);
});
it('should watch a sub directory in a directory to be changed', function(done) {
fs.mkdirSync(subDirToWatch);
var flow = [{id:"n1", type:"watch", name: "watch",
files: dirToWatch, recursive: true,
wires:[["n2"]]},
{id:"n2", type:"helper"}];
var results = {
'file2.txt': {
payload: file2ToWatch,
type: 'file',
size: 5
}
};
testWatch(flow, function() {
fs.appendFileSync(file2ToWatch, "ABCDE");
}, results, done);
});
});

View File

@ -0,0 +1,229 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var net = require("net");
var should = require("should");
var helper = require("../../helper.js");
var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js");
describe('TCP in Node', function() {
var port = 9200;
var server = undefined;
var server_port = 9300;
var reply_data = undefined;
before(function(done) {
done();
});
after(function() {
});
beforeEach(function(done) {
startServer(done);
});
afterEach(function() {
stopServer();
helper.unload();
});
function sendArray(sock, array) {
if(array.length > 0) {
sock.write(array[0], function() {
sendArray(sock, array.slice(1));
});
}
else {
sock.end();
}
}
function startServer(done) {
server_port += 1;
server = net.createServer(function(c) {
sendArray(c, reply_data);
}).listen(server_port, "localhost", function(err) {
done(err);
});
}
function stopServer() {
server.close();
}
function send(wdata) {
var opt = {port:port, host:"localhost"};
var client = net.createConnection(opt, function() {
client.write(wdata[0], function() {
client.end();
if(wdata.length > 1) {
send(wdata.slice(1));
}
});
});
}
function eql(v0, v1) {
return((v0 === v1) || ((typeof v0) === 'object' && v0.equals(v1)));
}
function testTCP(flow, wdata, rdata, is_server, done) {
if(is_server) {
reply_data = wdata;
}
helper.load(tcpinNode, flow, function() {
var n2 = helper.getNode("n2");
var rcount = 0;
n2.on("input", function(msg) {
if(eql(msg.payload, rdata[rcount])) {
rcount++;
}
else {
should.fail();
}
if(rcount === rdata.length) {
done();
}
});
if(!is_server) {
send(wdata);
}
});
}
function testTCP0(flow, wdata, rdata, done) {
testTCP(flow, wdata, rdata, false, done);
}
function testTCP1(flow, wdata, rdata, done) {
testTCP(flow, wdata, rdata, true, done);
}
it('should recv data (Stream/Buffer)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"buffer", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo"], [Buffer("foo")], done);
});
it('should recv data (Stream/String/Delimiter:\\n)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"utf8", newline:"\n", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo\nbar"], ["foo", "bar"], done);
});
it('should recv data (Stream/String/No delimiter)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"utf8", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo\nbar"], ["foo\nbar"], done);
});
it('should recv data (Stream/Base64)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"base64", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo"], [Buffer("foo").toString('base64')], done);
});
it('should recv data (Single/Buffer)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"single", datatype:"buffer", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo"], [Buffer("foo")], done);
});
it('should recv data (Single/String)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"single", datatype:"utf8", newline:"\n", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo\nbar\nbaz"], ["foo\nbar\nbaz"], done);
});
it('should recv data (Stream/Base64)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"single", datatype:"base64", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo"], [Buffer("foo").toString('base64')], done);
});
it('should recv multiple data (Stream/Buffer)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"buffer", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo", "bar"], [Buffer("foo"), Buffer("bar")], done);
});
it('should recv multiple data (Stream/String/Delimiter:\\n)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"utf8", newline:"\n", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo", "bar\nbaz"], ["foo", "bar", "baz"], done);
});
it('should recv multiple data (Stream/String/No delimiter)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"utf8", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo", "bar\nbaz"], ["foo", "bar\nbaz"], done);
});
it('should recv multiple data (Stream/Base64)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"base64", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
var wdata = ["foo", "bar"];
var rdata = wdata.map(function(x) {
return Buffer(x).toString('base64');
});
testTCP0(flow, wdata, rdata, done);
});
it('should connect & recv data (Stream/Buffer)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"stream", datatype:"buffer", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo"], [Buffer("foo")], done);
});
it('should connect & recv data (Stream/String/Delimiter:\\n)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"stream", datatype:"utf8", newline:"\n", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo\nbar"], ["foo", "bar"], done);
});
it('should connect & recv data (Stream/String/No delimiter)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"stream", datatype:"utf8", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo\nbar"], ["foo\nbar"], done);
});
it('should connect & recv data (Stream/Base64)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"stream", datatype:"base64", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo"], [Buffer("foo").toString('base64')], done);
});
it('should connect & recv data (Single/Buffer)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"single", datatype:"buffer", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo"], [Buffer("foo")], done);
});
it('should connect & recv data (Single/String)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"single", datatype:"utf8", newline:"\n", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo\nbar\nbaz"], ["foo\nbar\nbaz"], done);
});
it('should connect & recv data (Stream/Base64)', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"client", host:"localhost", port:server_port, datamode:"single", datatype:"base64", newline:"", topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP1(flow, ["foo"], [Buffer("foo").toString('base64')], done);
});
});

View File

@ -0,0 +1,110 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var net = require("net");
var should = require("should");
var helper = require("../../helper.js");
var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js");
describe('TCP Request Node', function() {
var server = undefined;
var port = 9000;
function startServer(done) {
port += 1;
server = net.createServer(function(c) {
c.on('data', function(data) {
var rdata = "ACK:"+data.toString();
c.write(rdata);
});
c.on('error', function(err) {
startServer(done);
});
}).listen(port, "127.0.0.1", function(err) {
done();
});
}
before(function(done) {
startServer(done);
});
after(function() {
server.close();
});
afterEach(function() {
helper.unload();
});
function testTCP(flow, val0, val1, done) {
helper.load(tcpinNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', Buffer(val1));
done();
} catch(err) {
done(err);
}
});
if((typeof val0) === 'object') {
n1.receive(val0);
} else {
n1.receive({payload:val0});
}
});
}
it('should send & recv data', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo", "ACK:foo", done)
});
it('should send & recv data when specified character received', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"char", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo0bar0", "ACK:foo0", done);
});
it('should send & recv data after fixed number of chars received', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"count", splitc: "7", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo bar", "ACK:foo", done);
});
it('should send & receive, then keep connection', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"sit", splitc: "5", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo", "ACK:foo", done);
});
it('should send & close', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"sit", splitc: "5", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo", "ACK:foo", done);
});
it('should send & recv data to/from server:port from msg', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"", port:"", out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, {payload:"foo", host:"localhost", port:port}, "ACK:foo", done)
});
});

View File

@ -0,0 +1,93 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var dgram = require("dgram");
var should = require("should");
var helper = require("../../helper.js");
var udpNode = require("../../../../nodes/core/io/32-udp.js");
describe('UDP in Node', function() {
var port = 9100;
before(function(done) {
helper.startServer(done);
});
after(function() {
});
afterEach(function() {
helper.unload();
});
function sendIPv4(msg) {
var sock = dgram.createSocket('udp4');
sock.send(msg, 0, msg.length, port, "127.0.0.1", function(msg) {
sock.close();
});
}
function checkRecv(dt, proto, val0, val1, done) {
var flow = [{id:"n1", type:"udp in",
group: "", multicast:false,
port:port, ipv:proto,
datatype: dt, iface: "",
wires:[["n2"]] },
{id:"n2", type:"helper"}];
helper.load(udpNode, flow, function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
var ip = ((proto === 'udp6') ? '::ffff:':'') +'127.0.0.1';
msg.should.have.property('ip', ip);
msg.should.have.property('port');
msg.should.have.property('payload');
msg.payload.should.deepEqual(val1);
done();
} catch(err) {
done(err);
}
});
sendIPv4(val0);
});
}
it('should recv IPv4 data (Buffer)', function(done) {
checkRecv('buffer', 'udp4', 'hello', Buffer('hello'), done);
});
it('should recv IPv4 data (String)', function(done) {
checkRecv('utf8', 'udp4', 'hello', 'hello', done);
});
it('should recv IPv4 data (base64)', function(done) {
checkRecv('base64', 'udp4', 'hello', Buffer('hello').toString('base64'), done);
});
it('should recv IPv6 data (Buffer)', function(done) {
checkRecv('buffer', 'udp6', 'hello', Buffer('hello'), done);
});
it('should recv IPv6 data (String)', function(done) {
checkRecv('utf8', 'udp6', 'hello', 'hello', done);
});
it('should recv IPv6 data (base64)', function(done) {
checkRecv('base64', 'udp6', 'hello', Buffer('hello').toString('base64'), done);
});
});

View File

@ -0,0 +1,85 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var dgram = require("dgram");
var should = require("should");
var helper = require("../../helper.js");
var udpNode = require("../../../../nodes/core/io/32-udp.js");
describe('UDP out Node', function() {
var port = 9200;
before(function(done) {
helper.startServer(done);
});
after(function() {
});
afterEach(function() {
helper.unload();
});
function recvData(data, done) {
var sock = dgram.createSocket('udp4');
sock.on('message', function(msg, rinfo) {
msg.should.deepEqual(data);
done();
});
sock.bind(port, '127.0.0.1');
port++;
}
function checkSend(proto, val0, val1, decode, dest_in_msg, done) {
var dst_ip = dest_in_msg ? undefined : "127.0.0.1";
var dst_port = dest_in_msg ? undefined : port;
var flow = [{id:"n1", type:"udp out",
addr:dst_ip, port:dst_port, iface: "",
ipv:proto, outport: "random",
base64:decode, multicast:false,
wires:[] }];
helper.load(udpNode, flow, function() {
var n1 = helper.getNode("n1");
var msg = {};
if(decode) {
msg.payload = Buffer("hello").toString('base64');
}
else {
msg.payload = "hello";
}
if(dest_in_msg) {
msg.ip = "127.0.0.1";
msg.port = port;
}
recvData(val1, done);
n1.receive(msg);
});
}
it('should send IPv4 data', function(done) {
checkSend('udp4', 'hello', Buffer('hello'), false, false, done);
});
it('should send IPv4 data (base64)', function(done) {
checkSend('udp4', 'hello', Buffer('hello'), true, false, done);
});
it('should send IPv4 data with dest from msg', function(done) {
checkSend('udp4', 'hello', Buffer('hello'), false, true, done);
});
});

View File

@ -187,6 +187,10 @@ describe('switch Node', function() {
twoFieldSwitchTest("btwn", "3", "5", true, true, 4, done);
});
it('should check if payload is between given string values', function(done) {
twoFieldSwitchTest("btwn", "c", "e", true, true, "d", done);
});
it('should check if payload is not between given values', function(done) {
twoFieldSwitchTest("btwn", 3, 5, true, false, 12, done);
});
@ -489,4 +493,9 @@ describe('switch Node', function() {
});
});
it('should handle JSONata expression', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"$abs(payload)",propertyType:"jsonata",rules:[{"t":"btwn","v":"$sqrt(16)","vt":"jsonata","v2":"$sqrt(36)","v2t":"jsonata"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
customFlowSwitchTest(flow, true, -5, done);
});
});

View File

@ -64,7 +64,6 @@ describe('change Node', function() {
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
var rule = helper.getNode("changeNode1").rules[0];
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("changed");
@ -77,13 +76,31 @@ describe('change Node', function() {
});
});
it('sets the value of global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t":"set","p":"globalValue","pt":"global","to":"changed","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
changeNode1.context().global.get("globalValue").should.equal("changed");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","changeMe");
changeNode1.receive({payload:""});
});
});
it('sets the value and type of the message property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "set", "p": "payload", "pt": "msg", "to": "12345", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
var rule = helper.getNode("changeNode1").rules[0];
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal(12345);
@ -263,6 +280,44 @@ describe('change Node', function() {
});
});
it('changes the value to flow context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"flowValue","tot":"flow"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("Hello World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("flowValue","Hello World!");
changeNode1.receive({payload:""});
});
});
it('changes the value to global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"globalValue","tot":"global"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("Hello World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","Hello World!");
changeNode1.receive({payload:""});
});
});
it('changes the value to a number', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"123","tot":"num"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
@ -281,6 +336,24 @@ describe('change Node', function() {
});
});
it('changes the value to a boolean value', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"true","tot":"bool"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql(true);
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:""});
});
});
it('changes the value to a js object', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":'{"a":123}',"tot":"json"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
@ -299,13 +372,31 @@ describe('change Node', function() {
});
});
it('changes the value to a buffer object', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"[72,101,108,108,111,32,87,111,114,108,100]","tot":"bin"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
var buff = Buffer.from("Hello World");
msg.payload.should.eql(buff);
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:""});
});
});
it('sets the value of the message property to the current timestamp', function(done) {
var flow = [{"id":"changeNode1","type":"change","rules":[{"t":"set","p":"ts","pt":"msg","to":"","tot":"date"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
var rule = helper.getNode("changeNode1").rules[0];
helperNode1.on("input", function(msg) {
try {
(Date.now() - msg.ts).should.be.approximately(0,50);
@ -318,6 +409,24 @@ describe('change Node', function() {
});
});
it('changes the value using jsonata', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$length(payload)","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql(12);
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:"Hello World!"});
});
});
});
describe('#change', function() {
it('changes the value of the message property', function(done) {
@ -344,7 +453,6 @@ describe('change Node', function() {
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
var rule = helper.getNode("changeNode1").rules[0];
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("Change456Me");
@ -365,7 +473,6 @@ describe('change Node', function() {
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
var rule = helper.getNode("changeNode1").rules[0];
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal(456);
@ -541,6 +648,63 @@ describe('change Node', function() {
});
});
it('changes the value using flow context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"123","fromt":"flow","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("topic","ABC");
changeNode1.receive({payload:"abcABCabc"});
});
});
it('changes the value using global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"123","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic","ABC");
changeNode1.receive({payload:"abcABCabc"});
});
});
it('changes the number using global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"ABC","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("ABC");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic",123);
changeNode1.receive({payload:123});
});
});
it('changes the value using number - string payload', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"123","to":"456","fromt":"num","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
@ -612,6 +776,103 @@ describe('change Node', function() {
changeNode1.receive({payload:true});
});
});
it('changes the value of the global context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "global", "from": "Hello", "fromt": "str", "to": "Goodbye", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().global.get("payload").should.equal("Goodbye World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("payload","Hello World!");
changeNode1.receive({payload:""});
});
});
it('changes the value and doesnt change type of the flow context for partial match', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload").should.equal("Change456Me");
helperNode1.context().flow.get("payload").should.be.a.String();
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload","Change123Me");
changeNode1.receive({payload:""});
});
});
it('changes the value and type of the flow context if a complete match', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload").should.equal(456);
helperNode1.context().flow.get("payload").should.be.a.Number();
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload","123");
changeNode1.receive({payload:""});
});
});
it('changes the value using number - number flow context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "num", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload").should.equal("abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload",123);
changeNode1.receive({payload:""});
});
});
it('changes the value using boolean - boolean flow context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "true", "fromt": "bool", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload").should.equal("abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload",true);
changeNode1.receive({payload:""});
});
});
});
describe("#delete", function() {
@ -633,6 +894,25 @@ describe('change Node', function() {
});
});
it('deletes the value of global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "delete", "p": "globalValue", "pt": "global"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
changeNode1.context().global.should.not.have.property("globalValue");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","Hello World!");
changeNode1.receive({payload:""});
});
});
it('deletes the value of a multi-level message property', function(done) {
var flow = [{"id":"changeNode1","type":"change","action":"delete","property":"foo.bar","from":"","to":"","reg":false,"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];

View File

@ -559,6 +559,31 @@ describe('JOIN node', function() {
});
});
it('should join complete message objects into an array after a count', function(done) {
var flow = [{id:"n1", type:"join", wires:[["n2"]], build:"array", timeout:0, count:3, propertyType:"full",mode:"custom"},
{id:"n2", type:"helper"}];
helper.load(joinNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.payload.should.be.an.Array();
msg.payload[0].should.be.an.Object();
msg.payload[0].should.have.property("payload","a");
msg.payload[1].should.be.an.Object();
msg.payload[1].should.have.property("payload","b");
msg.payload[2].should.be.an.Object();
msg.payload[2].should.have.property("payload","c");
done();
}
catch(e) { done(e); }
});
n1.receive({payload:"a"});
n1.receive({payload:"b"});
n1.receive({payload:"c"});
});
});
it('should join split things back into an array', function(done) {
var flow = [{id:"n1", type:"join", wires:[["n2"]]},
{id:"n2", type:"helper"}];

View File

@ -198,19 +198,55 @@ describe('CSV node', function() {
describe('json object to csv', function() {
it('should convert a simple object back to a csv', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] },
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,,e", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', '4,3,2,1\n');
msg.should.have.property('payload', '4,foo,true,,0\n');
done();
}
catch(e) { done(e); }
});
var testJson = { d: 1, b: 3, c: 2, a: 4 };
var testJson = { e:0, d:1, b:"foo", c:true, a:4 };
n1.emit("input", {payload:testJson});
});
});
it('should convert a simple object back to a csv with no template', function(done) {
var flow = [ { id:"n1", type:"csv", temp:" ", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', '1,foo,"ba""r","di,ng"\n');
done();
}
catch(e) { done(e); }
});
var testJson = { d:1, b:"foo", c:"ba\"r", a:"di,ng" };
n1.emit("input", {payload:testJson});
});
});
it('should handle a template with spaces in the property names', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b o,c p,,e", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', '4,foo,true,,0\n');
done();
}
catch(e) { done(e); }
});
var testJson = { e:0, d:1, "b o":"foo", "c p":true, a:4 };
n1.emit("input", {payload:testJson});
});
});
@ -241,12 +277,12 @@ describe('CSV node', function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', '0,1,2,3,4\n');
msg.should.have.property('payload', ',0,1,foo,"ba""r","di,ng"\n');
done();
}
catch(e) { done(e); }
});
var testJson = [0,1,2,3,4];
var testJson = ["",0,1,"foo",'ba"r','di,ng'];
n1.emit("input", {payload:testJson});
});
});

View File

@ -154,32 +154,43 @@ describe('file Nodes', function() {
var f = fs.readFileSync(fileToTest).toString();
f.should.equal("onetwo");
// Delete the file
fs.unlinkSync(fileToTest);
// Recreate it
fs.writeFileSync(fileToTest,"");
// Send two more messages to the file
n1.emit("input", {payload:"three"});
n1.emit("input", {payload:"four"});
setTimeout(function() {
// Check the file was updated
try {
var f = fs.readFileSync(fileToTest).toString();
f.should.equal("threefour");
fs.unlinkSync(fileToTest);
done();
} catch(err) {
done(err);
}
},wait);
if (os.type() === "Windows_NT") {
var dummyFile = path.join(resourcesDir,"50-file-test-dummy.txt");
fs.rename(fileToTest, dummyFile, function() {
recreateTest(n1, dummyFile);
});
} else {
recreateTest(n1, fileToTest);
}
} catch(err) {
done(err);
}
},wait);
});
function recreateTest(n1, fileToDelete) {
// Delete the file
fs.unlinkSync(fileToDelete);
// Recreate it
fs.writeFileSync(fileToTest,"");
// Send two more messages to the file
n1.emit("input", {payload:"three"});
n1.emit("input", {payload:"four"});
setTimeout(function() {
// Check the file was updated
try {
var f = fs.readFileSync(fileToTest).toString();
f.should.equal("threefour");
fs.unlinkSync(fileToTest);
done();
} catch(err) {
done(err);
}
},wait);
}
});

View File

@ -26,11 +26,11 @@ var registry = require("../../../../red/runtime/nodes/registry");
describe("red/nodes/index", function() {
before(function() {
sinon.stub(flows,"startFlows");
sinon.stub(index,"startFlows");
process.env.NODE_RED_HOME = path.resolve(path.join(__dirname,"..","..","..",".."))
});
after(function() {
flows.startFlows.restore();
index.startFlows.restore();
delete process.env.NODE_RED_HOME;
});

View File

@ -17,8 +17,10 @@
var should = require("should");
var fs = require('fs-extra');
var path = require('path');
var sinon = require('sinon');
var localfilesystem = require("../../../../red/runtime/storage/localfilesystem");
var log = require("../../../../red/runtime/log");
describe('LocalFileSystem', function() {
var userDir = path.join(__dirname,".testUserHome");
@ -279,6 +281,45 @@ describe('LocalFileSystem', function() {
});
});
it('should fsync the flows file',function(done) {
var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
sinon.spy(fs,"fsync");
localfilesystem.saveFlows(testFlow).then(function() {
fs.fsync.callCount.should.eql(1);
fs.fsync.restore();
done();
}).otherwise(function(err) {
done(err);
});
}).otherwise(function(err) {
done(err);
});
});
it('should log fsync errors and continue',function(done) {
var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
sinon.stub(fs,"fsync", function(fd, cb) {
cb(new Error());
});
sinon.spy(log,"warn");
localfilesystem.saveFlows(testFlow).then(function() {
log.warn.callCount.should.eql(1);
log.warn.restore();
fs.fsync.callCount.should.eql(1);
fs.fsync.restore();
done();
}).otherwise(function(err) {
done(err);
});
}).otherwise(function(err) {
done(err);
});
});
it('should backup the flows file', function(done) {
var defaultFlowFile = 'flows_'+require('os').hostname()+'.json';
var defaultFlowFilePath = path.join(userDir,defaultFlowFile);