我将运行 mocha 测试套件来测试 node-red 节点。因此我使用 mocha 和 selenium 驱动程序。
我在运行 node-red 模块时遇到了问题。如果我使用$ mocha --ui **tdd**
node-red 应用程序开始测试,则找不到我的流程。因为他正在文件夹“~/.node-red/ tdd ”中搜索。我不知道为什么将 mocha [option]设置为路径?只有命令$ mocha
功能suite();
没有定义?
我会用我自己的设置来解决这个问题来初始化 node-red。像这样.. http://nodered.org/docs/embedding.html
通过这种方式,我可以在“RED.start()”之后运行 node-red,但我没有得到 URL,并且无法在 selenium 驱动程序中打开 node-red?
require('colors');
var async = require ('async');
var fs = require('fs');
var node = require ('../../mynode.js');
var assert = require('node-assertthat');
var http = require('http');
var http = require('http');
var express = require("express");
var RED = require("node-red");
// Create an Express app
var app = express();
// Add a simple route for static content served from 'public'
app.use("/",express.static("public"));
// Create a server
var server = http.createServer(app);
var settings = {
settingsFile:"/usr/local/lib/node_modules/node-red/settings.js",
userDir:"/home/<user>/.nodered",
flowFile: "flow_<name>.json",
functionGlobalContext: { } // enables global context
};
// Initialise the runtime with a server and settings
RED.init(server,settings);
var webdriver = require('../'),
By = webdriver.By,
until = webdriver.until;
/* connect to selenium browser */
driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
suite('node', function(){
var driver;
suite('test setup', function(){
suite('connect to http://127.0.0.1:1880', function(){
setup(function(){
});
test('run Node-Red ',function(done){
setTimeout(function(){
/* run node-red */
RED.start();
done();
},2000);
});
test('open URL \'http://localhost:1880/#\'', function(done) {
setTimeout(function(){
driver.get('http://localhost:1880/#');
/* open node-red URL */
driver.getTitle().then(function(title) {
console.log('\nPage title is:\ '+ title.red.bold +"\n");
assert.that(title, is.equalTo('Node-RED'));
done();
});
},2000);
});
});