Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed timer logic, overcomplicated node. Started adding tests
- Loading branch information
Showing
10 changed files
with
4,260 additions
and
3,903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
class Context { | ||
constructor(type) { | ||
this._values = {}; | ||
this._type = type; | ||
} | ||
get(key) { | ||
return this._values[key]; | ||
} | ||
set(key, value) { | ||
console.log(this._type + ' context: set [' + key + '] => [' + value + ']'); | ||
this._values[key] = value; | ||
} | ||
} | ||
|
||
class MockNode { | ||
constructor() { | ||
this._events = {}; | ||
this._state = {}; | ||
this._sent = []; | ||
this._context = {}; | ||
this._status = {}; | ||
} | ||
|
||
log() { console.log(...arguments); } | ||
warn() { console.log(...arguments); } | ||
error() { console.log(...arguments); } | ||
on(event, eventFn) { | ||
this._events[event] = eventFn; | ||
} | ||
emit(event, data) { | ||
this._events[event].call(this, data); | ||
} | ||
status(status) { | ||
if (status) this._status = status; | ||
return status; | ||
} | ||
send(msg) { | ||
this._sent.push(msg); | ||
} | ||
sent(index) { | ||
return this._sent[index]; | ||
} | ||
context() { | ||
return this._context; | ||
} | ||
} | ||
|
||
module.exports = function(nodeRedModule, config) { | ||
const RED = { | ||
nodes: { | ||
getNode: () => {}, | ||
registerType: function(nodeName, nodeConfigFunc) { | ||
this.nodeConfigFunc = nodeConfigFunc; | ||
}, | ||
createNode: function() { | ||
// TODO write me | ||
} | ||
}, | ||
settings: { | ||
get: () => {} | ||
}, | ||
comms: { | ||
publish: () => true | ||
} | ||
}; | ||
const mockNode = new MockNode(); | ||
// Register the node (calls registerType) | ||
nodeRedModule(RED); | ||
return new RED.nodes.nodeConfigFunc.call(mockNode, config); // eslint-disable-line | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const test = require('tape'); | ||
const helper = require('node-red/test/nodes/helper'); | ||
const ConfigServerNode = require('../../nodes/config-server/config-server'); | ||
const ServerEventsNode = require('../../nodes/server-events-all/server-events-all'); | ||
|
||
test('before: start-server', function(t) { | ||
helper.startServer(() => t.end()); | ||
}); | ||
|
||
test('Simple Node: should load', function(t) { | ||
let flow = [ | ||
{ id: 'n1', type: 'server-events', server: 'n2', wires: [] }, | ||
{ id: 'n2', type: 'server', name: 'ha-server', url: 'http://localhost:1234', pass: '123' } | ||
]; | ||
|
||
helper.load([ServerEventsNode, ConfigServerNode], flow, function() { | ||
const n1 = helper.getNode('n1'); | ||
t.equals(n1.type, 'server-events', 'simple node should instantiate with type "simple-node"'); | ||
helper.unload(); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
// test('Simple Node: should send lowercased payload', function(t) { | ||
// let flow = [ | ||
// { id: 'n1', type: 'simple-node', server: 'n2', wires: [ ['n3'] ] }, | ||
// { id: 'n2', type: 'config-node', host: 'localhost', port: '1234' }, | ||
// { id: 'n3', type: 'helper' } | ||
// ]; | ||
|
||
// helper.load([ConfigNode, SimpleNode], flow, function() { | ||
// const n1 = helper.getNode('n1'); | ||
// const n3 = helper.getNode('n3'); | ||
|
||
// n3.on('input', function(msg) { | ||
// t.equals(msg.topic, expectedMsg.topic, 'topics should match'); | ||
// t.equals(msg.payload, expectedMsg.payload.toLowerCase(), 'payload should be lowercased match'); | ||
// t.end(); | ||
// }); | ||
|
||
// const expectedMsg = { topic: 'test', payload: 'ABC' }; | ||
// n1.receive(expectedMsg); | ||
// }); | ||
// }); | ||
|
||
test('after: stop-server', function(t) { | ||
helper.stopServer(); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.