Permalink
Browse files

small changes, updates

  • Loading branch information...
khrome committed Dec 5, 2012
1 parent fdae387 commit 5f57fd2796e84425693c318db4f17c7ed89c7f00
Showing with 52 additions and 20 deletions.
  1. +15 −9 demo.js
  2. +2 −1 package.json
  3. +11 −10 protolus-resource.js
  4. +24 −0 test.js
View
24 demo.js
@@ -1,13 +1,19 @@
var resource = require('./protolus-resource');
-resource('test-component', function(test){
- //test.files('js', function(files){
- // console.log('files', files);
- //});
- var app = require('http').createServer(function handler(req, res) {
- resource.handleResourceCalls(req, res, function(){
- //serve a page
- });
+var app = require('http').createServer(function handler(req, res) {
+ resource.handleResourceCalls(req, res, function(){
+ //serve a page
});
- app.listen(80);
+});
+app.listen(80);
+
+var request = require('request');
+
+request('http://localhost/js/test-component', function (error, response, body) {
+ var check = require('syntax-error');
+ if (!error && response.statusCode == 200) {
+ var err = check(body);
+ if(err) throw('OMG, Error!')
+ else console.log('No Errors!');
+ }
});
View
@@ -28,7 +28,8 @@
},
"devDependencies": {
"mocha": "*",
- "should": "*"
+ "should": "*",
+ "request":"*"
},
"optionalDependencies": {},
"engines": {
View
@@ -79,6 +79,7 @@ var ProtolusResource = new Class({
if(type(resource) == 'string') resource = {name:resource};
if(resource.name.lastIndexOf('.') == -1) return; //no type, skip it
var resourceType = resource.name.substring(resource.name.lastIndexOf('.')+1);
+ //console.log('?', resourceType.toLowerCase(), fileType.toLowerCase(), (resourceType.toLowerCase() == fileType.toLowerCase()) )
if(resourceType.toLowerCase() == fileType.toLowerCase()) result.push(resource.name);
});
callback(result);
@@ -167,10 +168,10 @@ var import_resource = function(name, callback){
count++;
import_resource(dependency, function(){
count--;
- if(count == 0) callback();
+ if(count == 0) callback(resource);
})
});
- if(count == 0) callback();
+ if(count == 0) callback(resource);
});
}
module.exports = function(name, callback){
@@ -191,21 +192,21 @@ module.exports.handleResourceCalls = function(request, response, passthru){
var uri = url.parse(request.url, true);
var value;
var wasResourceRequest = false;
- for(key in ProtolusResource.handlers){
+ for(var key in ProtolusResource.handlers){
if(wasResourceRequest) return;
if(uri.pathname.indexOf('/'+key+'/') === 0){
var rem = uri.pathname.substring(('/'+key+'/').length);
var resources = rem.split(".");
var results = [];
- var resource;
array.forEachEmission(resources, function(name, index, returnFn){
- resource = registry[name];
- resource.files(key, function(files){
- array.forEach(files, function(file){
- results.push(file);
+ import_resource(name, function(resource){
+ resource.files(key, function(files){
+ array.forEach(files, function(file){
+ results.push(file);
+ });
+ returnFn();
});
- returnFn();
- })
+ });
}, function(){
response.writeHead(200);
response.end(results.join("\n"));
View
24 test.js
@@ -0,0 +1,24 @@
+var should = require("should");
+var request = require('request');
+describe('ProtolusResource', function(){
+ describe('Simple \'test-component\' tests', function(){
+ it('js URL is non-empty and serves valid JS', function(){
+ request('http://localhost/js/test-component', function (error, response, body) {
+ var check = require('syntax-error');
+ if (!error && response.statusCode == 200) {
+ should.not.equal(body, '');
+ var err = check(body);
+ should.not.exist(err);
+ }
+ });
+ });
+ it('css URL is non-empty', function(){
+ request('http://localhost/css/test-component', function (error, response, body) {
+ var check = require('syntax-error');
+ if (!error && response.statusCode == 200) {
+ should.not.equal(body, '');
+ }
+ });
+ });
+ });
+});

0 comments on commit 5f57fd2

Please sign in to comment.