diff --git a/test/adapter/template/nunjucks.js b/test/adapter/template/nunjucks.js index 0e17ced2..1be12721 100644 --- a/test/adapter/template/nunjucks.js +++ b/test/adapter/template/nunjucks.js @@ -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(){