Reputation: 67
I will run mocha test suite's to test a node-red node. Therefore i use mocha and the selenium driver.
I had a Problem to run the node-red module.
If i start the test with $ mocha --ui **tdd**
the node-red application cant't find my flow. Because he is searching in folder '~/.node-red/tdd'. I don't known why the mocha [option] is set as path?
Only with command $ mocha
the function suite();
is not define?
I would solve the problem to init node-red with my own settings. Like this way.. http://nodered.org/docs/embedding.html
With this way i can run node-red after 'RED.start()' but i get no URL and can't open node-red in the selenium driver?
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);
});
});
Upvotes: 0
Views: 1258
Reputation: 67
solved
The Problem was the 'var driver' In the first 'suite()' i initialized a new 'var drive;' and overwrites the first one. Thats a silly fault.
...
suite('node', function(){
-- var driver;
++ //var drive;
...
Upvotes: 0
Reputation: 59866
You have set the default route
app.use("/",express.static("public"));
This is going to clash with Node-RED unless you set the Node-RED routes to something different.
You need to set the httpNodeRoot and the httpAdminRoot in your settings e.g.
var settings = {
settingsFile:"/usr/local/lib/node_modules/node-red/settings.js",
userDir:"/home/<user>/.nodered",
flowFile: "flow_<name>.json",
httpAdminRoot:"/red",
httpNodeRoot: "/api",
functionGlobalContext: { } // enables global context
};
If you do this then you would access Node-RED on localhost as follows:
EDIT: You only need to set the httpNodeRoot if you are using the httpIn node
Upvotes: 1