fix error in nunjucks template, add tests

This commit is contained in:
lichengyin 2015-12-25 17:37:13 +08:00
parent f0047ae1f0
commit dedc9d60a7

View File

@ -69,6 +69,76 @@ describe('adapter/template/nunjucks.js', function(){
console.log(err.stack)
})
})
it('run, config, root_path', function(done){
var instance = new Template();
var flag = false;
muk(think, 'npm', function(){
return {
configure: function(root_path){
assert.equal(root_path, __dirname);
flag = true;
},
render: function(filepath, conf){
var content = fs.readFileSync(filepath, 'utf8')
assert.equal(content.indexOf("describe('adapter/template/nunjucks.js'") > -1, true);
assert.deepEqual(conf,{ name: 'welefen' })
return content;
}
}
})
muk(think, 'log', function(){})
instance.run(__filename, {
name: 'welefen'
}, {
type: 'swig',
root_path: __dirname,
options: {
test: 'haha'
}
}).then(function(data){
assert.equal(data.indexOf("describe('adapter/template/base.js'") > -1, true);
muk.restore();
assert.equal(flag, true)
done();
}).catch(function(err){
console.log(err.stack)
})
})
it('run, config, root_path, not start in template file', function(done){
var instance = new Template();
var flag = false;
muk(think, 'npm', function(){
return {
configure: function(config){
assert.equal(config.root_path, 'test' + __dirname)
flag = true;
},
render: function(filepath, conf){
var content = fs.readFileSync(filepath, 'utf8')
assert.equal(content.indexOf("describe('adapter/template/nunjucks.js'") > -1, true);
assert.deepEqual(conf,{ name: 'welefen' })
return content;
}
}
})
muk(think, 'log', function(){})
instance.run(__filename, {
name: 'welefen'
}, {
type: 'swig',
root_path: 'test' + __dirname,
options: {
test: 'haha'
}
}).then(function(data){
assert.equal(data.indexOf("describe('adapter/template/base.js'") > -1, true);
muk.restore();
assert.equal(flag, true)
done();
}).catch(function(err){
console.log(err.stack)
})
})
it('run, config, with prerender', function(done){
var instance = new Template();
muk(think, 'npm', function(){