Skip to content

Commit

Permalink
fix(serve): serve system module
Browse files Browse the repository at this point in the history
  • Loading branch information
thepian committed Mar 29, 2015
1 parent 5bc2a05 commit 91ddaa4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/client/serve/dev.js
Expand Up @@ -22,7 +22,7 @@ module.exports = function (ss, router/*, options*/) {
clientId = thisUrl.pathname.split('/')[3],
bundler = ss.bundler.get({ name:clientName }),
params = thisUrl.query, //qs.parse(thisUrl.query),
content = '/* unknown */';
content;

if (params._) {
return bundler.asset(bundler.entryFor('css',params._), {
Expand All @@ -35,7 +35,7 @@ module.exports = function (ss, router/*, options*/) {
});
}

utils.serve.css(content, response);
utils.serve.css(content || '/* unknown module */', response);
}

function serveJS(request, response) {
Expand All @@ -44,10 +44,10 @@ module.exports = function (ss, router/*, options*/) {
clientId = thisUrl.pathname.split('/')[3],
bundler = ss.bundler.get({ name:clientName }),
params = thisUrl.query, //qs.parse(thisUrl.query),
content = '// unknown';
content;

if (params.mod) {
content = (bundler.module(params.mod) || {}).content;
content = (bundler.module(params.mod)[0] || {}).content;

} else if (params._) {

Expand All @@ -63,7 +63,7 @@ module.exports = function (ss, router/*, options*/) {
return utils.serve.js(output, response);
});
}
utils.serve.js(content, response);
utils.serve.js(content || '// unknown module', response);
}

//TODO bundler - formatter is predetermined
Expand Down
41 changes: 39 additions & 2 deletions test/unit/client/serve/dev.test.js
@@ -1,12 +1,49 @@
'use strict';

var path = require('path'),
should = require('should'),
ss = require( '../../../../lib/socketstream'),
Router = require('../../../../lib/http/router').Router,
options = ss.client.options,
defineAbcClient = require('../abcClient');

var responseStub = {
writeHead: function(status,headers) {},
end: function(body) {}
};


describe('development mode asset server', function () {

var router = new Router();


beforeEach(function() {

// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
});

afterEach(function() {
ss.client.forget();
});

it('should serve system loader module',function() {

var client = defineAbcClient({
code: './abc/index.a'
}, function() {
require('../../../../lib/client/serve/dev')(ss.api, router, options);
});

// dev time URL
var req = {url: '/assets/abc/'+client.id+'.js?mod=loader' };
router.route(req.url,req,responseStub).should.equal(true);
//TODO check that it's the right content
});

it('should provide a route for serving system libraries and modules');
it('should provide a route for serving system libraries and modules');



Expand All @@ -18,4 +55,4 @@ describe('development mode asset server', function () {



});
});

0 comments on commit 91ddaa4

Please sign in to comment.