Skip to content

Commit

Permalink
Add basic templateManager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsims committed Mar 10, 2014
1 parent 1d149d3 commit 9a41ad0
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 1 deletion.
9 changes: 8 additions & 1 deletion package.json
Expand Up @@ -41,6 +41,9 @@
"node": ">= 0.6.0"
},
"main": "lib/main.js",
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec --ui bdd"
},
"dependencies": {
"ejs": "0.8.3",
"juice": "~0.3.2",
Expand All @@ -58,6 +61,10 @@
},
"devDependencies": {
"nodemailer": "0.3.27",
"postmark": "0.1.6"
"postmark": "0.1.6",
"mocha": "~1.17.1",
"chai": "^1.9.0",
"mkdirp": "^0.3.5",
"rimraf": "^2.2.6"
}
}
135 changes: 135 additions & 0 deletions test/testTemplateManager.js
@@ -0,0 +1,135 @@
var tm = require('../lib/templateManager')
, expect = require('chai').expect;

describe('Template manager', function() {

it('should render ejs', function(done) {
var opts = {
locals: {item: 'test'},
filename: 'test.ejs',
source: '<h1><%= item%> <%= engine%></h1>'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('<h1>test .ejs</h1>');

done()
})
})

it('should render jade', function(done) {
var opts = {
locals: {item: 'test'},
filename: 'test.jade',
source: 'h1= item\nh1= engine'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('<h1>test</h1><h1>.jade</h1>');

done()
})
})

it('should render swig', function(done) {
var opts = {
locals: {item: 'test'},
filename: 'test.swig',
source: '<h1>{{ item }} {{ engine }}</h1>'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('<h1>test .swig</h1>');

done()
})
})

it('should render handlebars', function(done) {
var opts = {
locals: {item: 'test'},
filename: 'test.handlebars',
source: '<h1>{{ item }} {{ engine }}</h1>'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('<h1>test .handlebars</h1>');

done()
})
})

it('should render less', function(done) {
var opts = {
locals : {},
filename : 'test.less',
source : '.class{ width: (1 + 1) }'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('.class {\n width: 2;\n}\n');

done()
})
})

it('should render stylus', function(done) {
var opts = {locals: {}};
opts.filename = 'test.stylus';
opts.source = 'body\n width: 2px\n';
tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('body {\n width: 2px;\n}\n');
done();
})
})

it('should render styl', function(done) {
var opts = {
locals : {whitespace: true},
filename : 'test.styl',
source : 'body\n color: blue'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('body {\n color: blue;\n}')
done()
})
})

it('should render sass', function(done) {
var opts = {
locals : {},
filename : 'test.sass',
source : '$gray: #ccc;body {color: $gray}'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('body {\n color: #ccc; }\n');

done()
})
})

it('should render css', function(done) {
var opts = {
locals : {},
filename : 'test.css',
source : 'body { color: #ccc; }'
}

tm.render(opts, function(err, res) {
expect(err).to.be.null;
expect(res).to.equal('body { color: #ccc; }');

done()
})
})
})

0 comments on commit 9a41ad0

Please sign in to comment.