mocha change节点红色的流文件路径

时间:2015-09-22 12:32:00

标签: javascript mocha node-red

我有一个问题是用mocha实现节点红色节点的单元测试。

如果我用" $ sudo mocha -t 3000"运行我的测试node-red无法加载flow_user.json。因为选项' 3000'来自mocha的设置为'流文件中的目录:'路径。

node-opcua-client
✓ copy testfile 'flow/flows_user' (1509ms)
✓ run Node-Red  (1856ms)

Welcome to Node-RED
===================

22 Sep 14:13:03 - [info] Node-RED version: v0.11.1
22 Sep 14:13:03 - [info] Node.js  version: v0.12.3
22 Sep 14:13:03 - [info] Loading palette nodes
Warning : using memcpy : OK
FAST: using node-expat
22 Sep 14:13:04 - [warn] ------------------------------------------
22 Sep 14:13:04 - [warn] Failed to register 1 node type
22 Sep 14:13:04 - [warn] Run with -v for details
22 Sep 14:13:04 - [warn] ------------------------------------------
22 Sep 14:13:04 - [info] Settings file  : /usr/local/lib/node_modules/node-red/settings.js
22 Sep 14:13:04 - [info] User directory : /home/user/.node-red
22 Sep 14:13:04 - [info] Flows file : /home/user/.node-red/30000
22 Sep 14:13:04 - [info] Server now running at http://127.0.0.1:1880/
22 Sep 14:13:04 - [info] Creating new flow file
22 Sep 14:13:04 - [info] Starting flows
22 Sep 14:13:04 - [info] Started flows

在' test.js'我用

打开node-red
RED = require ('/usr/local/lib/node_modules/node-red/red.js');

我错了吗?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您需要在网站上查看嵌入节点RED文档:http://nodered.org/docs/embedding.html

但基本上你应该要求node-red然后创建一个设置对象来传入

var RED = require('node-red');
...
var server = http.createServer(app);
...
var settings = {
    httpAdminRoot:"/red",
    httpNodeRoot: "/api",
    userDir:"/home/nol/.nodered/",
    flowFile: "flow_user.json",
    functionGlobalContext: { }    // enables global context
};
...
RED.init(server,settings);