Permalink
Browse files

Couple of fixes plus working tests

  • Loading branch information...
1 parent e0810b0 commit 28296ca2f2f055db07a5386f3c21c40fc1d43309 @khrome khrome committed Dec 6, 2012
Showing with 32 additions and 38 deletions.
  1. +1 −3 protolus-resource.js
  2. +31 −35 test.js
@@ -42,7 +42,7 @@ var Options = new Class({
setOptions : function(options){
if(!this.options) this.options = {};
var value;
- for(key in options){
+ for(var key in options){
value = options[key];
if(this.on && key.substring(0,2) == 'on' && key.substring(2,3) == key.substring(2,3).toUpperCase()){
var event = key.substring(2,3).toLowerCase()+key.substring(3);
@@ -59,7 +59,6 @@ var Protolus = function(options){
Protolus.packages = ['mootools-core','protolus'];
Protolus.loaded = {};
Protolus.scripts = {};
- console.log('done');
}
}
@@ -231,7 +230,6 @@ ProtolusResource.JavascriptMainHandler = new Class({
},
handle : function(options, callback){
var text = options.body.replace( /\n/g, ' ').replace( /\\/g, '\\\\').replace(/'/g, "\\'");
- console.log(text);
options.body = 'Protolus.register(\''+options.name+'\', \''+text+'\')';
options.body += "\n"+' //@ sourceURL='+options.location+"\n"
callback(options.body);
View
@@ -1,65 +1,61 @@
var should = require("should");
var request = require('request');
var http = require('http');
-var port = 4599;
+var port = 221;
+var resource = require('./protolus-resource');
describe('ProtolusResource', function(){
describe('Simple \'test-component\' tests', function(){
- var server
+ var server;
+ var running = false;
before(function(done){
try{
server = http.createServer(function(req, res) {
- console.log('Server Running');
resource.handleResourceCalls(req, res, function(){
//serve a page
});
- done();
}).listen(port);
+ server.on("listening", function() {
+ running = true;
+ done();
+ });
}catch(ex){
should.not.exist(ex);
}
});
+
it('Server Runs', function(){
- //should.not.exist(ex);
- /*
- try{
- http.createServer(function(req, res) {
- console.log('Server Running');
- resource.handleResourceCalls(req, res, function(){
- //serve a page
- });
- }).listen(80);
- }catch(ex){
- should.not.exist(ex);
- }//*/
+ should.equal(running, true);
});
- it('js URL is non-empty and serves valid JS', function(){
- /*try{
- http.createServer(function(req, res) {
- console.log('Server Running');
- resource.handleResourceCalls(req, res, function(){
- //serve a page
- });
- }).listen(port);
- }catch(ex){
- should.not.exist(ex);
- }*/
- console.log('blah');
- request('http://localhost/js/test-component', function (error, response, body) {
- var check = require('syntax-error');
+
+ it('js URL is non-empty and serves valid JS', function(done){
+ request('http://localhost:'+port+'/js/test-component', function (error, response, body) {
if (!error && response.statusCode == 200) {
- should.not.equal(body, '');
+ var check = require('syntax-error');
+ body.should.not.equal('');
var err = check(body);
should.not.exist(err);
}
+ if(error) should.fail('Error fetching URL', error);
+ if(response.statusCode != 200) should.fail('Fetch not OK', 'Code:'+response.statusCode);
+ done();
});
});
- it('css URL is non-empty', function(){
- request('http://localhost/css/test-component', function (error, response, body) {
- var check = require('syntax-error');
+
+ it('css URL is non-empty', function(done){
+ request('http://localhost:'+port+'/css/test-component', function (error, response, body) {
if (!error && response.statusCode == 200) {
- should.not.equal(body, '');
+ var check = require('syntax-error');
+ body.should.not.equal('');
}
+ if(error) should.fail('Error fetching URL', error);
+ if(response.statusCode != 200) should.fail('Fetch not OK', 'Code:'+response.statusCode);
+ done();
});
});
+
+ after(function(done) {
+ server.close();
+ done();
+ });
});
});

0 comments on commit 28296ca

Please sign in to comment.