Skip to content
Permalink
Browse files

cli test cases

  • Loading branch information...
bevacqua committed Nov 23, 2014
1 parent 15b574b commit f102974dea67422c8ded5f36772cb84b0056ac27
@@ -23,12 +23,11 @@ var bundle = argv.bundle;
var options = parse();

function parse () {
var t = argv.transform ? require(argv.transform) : identity;
var resolvers = argv.resolvers && require(argv.resolvers);
var defer = getDeferred();
return {
resolvers: resolvers,
transform: t,
transform: argv.transform,
deferred: defer
};
function getDeferred () {
@@ -55,8 +54,6 @@ function output (force) {
}
}

function identity (d) { return d; }

function browser () {
var b = browserify();
var lib = path.join(__dirname, '../browser/bundle');
@@ -13,6 +13,8 @@ var deferred = require('./deferred');
resolvers.use(shared);
resolvers.use(defaults);

function identity (d) { return d; }

function getRoutes (replacements, force) {
if (replacements) {
resolvers.use(replacements);
@@ -29,6 +31,7 @@ function getRoutes (replacements, force) {
function render (o, force) {
var options = o || {};
if (!options.deferred) { options.deferred = []; }
var interpreter = options.transform ? require(options.transform) : identity;
var routes = getRoutes(options.resolvers, force);
var buffer = [];
var templates = glob.sync(path.join(rc.views, '**/*.js'));
@@ -92,11 +95,15 @@ function render (o, force) {
}

function route (data) {
var caching = data.cache === true || typeof data.cache === 'number';
var caching = typeof data.cache === 'boolean' || typeof data.cache === 'number';

if (!data.route) {
return;
}

put(br(!first));
put(' {\n');
put(' route: "%s"%s', options.transform(data.route), br(data.action || data.ignore || caching));
put(' route: "%s"%s', interpreter(data.route), br(data.action || data.ignore || caching));

if (data.action) {
put(' action: "%s"%s', data.action, br(data.ignore || caching));
@@ -3,12 +3,32 @@
var fs = require('fs');
var test = require('tape');
var rc = require('../../lib/rc');
var cases = [
'cli produces empty wiring module',
'cli ignores unrouted actions',
'cli lists routes',
'cli lists routes and uses ignore parameter',
'cli lists routes and uses cache parameters correctly',
'cli finds controllers',
'cli finds view templates',
'cli defers actions and ignores deferred controllers or templates'
];

test('cli produces empty wiring module', function (t) {
rc.server_routes = './test/lib/fixture/server_routes.js';
var cli = require('../../lib/cli');
t.equal(cli.render(), read('./test/lib/fixture/wiring.expected1.js'));
t.end();
cases.forEach(function register (tc, i) {
test(tc, function testCase (t) {
rc.server_routes = './test/lib/fixture/server_routes.' + i + '.js';
rc.views = './test/lib/fixture/views_' + i;
rc.client_controllers = './test/lib/fixture/controllers_' + i;
var cli = require('../../lib/cli');
var opt;
if (i === 7) {
opt = {
deferred: ['bar/?']
}
}
t.equal(cli.render(opt), read('./test/lib/fixture/wiring_expected.' + i + '.js'));
t.end();
});
});

function read (file) {
@@ -0,0 +1 @@
module.exports = function () {}
@@ -0,0 +1 @@
module.exports = function () {}
@@ -0,0 +1 @@
module.exports = function () {}
@@ -0,0 +1 @@
module.exports = function () {}
File renamed without changes.
@@ -0,0 +1,3 @@
module.exports = [
{action:'foo/bar'}
];
@@ -0,0 +1,3 @@
module.exports = [
{action:'foo/bar', route:'/'}
];
@@ -0,0 +1,3 @@
module.exports = [
{action:'foo/bar', route:'/', ignore: true}
];
@@ -0,0 +1,9 @@
module.exports = [
{action:'foo/bar', route:'/bar', cache: true},
{action:'foo/baz', route:'/baz', cache: false},
{action:'foo/bat', route:'/bat', cache: 15},
{action:'foo/baal', route:'/baal', cache: 0},
{action:'foo/baw', route:'/baw', cache: null},
{action:'foo/bam', route:'/bam', cache: void 0},
{action:'foo/bang', route:'/bang', cache: 'foo'},
];
@@ -0,0 +1,2 @@
module.exports = [
];
@@ -0,0 +1,2 @@
module.exports = [
];
@@ -0,0 +1,9 @@
module.exports = [
{action:'foo/bar', route:'/bar'},
{action:'foo/baz', route:'/baz'},
{action:'foo/bat', route:'/bat'},
{action:'foo/baal', route:'/baal'},
{action:'bar/baw', route:'/baw'},
{action:'bar/bam', route:'/bam'},
{action:'bar/bang', route:'/bang'}
];
@@ -0,0 +1 @@
module.exports = function () {}
File renamed without changes.
@@ -0,0 +1,16 @@
'use strict';

var templates = {
};

var controllers = {
};

var routes = [
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes
};
@@ -0,0 +1,20 @@
'use strict';

var templates = {
};

var controllers = {
};

var routes = [
{
route: '/',
action: 'foo/bar'
}
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes
};
@@ -0,0 +1,21 @@
'use strict';

var templates = {
};

var controllers = {
};

var routes = [
{
route: '/',
action: 'foo/bar',
ignore: true
}
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes
};
@@ -0,0 +1,48 @@
'use strict';

var templates = {
};

var controllers = {
};

var routes = [
{
route: '/bar',
action: 'foo/bar',
cache: true
},
{
route: '/baz',
action: 'foo/baz',
cache: false
},
{
route: '/bat',
action: 'foo/bat',
cache: 15
},
{
route: '/baal',
action: 'foo/baal',
cache: 0
},
{
route: '/baw',
action: 'foo/baw'
},
{
route: '/bam',
action: 'foo/bam'
},
{
route: '/bang',
action: 'foo/bang'
}
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes
};
@@ -0,0 +1,17 @@
'use strict';

var templates = {
};

var controllers = {
'sample/sample': require('../test/lib/fixture/controllers_5/sample/sample.js')
};

var routes = [
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes
};
@@ -0,0 +1,17 @@
'use strict';

var templates = {
'sample/sample': require('../test/lib/fixture/views_6/sample/sample.js')
};

var controllers = {
};

var routes = [
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes
};
@@ -0,0 +1,51 @@
'use strict';

var templates = {
};

var controllers = {
'foo/bar': require('../test/lib/fixture/controllers_7/foo/bar.js'),
'sample/sample': require('../test/lib/fixture/controllers_7/sample/sample.js')
};

var routes = [
{
route: '/bar',
action: 'foo/bar'
},
{
route: '/baz',
action: 'foo/baz'
},
{
route: '/bat',
action: 'foo/bat'
},
{
route: '/baal',
action: 'foo/baal'
},
{
route: '/baw',
action: 'bar/baw'
},
{
route: '/bam',
action: 'bar/bam'
},
{
route: '/bang',
action: 'bar/bang'
}
];

var deferrals = [
'bar/?'
];

module.exports = {
templates: templates,
controllers: controllers,
routes: routes,
deferrals: deferrals
};

0 comments on commit f102974

Please sign in to comment.
You can’t perform that action at this time.