UNPKG

tooljs-template

Version:
77 lines (65 loc) 2.06 kB
var template = require('..'); var assert = require('assert'); var tool = require('tooljs'); var fs = require('fs'); describe('tooljs-template', function(){ afterEach(function(){ fs.unlinkSync('test/tmp/example.js'); }); it('should render template', function(done){ var Generator = tool('generator') .use(template('example.js')); var generator = new Generator({ template: { source: __dirname + '/templates', target: __dirname + '/tmp' } }); generator.exec(function(){ assert(fs.existsSync('test/tmp/example.js')); done(); }); }); it('should render templates by inheriting parent options', function(done){ var Generator = tool('generator') .input('source', { type: 'string' }) .input('target', { type: 'string' }) .output('source', { type: 'string' }) .output('target', { type: 'string' }) .use(template('example.js')); var generator = new Generator({ source: __dirname + '/templates', target: __dirname + '/tmp' }); generator.exec(function(){ assert(fs.existsSync('test/tmp/example.js')); done(); }); }); it('should render templates with parent locals', function(done){ var Generator = tool('generator') .input('source', { type: 'string' }) .input('locals', { type: 'object' }) .input('target', { type: 'string' }) .output('source', { type: 'string' }) .output('target', { type: 'string' }) .output('locals', { type: 'object' }) .use(locals()) .use(template('example.js')); var generator = new Generator({ source: __dirname + '/templates', target: __dirname + '/tmp' }); generator.exec(function(){ assert(fs.existsSync('test/tmp/example.js')); assert.equal("module.exports = 'hello world';", fs.readFileSync('test/tmp/example.js', 'utf-8')); done(); }); function locals() { return function(next){ this.locals = { name: 'hello world' }; next(); }; } }); });