From 2afbcf4e7d000d99fdbc582d7113684ee00e80cc Mon Sep 17 00:00:00 2001 From: yo mama Date: Fri, 20 Mar 2015 17:33:43 -0700 Subject: first --- node_modules/ejs/test/ejs.js | 265 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 node_modules/ejs/test/ejs.js (limited to 'node_modules/ejs/test/ejs.js') diff --git a/node_modules/ejs/test/ejs.js b/node_modules/ejs/test/ejs.js new file mode 100644 index 0000000..1c58c1c --- /dev/null +++ b/node_modules/ejs/test/ejs.js @@ -0,0 +1,265 @@ +/** + * Module dependencies. + */ + +var ejs = require('..') + , fs = require('fs') + , read = fs.readFileSync + , assert = require('should'); + +/** + * Load fixture `name`. + */ + +function fixture(name) { + return read('test/fixtures/' + name, 'utf8').replace(/\r/g, ''); +} + +/** + * User fixtures. + */ + +var users = []; +users.push({ name: 'tobi' }); +users.push({ name: 'loki' }); +users.push({ name: 'jane' }); + +describe('ejs.compile(str, options)', function(){ + it('should compile to a function', function(){ + var fn = ejs.compile('

yay

'); + fn().should.equal('

yay

'); + }) + + it('should throw if there are syntax errors', function(){ + try { + ejs.compile(fixture('fail.ejs')); + } catch (err) { + err.message.should.include('compiling ejs'); + + try { + ejs.compile(fixture('fail.ejs'), { filename: 'fail.ejs' }); + } catch (err) { + err.message.should.include('fail.ejs'); + return; + } + } + + assert(false, 'compiling a file with invalid syntax should throw an exception'); + }) + + it('should allow customizing delimiters', function(){ + var fn = ejs.compile('

{= name }

', { open: '{', close: '}' }); + fn({ name: 'tobi' }).should.equal('

tobi

'); + + var fn = ejs.compile('

::= name ::

', { open: '::', close: '::' }); + fn({ name: 'tobi' }).should.equal('

tobi

'); + + var fn = ejs.compile('

(= name )

', { open: '(', close: ')' }); + fn({ name: 'tobi' }).should.equal('

tobi

'); + }) + + it('should default to using ejs.open and ejs.close', function(){ + ejs.open = '{'; + ejs.close = '}'; + var fn = ejs.compile('

{= name }

'); + fn({ name: 'tobi' }).should.equal('

tobi

'); + + var fn = ejs.compile('

|= name |

', { open: '|', close: '|' }); + fn({ name: 'tobi' }).should.equal('

tobi

'); + delete ejs.open; + delete ejs.close; + }) + + it('should have a working client option', function(){ + var fn = ejs.compile('

<%= foo %>

', { client: true }); + var str = fn.toString(); + eval('var preFn = ' + str); + preFn({ foo: 'bar' }).should.equal('

bar

'); + }) +}) + +describe('ejs.render(str, options)', function(){ + it('should render the template', function(){ + ejs.render('

yay

') + .should.equal('

yay

'); + }) + + it('should accept locals', function(){ + ejs.render('

<%= name %>

', { name: 'tobi' }) + .should.equal('

tobi

'); + }) +}) + +describe('ejs.renderFile(path, options, fn)', function(){ + it('should render a file', function(done){ + ejs.renderFile('test/fixtures/para.ejs', function(err, html){ + if (err) return done(err); + html.should.equal('

hey

'); + done(); + }); + }) + + it('should accept locals', function(done){ + var options = { name: 'tj', open: '{', close: '}' }; + ejs.renderFile('test/fixtures/user.ejs', options, function(err, html){ + if (err) return done(err); + html.should.equal('

tj

'); + done(); + }); + }) + + it('should not catch err threw by callback', function(done){ + var options = { name: 'tj', open: '{', close: '}' }; + var counter = 0; + try { + ejs.renderFile('test/fixtures/user.ejs', options, function(err, html){ + counter++; + if (err) { + err.message.should.not.equal('Exception in callback'); + return done(err); + } + throw new Error('Exception in callback'); + }); + } catch (err) { + counter.should.equal(1); + err.message.should.equal('Exception in callback'); + done(); + } + }) +}) + +describe('<%=', function(){ + it('should escape', function(){ + ejs.render('<%= name %>', { name: '