"Make sure we still serve a plain old html file": function(done){ jQuery.ajax("http://localhost:8080/test.html") .done(function(html){ assert(html == "hello html"); done(); }) .fail(function(err){ assert(err == false); }); },
"Try for French in welcome file": function(done){ jQuery.ajax("http://localhost:8080/fr/") .done(function(html){ assert(html == "<!Doctype html><body>Bonjour</body></html>"); done(); }) .fail(function(err){ assert(err == false); }); },
"Try for English": function(done){ jQuery.ajax("http://localhost:8080/multilingual.js.html") .done(function(html){ assert(html == "Hello"); done(); }) .fail(function(err){ assert(err == false); }); },
"Try for French": function(done){ jQuery.ajax("http://localhost:8080/fr/multilingual.js.html") .done(function(html){ assert(html == "Bonjour"); done(); }) .fail(function(err){ assert(err == false); }); },
"Install it and test for welcome file": function(done){ // we don't seem to be able to have an engine with a . in it. app.get("*.js.html", renderAsync.renderAsync); jQuery.ajax("http://localhost:8080/") .done(function(html){ assert(html == "<!Doctype html><body>Hello</body></html>"); done(); }) .fail(function(err){ assert(err == false); }); },
"Install it and test with js.html extension": function(done){ // we don't seem to be able to have an engine with a . in it. app.get("*.js.html", renderAsync.renderAsync); jQuery.ajax("http://localhost:8080/include.js.html") .done(function(html){ assert(html == "<!Doctype html><body>included from _included.js.html <p>Rich was here</p></body></html>"); done(); }) .fail(function(err){ assert(err == false); }); },
"do a post and make sure we get our variables": function(done){ jQuery.ajax({ url: "http://localhost:8080/test4", type:"post", headers:{ "Content-type": "application/x-www-form-urlencoded" }, data: "test1=test2&test3=test4", dataType: "json" }) .done(function(html){ console.log(html); done(); }). fail(function(err){ console.log(err); assert(err == false); }); }
var renderAsync = require('render-async'), Io = require('socket.io'), jQuery = require('js-toolbox')._jQuery, Chat = require('./jssrc/chat.js'), Random = require('./jssrc/random.js'); //now we need a server for this so that we can test include var app= renderAsync.express(); app.set('views', __dirname + '/www'); // add a route to the random data app.get('/random', function(req, res){Random.random(req, res);}); //server everything index.html welcome file app.use(renderAsync.webServer); //set ipaddress from openshift, to command line or to localhost:8080 var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; var port = process.env.OPENSHIFT_NODEJS_PORT || parseInt(process.argv.pop()) || 8080; app.set('port', port); //start the server listening for requests var io = Io.listen(app.listen(port)); // set up a handler for new connections io.sockets.on("connection", jQuery.proxy(Chat.chat, io));