@gregoriusrippenstein/erlang-red-unittest 0.12.3 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/nodes/locales/en-US/ut-assert-success.html +8 -2
- package/nodes/locales/en-US/ut-assert-success.json +7 -1
- package/nodes/ut-assert-debug.js +403 -19
- package/nodes/ut-assert-failure.js +29 -18
- package/nodes/ut-assert-status.js +28 -18
- package/nodes/ut-assert-success.html +33 -12
- package/nodes/ut-assert-success.js +59 -28
- package/nodes/ut-assert-values.js +126 -16
- package/package.json +1 -1
- package/plugins/sidebar.html +131 -28
- package/testflows/01b074cfa6ae8818/flows.json +1 -0
- package/testflows/02b18fc0ed9de178/flows.json +1 -0
- package/testflows/0616f795a4aee63e/flows.json +1 -0
- package/testflows/069552b2eb6bce48/flows.json +265 -0
- package/testflows/08183069b5f8ef9c/flows.json +156 -0
- package/testflows/084fb0fc954b7156/flows.json +132 -0
- package/testflows/090eb2d5d71fd45f/flows.json +158 -0
- package/testflows/09aab59a2455cf15/flows.json +1 -0
- package/testflows/0b299a3175fc0df1/flows.json +1 -0
- package/testflows/0c35d269ca7178c6/flows.json +443 -0
- package/testflows/0cb8971e5f88ed1e/flows.json +1 -0
- package/testflows/0cc95e44532c14ec/flows.json +94 -0
- package/testflows/0e54563ba63b1501/flows.json +1 -0
- package/testflows/12572f9ac11e1786/flows.json +1 -0
- package/testflows/1566e453a88578a9/flows.json +1 -0
- package/testflows/15c2fad089960984/flows.json +1 -0
- package/testflows/1658196c31549916/flows.json +1 -0
- package/testflows/16b0bc0cdb0c5807/flows.json +1 -0
- package/testflows/16b254125478329a/flows.json +114 -0
- package/testflows/182731f54d855071/flows.json +52 -0
- package/testflows/1a196bce3e57f5c1/flows.json +1 -0
- package/testflows/1ace9e051618db79/flows.json +125 -0
- package/testflows/1bac0a78e0a36ec0/flows.json +1 -0
- package/testflows/1c1d2cb981cf9f01/flows.json +120 -0
- package/testflows/1d3326a724ecbea0/flows.json +1 -0
- package/testflows/1db9c9a1b92e0263/flows.json +172 -0
- package/testflows/1eb35963b752eca9/flows.json +1 -0
- package/testflows/2037454a5ee0d6c3/flows.json +1 -0
- package/testflows/20eeaf41372f7b17/flows.json +62 -0
- package/testflows/213803d61ecfde3a/flows.json +1 -0
- package/testflows/218350f2e240a15d/flows.json +1 -0
- package/testflows/24f35eaa8656755f/flows.json +1 -0
- package/testflows/27804627fb8f56bd/flows.json +178 -0
- package/testflows/2a12af161b544aa1/flows.json +1 -0
- package/testflows/2a2c508260b96236/flows.json +141 -0
- package/testflows/2a95a7b40a798878/flows.json +1 -0
- package/testflows/2c1c291ec8466bfb/flows.json +1 -0
- package/testflows/2c59ef974b2523ba/flows.json +1 -0
- package/testflows/30465efe017cc9b0/flows.json +1 -0
- package/testflows/30c79fc42a5c35eb/flows.json +1 -0
- package/testflows/338c5b411f4edfe8/flows.json +1 -0
- package/testflows/34d211e37618313c/flows.json +1 -0
- package/testflows/36846ad6698e1bc0/flows.json +163 -0
- package/testflows/37883612d913fd66/flows.json +1 -0
- package/testflows/38616d22e1569aa5/flows.json +1 -0
- package/testflows/3be6bc074c7647bd/flows.json +319 -0
- package/testflows/3e9e526b992d4c48/flows.json +1 -0
- package/testflows/3ea113b4ec3b6e5e/flows.json +1 -0
- package/testflows/3ed472eab9503b4f/flows.json +1 -0
- package/testflows/3edda6bd788f88c2/flows.json +1 -0
- package/testflows/435d3b48dd0f462c/flows.json +1 -0
- package/testflows/44f12f6e4a455084/flows.json +272 -0
- package/testflows/45209c67f865ce73/flows.json +1 -0
- package/testflows/459322e0f8e0b785/flows.json +1 -0
- package/testflows/4657dbc0aa4a97bb/flows.json +268 -0
- package/testflows/47514a335b4cd67e/flows.json +362 -0
- package/testflows/486c1412721bb241/flows.json +525 -0
- package/testflows/48d9fdcde317974e/flows.json +1 -0
- package/testflows/4de34883c5d93dc3/flows.json +1 -0
- package/testflows/50d5679818477b66/flows.json +1 -0
- package/testflows/51870a76d1aaf67a/flows.json +1 -0
- package/testflows/51bfa9456b1745c0/flows.json +639 -0
- package/testflows/538be5947c639b32/flows.json +75 -0
- package/testflows/538d2f4704cd2eca/flows.json +1 -0
- package/testflows/5433b57035d597f9/flows.json +1 -0
- package/testflows/545871d31c3f5f3f/flows.json +376 -0
- package/testflows/55f105cfd894b06c/flows.json +121 -0
- package/testflows/55f7fbe90e5befa8/flows.json +1 -0
- package/testflows/562c518969666f24/flows.json +1 -0
- package/testflows/57d44c342a1f00e2/flows.json +1 -0
- package/testflows/597ee2a683d9908f/flows.json +129 -0
- package/testflows/59aa8a866d8d7a70/flows.json +1 -0
- package/testflows/59da63b5adb460db/flows.json +188 -0
- package/testflows/5a06352874fa379d/flows.json +1 -0
- package/testflows/5cd133958df17529/flows.json +1 -0
- package/testflows/5cf6aec7d688fce4/flows.json +1 -0
- package/testflows/5d4908af3d4f95e5/flows.json +1 -0
- package/testflows/5e07acf2da13b504/flows.json +1 -0
- package/testflows/5f6929bb3374b782/flows.json +1 -0
- package/testflows/61142eb3e4e54eab/flows.json +536 -0
- package/testflows/61847d719e50f83f/flows.json +1 -0
- package/testflows/63ca9baf860d1d8f/flows.json +1 -0
- package/testflows/641ddaab2819c61d/flows.json +1 -0
- package/testflows/64445798b59d2630/flows.json +257 -0
- package/testflows/684b9066e98b9722/flows.json +1 -0
- package/testflows/698b83b8aeb5d5b6/flows.json +1 -0
- package/testflows/6a9ffd45c418497b/flows.json +1 -0
- package/testflows/6d46e3fe1f2245b8/flows.json +86 -0
- package/testflows/6dd3a5754f83dc2e/flows.json +232 -0
- package/testflows/6ea4c6b373eeaa8d/flows.json +1 -0
- package/testflows/6f0dcbf18234c5e2/flows.json +1 -0
- package/testflows/6ff45e2a0ce77393/flows.json +149 -0
- package/testflows/700c94899fdd3334/flows.json +107 -0
- package/testflows/71f65246c742cfc9/flows.json +1 -0
- package/testflows/7581c2be261f9c17/flows.json +1874 -0
- package/testflows/77854a5ea962257b/flows.json +1 -0
- package/testflows/7b77600dcf78933f/flows.json +1 -0
- package/testflows/7dae2b1a7881c607/flows.json +1 -0
- package/testflows/7e1d04570c6bdff9/flows.json +1 -0
- package/testflows/7ecfd18f58fc6510/flows.json +1 -0
- package/testflows/7fea9696f6186962/flows.json +141 -0
- package/testflows/80655e5d4035fa71/flows.json +215 -0
- package/testflows/8180ae5891c673de/flows.json +1 -0
- package/testflows/8421f37b6c40e1ec/flows.json +1 -0
- package/testflows/84a5a362cafe703f/flows.json +1 -0
- package/testflows/866410b56fa42447/flows.json +1076 -0
- package/testflows/894f6e38bfd1aca6/flows.json +1 -0
- package/testflows/89aeaeef64509bed/flows.json +101 -0
- package/testflows/8a627c9bfe3b4aff/flows.json +552 -0
- package/testflows/8bc7412d6a4869c6/flows.json +1 -0
- package/testflows/92054e0dd22f14c6/flows.json +1 -0
- package/testflows/93c6e969dcf84e70/flows.json +1 -0
- package/testflows/9463eba0ab843567/flows.json +1 -0
- package/testflows/96f6f83dcab507e5/flows.json +105 -0
- package/testflows/9746601768c3b3b6/flows.json +93 -0
- package/testflows/987cd33b9cda8529/flows.json +1 -0
- package/testflows/988f27b9abdde6e9/flows.json +1 -0
- package/testflows/9942fa1aeb1b2428/flows.json +2346 -0
- package/testflows/9a1bdfdcd7b2be8e/flows.json +1 -0
- package/testflows/9b1023c95a2613cc/flows.json +141 -0
- package/testflows/9c51a179141515b2/flows.json +1 -0
- package/testflows/9d11bfc3a6d88535/flows.json +301 -0
- package/testflows/9e7ccc97f80d9afb/flows.json +93 -0
- package/testflows/9f0d6c3ad7798a77/flows.json +142 -0
- package/testflows/9f7351d7a7304584/flows.json +83 -0
- package/testflows/9ff2e8ab21d922c5/flows.json +1 -0
- package/testflows/a123cd431f1967cd/flows.json +1757 -0
- package/testflows/a4c9cabf4b335488/flows.json +86 -0
- package/testflows/a6dc7002d0a8640e/flows.json +1 -0
- package/testflows/a862ae412a70ded1/flows.json +1 -0
- package/testflows/a916165378c446e3/flows.json +240 -0
- package/testflows/ad2bf1089481dcfb/flows.json +1 -0
- package/testflows/ae38b2dbd23d1681/flows.json +3089 -0
- package/testflows/ae8a9b0bbbaff447/flows.json +271 -0
- package/testflows/b07b511dc8bb8339/flows.json +92 -0
- package/testflows/b1430ea37ba7cc19/flows.json +1 -0
- package/testflows/b1463d7bbf545725/flows.json +1 -0
- package/testflows/b1501de32c769cf2/flows.json +94 -0
- package/testflows/b2a67e301fabab0e/flows.json +1 -0
- package/testflows/b2fcc5806b2715c0/flows.json +1 -0
- package/testflows/b3f365d0b7d1f97d/flows.json +1 -0
- package/testflows/b50f775ae3b74d38/flows.json +1 -0
- package/testflows/b5fbcdbffb568569/flows.json +1 -0
- package/testflows/b6d4e4592b27a344/flows.json +1 -0
- package/testflows/b723353a316fa50e/flows.json +1 -0
- package/testflows/b7ebaf91f4d66ab3/flows.json +1 -0
- package/testflows/b85795a24882502b/flows.json +1 -0
- package/testflows/b864b3e3510cd120/flows.json +205 -0
- package/testflows/b98d0b05a760ad79/flows.json +1 -0
- package/testflows/b9cd19107a5145c4/flows.json +1 -0
- package/testflows/bbb1fc2d47c3cd5f/flows.json +1 -0
- package/testflows/bdbe94d065f3b3a6/flows.json +143 -0
- package/testflows/bfced61e72c69715/flows.json +616 -0
- package/testflows/c0b1cf6656eac77f/flows.json +518 -0
- package/testflows/c1370220fd37968e/flows.json +1 -0
- package/testflows/c163c627bd2a37c7/flows.json +1 -0
- package/testflows/c274a07715a87ca4/flows.json +1 -0
- package/testflows/c28048d859db3773/flows.json +1 -0
- package/testflows/c381b5135cc947cd/flows.json +272 -0
- package/testflows/c4690c0a085d6ef5/flows.json +145 -0
- package/testflows/c5f513bc380bc30a/flows.json +696 -0
- package/testflows/c6ee6e89a51c98fc/flows.json +1 -0
- package/testflows/c843dacf753a19d8/flows.json +1 -0
- package/testflows/caccb020fce3f485/flows.json +1 -0
- package/testflows/cd44a688eb2ab3cf/flows.json +1 -0
- package/testflows/ce2f98273da05245/flows.json +1 -0
- package/testflows/ced70c769db825eb/flows.json +1 -0
- package/testflows/cef9dd7dc179b8b3/flows.json +1 -0
- package/testflows/cfa8595b2e2b8269/flows.json +255 -0
- package/testflows/cffa610c817beb43/flows.json +1 -0
- package/testflows/d17062b01c4a9435/flows.json +1 -0
- package/testflows/d17fb2553fe8013a/flows.json +157 -0
- package/testflows/d206746f9f2594a6/flows.json +1 -0
- package/testflows/d4ce58359ff6ff96/flows.json +1 -0
- package/testflows/d5424657b497d5af/flows.json +1 -0
- package/testflows/d595c53abba88f72/flows.json +1 -0
- package/testflows/d61182e87a604efa/flows.json +340 -0
- package/testflows/def45a46c8f4da72/flows.json +1 -0
- package/testflows/def56742e02f6a75/flows.json +1 -0
- package/testflows/e1ced3b16782f7c8/flows.json +1 -0
- package/testflows/e2a801d2b3e2143f/flows.json +1 -0
- package/testflows/e7184b7ca4f07907/flows.json +1 -0
- package/testflows/ea246f68766c8630/flows.json +1 -0
- package/testflows/eb447048178f6e16/flows.json +201 -0
- package/testflows/ec921769b3c24fb6/flows.json +1 -0
- package/testflows/ed621e03921c13de/flows.json +1 -0
- package/testflows/eed68dbcecd1431f/flows.json +204 -0
- package/testflows/ef61f644d5436dbe/flows.json +1 -0
- package/testflows/f19fdae0c02b4f03/flows.json +1008 -0
- package/testflows/f1e71f2ccb34fd6e/flows.json +1 -0
- package/testflows/f2f61ec9fc46a468/flows.json +575 -0
- package/testflows/f346d45c81f595e5/flows.json +501 -0
- package/testflows/f38603a59963386c/flows.json +1 -0
- package/testflows/f4c4a57e77439a1b/flows.json +1 -0
- package/testflows/f5bdafa844f6d280/flows.json +1 -0
- package/testflows/f5f82ca50317fda7/flows.json +121 -0
- package/testflows/f8727464c799eb22/flows.json +1 -0
- package/testflows/f946aafaebb1398d/flows.json +160 -0
- package/testflows/f94db507552f4934/flows.json +183 -0
- package/testflows/fb50bac16667fc54/flows.json +364 -0
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
2
|
(function(){
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function frontendSupportFunction() {
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
var functTwo = (arg) => {
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
3
|
+
|
|
12
4
|
RED.nodes.registerType('ut-assert-success',{
|
|
13
5
|
color: '#addb7b',
|
|
14
6
|
icon: "font-awesome/fa-smile-o",
|
|
@@ -17,6 +9,9 @@
|
|
|
17
9
|
name: {
|
|
18
10
|
value:"",
|
|
19
11
|
},
|
|
12
|
+
msglimit: {
|
|
13
|
+
value:"=="
|
|
14
|
+
},
|
|
20
15
|
count: {
|
|
21
16
|
value: 1,
|
|
22
17
|
required: true,
|
|
@@ -36,8 +31,8 @@
|
|
|
36
31
|
|
|
37
32
|
if ( this.count == "") { this.count = 1 }
|
|
38
33
|
|
|
39
|
-
if ( this.count >
|
|
40
|
-
label = `${label}: ${this.count}`
|
|
34
|
+
if ( this.count > 0 ) {
|
|
35
|
+
label = `${label}: ${this.msglimit || '=='} ${this.count}`
|
|
41
36
|
}
|
|
42
37
|
return label;
|
|
43
38
|
},
|
|
@@ -55,6 +50,21 @@
|
|
|
55
50
|
|
|
56
51
|
oneditprepare: function() {
|
|
57
52
|
if (!this.count || this.count == "") { this.count = 1 }
|
|
53
|
+
|
|
54
|
+
$(".limit-msgcnt-button-group").removeClass("selected")
|
|
55
|
+
$('#node-input-msglimit').val(this.msglimit || "==")
|
|
56
|
+
|
|
57
|
+
$(".limit-msgcnt-button-group").map((i, d) => {
|
|
58
|
+
if ($(d).data("value") == $('#node-input-msglimit').val()) {
|
|
59
|
+
$(d).addClass("selected")
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
$(".limit-msgcnt-button-group").on("click", function () {
|
|
64
|
+
$(".limit-msgcnt-button-group").removeClass("selected");
|
|
65
|
+
$(this).addClass("selected");
|
|
66
|
+
$('#node-input-msglimit').val($(this).data("value"))
|
|
67
|
+
})
|
|
58
68
|
},
|
|
59
69
|
|
|
60
70
|
oneditcancel: function() {
|
|
@@ -78,9 +88,20 @@
|
|
|
78
88
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
|
79
89
|
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
|
80
90
|
</div>
|
|
81
|
-
|
|
91
|
+
|
|
82
92
|
<div class="form-row">
|
|
83
93
|
<label for="node-input-count" data-i18n="ut-assert-success.label.count"></label>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<span class="button-group">
|
|
97
|
+
<button type="button" data-value="<=" class="red-ui-button toggle limit-msgcnt-button-group selected"><span data-i18n="ut-assert-success.label.limit.upperlimit"></span></button>
|
|
98
|
+
<button type="button" data-value="=="class="red-ui-button toggle limit-msgcnt-button-group"><span data-i18n="ut-assert-success.label.limit.exactly"></span></button>
|
|
99
|
+
<button type="button" data-value=">=" class="red-ui-button toggle limit-msgcnt-button-group"><span data-i18n="ut-assert-success.label.limit.lowerlimit"></span></button>
|
|
100
|
+
</span>
|
|
101
|
+
|
|
102
|
+
<input type="text" id="node-input-msglimit" class='hide'></input>
|
|
84
103
|
<input type="number" id="node-input-count" data-i18n="[placeholder]ut-assert-success.placeholder.count" style="width: 100px;"></input>
|
|
104
|
+
|
|
105
|
+
<span data-i18n="ut-assert-success.label.messages"></span>
|
|
85
106
|
</div>
|
|
86
107
|
</script>
|
|
@@ -1,43 +1,74 @@
|
|
|
1
|
-
module.exports = function(RED) {
|
|
1
|
+
module.exports = function (RED) {
|
|
2
2
|
function CoreutassertsuccessFunctionality(config) {
|
|
3
|
-
RED.nodes.createNode(this,config);
|
|
3
|
+
RED.nodes.createNode(this, config);
|
|
4
4
|
|
|
5
5
|
var node = this;
|
|
6
6
|
var cfg = config;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
let hasFailed = () => {
|
|
9
|
+
if (!cfg.msglimit) { cfg.msglimit = "==" }
|
|
10
|
+
let msgcnt = (node.context().get("msgcnt") || 0)
|
|
11
|
+
|
|
12
|
+
if (cfg.count == 0) { return msgcnt < 1 } // zero count means 1 and above, so a msgcnt of zero is only failure
|
|
13
|
+
else if (cfg.msglimit == "==") { return msgcnt != cfg.count }
|
|
14
|
+
else if (cfg.msglimit == ">=") { return msgcnt < cfg.count }
|
|
15
|
+
else if (cfg.msglimit == "<=") { return msgcnt > cfg.count }
|
|
16
|
+
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
node.on('close', function (removed, done) {
|
|
21
|
+
if (removed) {
|
|
22
|
+
if ( hasFailed() ) {
|
|
23
|
+
RED.comms.publish("unittesting:testresults", {
|
|
24
|
+
flowid: node.z,
|
|
25
|
+
status: "failed"
|
|
26
|
+
})
|
|
27
|
+
node.status({ fill: "red", shape: "ring", text: RED._("ut-assert-success.label.failed") + `: ${cfg.count} ${cfg.msglimit} ${node.context().get("msgcnt") || 0}` });
|
|
28
|
+
// use node.log(..) here because node.error(..) sends a message to the debug
|
|
29
|
+
// panel but that errors out because the frontend can't find the workspace:
|
|
30
|
+
// Uncaught TypeError: can't access property "label", RED.nodes.workspace(...) is undefined
|
|
31
|
+
// that has follow-on effects.
|
|
32
|
+
// see https://nodered.org/docs/creating-nodes/node-js#logging-events for more details
|
|
33
|
+
node.log(`FAILED [${node.z}] assert success node failed: ${cfg.count} ${cfg.msglimit} ${node.context().get("msgcnt") || 0}`)
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
node.status({});
|
|
37
|
+
}
|
|
38
|
+
|
|
9
39
|
node.context().set("msgcnt", 0)
|
|
10
|
-
|
|
40
|
+
done();
|
|
11
41
|
});
|
|
12
42
|
|
|
13
43
|
/* msg handler, in this case pass the message on unchanged */
|
|
14
|
-
node.on("input", function(msg, send, done) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
node.on("input", function (msg, send, done) {
|
|
45
|
+
let msgcnt = (node.context().get("msgcnt") || 0) + 1;
|
|
46
|
+
node.context().set("msgcnt", msgcnt)
|
|
47
|
+
|
|
48
|
+
// How to send a status update
|
|
49
|
+
if (!hasFailed()) {
|
|
50
|
+
node.status({ fill: "green", shape: "ring", text: RED._("ut-assert-success.label.succeed") });
|
|
51
|
+
setTimeout(() => { node.status({}); }, 1000)
|
|
52
|
+
} else {
|
|
53
|
+
// node.status({ fill: "red", shape: "ring", text: RED._("ut-assert-success.label.failed") + `: ${cfg.count} != ${msgcnt}` });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Send a message and how to handle errors.
|
|
57
|
+
try {
|
|
26
58
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
done();
|
|
30
|
-
} catch ( err ) {
|
|
31
|
-
// use node.error if the node might send subsequent messages
|
|
32
|
-
node.error("error occurred", { ...msg, error: err })
|
|
33
|
-
done();
|
|
34
|
-
}
|
|
59
|
+
send(msg);
|
|
60
|
+
done();
|
|
35
61
|
} catch (err) {
|
|
36
|
-
// use
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
done(err.message, msg)
|
|
62
|
+
// use node.error if the node might send subsequent messages
|
|
63
|
+
node.error("error occurred", { ...msg, error: err })
|
|
64
|
+
done();
|
|
40
65
|
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
// use done if the node won't send anymore messages for the
|
|
68
|
+
// message it received.
|
|
69
|
+
msg.error = err
|
|
70
|
+
done(err.message, msg)
|
|
71
|
+
}
|
|
41
72
|
});
|
|
42
73
|
}
|
|
43
74
|
|
|
@@ -5,6 +5,14 @@ module.exports = function(RED) {
|
|
|
5
5
|
var node = this;
|
|
6
6
|
var cfg = config;
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
//
|
|
11
|
+
// Helper Code
|
|
12
|
+
//
|
|
13
|
+
//
|
|
14
|
+
|
|
15
|
+
|
|
8
16
|
/*
|
|
9
17
|
* Note to self: getMessageProperty(..) and getObjectProperty(...) only differ in that
|
|
10
18
|
* getMessageProperty will remove any 'msg.' prefix from the property name. This is not
|
|
@@ -17,7 +25,6 @@ module.exports = function(RED) {
|
|
|
17
25
|
* getObjectProperty will return undefined if a property isn't set.
|
|
18
26
|
*/
|
|
19
27
|
|
|
20
|
-
|
|
21
28
|
var sendToDebug = (nde,rule,msgc,lvl) => {
|
|
22
29
|
try {
|
|
23
30
|
let msg = {
|
|
@@ -33,7 +40,15 @@ module.exports = function(RED) {
|
|
|
33
40
|
|
|
34
41
|
msg = RED.util.encodeObject(msg);
|
|
35
42
|
if (!cfg.ignore_failure_if_succeed) {
|
|
36
|
-
|
|
43
|
+
// don't post debug, causes error in the editor because the flow does not
|
|
44
|
+
// exist in the workspace of the editor - flow is loaded in the backend only.
|
|
45
|
+
if (!msg._unittest_triggered) {
|
|
46
|
+
RED.comms.publish("debug", msg);
|
|
47
|
+
} else {
|
|
48
|
+
// send details to the console.
|
|
49
|
+
node.log(`ASSERT FAILURE [${node.z}] assert values failed`)
|
|
50
|
+
console.log(msg)
|
|
51
|
+
}
|
|
37
52
|
}
|
|
38
53
|
} catch (ex) {
|
|
39
54
|
console.error(ex)
|
|
@@ -45,23 +60,61 @@ module.exports = function(RED) {
|
|
|
45
60
|
node.status({ fill: "red", shape: "dot",
|
|
46
61
|
text: RED._("ut-assert-values.label.unsupported", { property: JSON.stringify(rule) }) });
|
|
47
62
|
sendToDebug(node, rule, msg, 30)
|
|
48
|
-
|
|
63
|
+
|
|
64
|
+
RED.comms.publish("unittesting:testresults", {
|
|
65
|
+
flowid: node.z,
|
|
66
|
+
status: "pending"
|
|
67
|
+
})
|
|
68
|
+
|
|
49
69
|
return ["unsupported", rule]
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
var escapeSpecials = (str) => {
|
|
53
|
-
return str ? str.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replaceAll(/\t/g, "\\t") : str
|
|
73
|
+
return (str && str.replace && (typeof str.replace == "function")) ? str.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replaceAll(/\t/g, "\\t") : str
|
|
54
74
|
}
|
|
55
75
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
//
|
|
77
|
+
//
|
|
78
|
+
// Event Hander code
|
|
79
|
+
//
|
|
80
|
+
//
|
|
81
|
+
|
|
82
|
+
/* initialise and close handler - if removed is false, then this is an initailise */
|
|
83
|
+
node.on('close', function(removed, done) {
|
|
84
|
+
if (removed) {
|
|
85
|
+
if ((!node.context().get("succeed") && !cfg.ignore_failure_if_succeed) || !node.context().get("received_message")) {
|
|
86
|
+
RED.comms.publish("unittesting:testresults", {
|
|
87
|
+
flowid: node.z,
|
|
88
|
+
status: "failed"
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
node.status({ fill: "red", shape: "dot", text: "assert failed" })
|
|
92
|
+
|
|
93
|
+
// use node.log(..) here because node.error(..) sends a message to the debug
|
|
94
|
+
// panel but that errors out because the frontend can't find the workspace:
|
|
95
|
+
// Uncaught TypeError: can't access property "label", RED.nodes.workspace(...) is undefined
|
|
96
|
+
// that has follow-on effects.
|
|
97
|
+
// see https://nodered.org/docs/creating-nodes/node-js#logging-events for more details
|
|
98
|
+
if (!node.context().get("received_message")) {
|
|
99
|
+
node.log(`FAILED [${node.z}] Assert Values node not reached`)
|
|
100
|
+
} else {
|
|
101
|
+
node.log(`FAILED [${node.z}] Assert values node failed`)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
node.status({});
|
|
106
|
+
node.context().set("succeed", false)
|
|
107
|
+
node.context().set("received_message", false)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
done()
|
|
59
111
|
});
|
|
60
112
|
|
|
61
113
|
/* msg handler, in this case pass the message on unchanged */
|
|
62
114
|
node.on("input", function(msg, send, done) {
|
|
63
115
|
var failures = [];
|
|
64
116
|
var unsupported = [];
|
|
117
|
+
node.context().set("received_message", true)
|
|
65
118
|
|
|
66
119
|
try {
|
|
67
120
|
cfg.rules.forEach(rule => {
|
|
@@ -75,8 +128,14 @@ module.exports = function(RED) {
|
|
|
75
128
|
failures.push(sendToDebug(node, rule, msg, 20))
|
|
76
129
|
}
|
|
77
130
|
} else if ( rule.tot == "num") {
|
|
78
|
-
if (
|
|
79
|
-
|
|
131
|
+
if (rule.to == "NaN") {
|
|
132
|
+
if ( !isNaN(RED.util.getObjectProperty(msg, rule.p)) ) {
|
|
133
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
if ( rule.to != RED.util.getObjectProperty(msg,rule.p) ) {
|
|
137
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
138
|
+
}
|
|
80
139
|
}
|
|
81
140
|
} else if (rule.tot == "bin") {
|
|
82
141
|
let expBuffer = Buffer.from(JSON.parse(rule.to));
|
|
@@ -90,17 +149,44 @@ module.exports = function(RED) {
|
|
|
90
149
|
} else if (rule.to == "false" && !!RED.util.getObjectProperty(msg, rule.p) ) {
|
|
91
150
|
failures.push(sendToDebug(node, rule, msg, 20))
|
|
92
151
|
}
|
|
152
|
+
} else if (rule.tot == "jsonata") {
|
|
153
|
+
try {
|
|
154
|
+
let jsonExpr = RED.util.prepareJSONataExpression(rule.to, node);
|
|
155
|
+
|
|
156
|
+
RED.util.evaluateJSONataExpression(jsonExpr, msg, (err, value) => {
|
|
157
|
+
if (err) {
|
|
158
|
+
rule._err = err
|
|
159
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
160
|
+
} else {
|
|
161
|
+
if (value != escapeSpecials(RED.util.getObjectProperty(msg, rule.p))) {
|
|
162
|
+
rule._vt = escapeSpecials(RED.util.getObjectProperty(msg, rule.p))
|
|
163
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} catch (e) {
|
|
168
|
+
rule._err = e
|
|
169
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
170
|
+
}
|
|
171
|
+
|
|
93
172
|
} else if (rule.tot == "json") {
|
|
94
173
|
let expObj = JSON.parse(rule.to)
|
|
95
174
|
let oldObj = RED.util.getObjectProperty(msg, rule.p)
|
|
96
175
|
|
|
97
|
-
|
|
98
|
-
|
|
176
|
+
// special case: null or undefined
|
|
177
|
+
if (!expObj) {
|
|
178
|
+
if (oldObj != null && oldObj != undefined) {
|
|
99
179
|
failures.push(sendToDebug(node, rule, msg, 20))
|
|
100
180
|
}
|
|
101
181
|
} else {
|
|
102
|
-
if (
|
|
103
|
-
|
|
182
|
+
if ( Array.isArray(expObj)) {
|
|
183
|
+
if (JSON.stringify(oldObj) != JSON.stringify(expObj)) {
|
|
184
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
if ( JSON.stringify(oldObj, Object.keys(oldObj).sort()) != JSON.stringify(expObj, Object.keys(expObj).sort()) ) {
|
|
188
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
189
|
+
}
|
|
104
190
|
}
|
|
105
191
|
}
|
|
106
192
|
} else if (rule.tot == "msg") {
|
|
@@ -137,16 +223,37 @@ module.exports = function(RED) {
|
|
|
137
223
|
unsupported.push(postUnsupported(rule,msg))
|
|
138
224
|
}
|
|
139
225
|
/*
|
|
140
|
-
* Rule is not equal
|
|
226
|
+
* Rule is not equal - both value are msg properties
|
|
141
227
|
*/
|
|
142
228
|
} else if (rule.t == "noteql" && rule.pt == "msg" && rule.tot == "msg") {
|
|
143
|
-
/* comparing two values on the message object */
|
|
144
229
|
let expObj = RED.util.getObjectProperty(msg, rule.to)
|
|
145
230
|
let oldObj = RED.util.getObjectProperty(msg, rule.p)
|
|
146
231
|
if (expObj == oldObj) {
|
|
147
232
|
failures.push(sendToDebug(node, rule, msg, 20))
|
|
148
233
|
}
|
|
149
234
|
/*
|
|
235
|
+
* Rule is not equal - comparing message property to string value
|
|
236
|
+
*/
|
|
237
|
+
} else if (rule.t == "noteql" && rule.pt == "msg" && rule.tot == "str") {
|
|
238
|
+
let expValue = rule.to
|
|
239
|
+
let msgValue = RED.util.getObjectProperty(msg, rule.p)
|
|
240
|
+
if (expValue == escapeSpecials(msgValue)) {
|
|
241
|
+
rule._vt = escapeSpecials(msgValue)
|
|
242
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/*
|
|
246
|
+
* Rule is not equal - comparing message property to number value
|
|
247
|
+
*/
|
|
248
|
+
} else if (rule.t == "noteql" && rule.pt == "msg" && rule.tot == "num") {
|
|
249
|
+
let expValue = rule.to
|
|
250
|
+
let msgValue = RED.util.getObjectProperty(msg, rule.p)
|
|
251
|
+
if (expValue == msgValue) {
|
|
252
|
+
rule._vt = msgValue
|
|
253
|
+
failures.push(sendToDebug(node, rule, msg, 20))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/*
|
|
150
257
|
* Other rule types are not supported
|
|
151
258
|
*/
|
|
152
259
|
} else {
|
|
@@ -156,11 +263,12 @@ module.exports = function(RED) {
|
|
|
156
263
|
|
|
157
264
|
if (node.context().get("succeed") && cfg.ignore_failure_if_succeed) {
|
|
158
265
|
node.status({ fill: "green", shape: "ring", text: "assert succeed" })
|
|
266
|
+
setTimeout(() => { node.status({}); }, 1000)
|
|
159
267
|
} else {
|
|
160
268
|
if (failures.length > 0 ) {
|
|
161
269
|
node.status({fill: "red", shape: "dot", text: "assert failed"})
|
|
162
270
|
msg.assert_succeed = false
|
|
163
|
-
msg.assert_failures = failures.concat(unsupported)
|
|
271
|
+
msg.assert_failures = failures.concat(unsupported)
|
|
164
272
|
} else {
|
|
165
273
|
if ( unsupported.length > 0) {
|
|
166
274
|
node.status({ fill: "yellow", shape: "ring", text: "unsupported errors - check debug" })
|
|
@@ -169,6 +277,8 @@ module.exports = function(RED) {
|
|
|
169
277
|
} else {
|
|
170
278
|
node.context().set("succeed",true)
|
|
171
279
|
node.status({ fill: "green", shape: "ring", text: "assert succeed" })
|
|
280
|
+
setTimeout(() => { node.status({}); }, 1000)
|
|
281
|
+
|
|
172
282
|
msg.assert_succeed = true
|
|
173
283
|
delete msg.assert_failures
|
|
174
284
|
}
|