mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: crash when express views set to string
This commit is contained in:
+44
-24
@@ -8,38 +8,29 @@ const Liquid = require('..');
|
||||
describe('engine#express()', function() {
|
||||
var app, engine;
|
||||
|
||||
before(function() {
|
||||
mock({
|
||||
'/root/foo.html': 'foo',
|
||||
'/views/name.html': 'My name is {{name}}.',
|
||||
'/views/include.html': '{% include file %}',
|
||||
'/partials/bar.html': 'bar'
|
||||
});
|
||||
beforeEach(function() {
|
||||
app = express();
|
||||
engine = Liquid({
|
||||
root: '/root',
|
||||
extname: '.html'
|
||||
});
|
||||
|
||||
app.set('views', ['/views', '/partials']);
|
||||
app.set('view engine', 'html');
|
||||
app.engine('html', engine.express());
|
||||
|
||||
app.get('/name', function(req, res) {
|
||||
res.render('name', {
|
||||
name: 'harttle'
|
||||
});
|
||||
});
|
||||
app.get('/include/:file', function(req, res) {
|
||||
res.render('include', {
|
||||
file: req.params.file
|
||||
});
|
||||
});
|
||||
app.get('/name', (req, res) => res.render('name', {
|
||||
name: 'harttle'
|
||||
}));
|
||||
app.get('/include/:file', (req, res) => res.render('include', {
|
||||
file: req.params.file
|
||||
}));
|
||||
});
|
||||
after(function(){
|
||||
after(function() {
|
||||
mock.restore();
|
||||
});
|
||||
it('should render templates', function(done) {
|
||||
it('should render express views', function(done) {
|
||||
mock({ '/views/name.html': 'My name is {{name}}.' });
|
||||
app.set('views', ['/views']);
|
||||
request(app).get('/name')
|
||||
.expect('My name is harttle.')
|
||||
.expect(200, done);
|
||||
@@ -51,22 +42,51 @@ describe('engine#express()', function() {
|
||||
var file = '/not-exist.html';
|
||||
var ctx = {};
|
||||
engine.express().call(view, file, ctx, function(err) {
|
||||
try{
|
||||
try {
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
expect(err.message).to.match(/Failed to lookup/);
|
||||
done();
|
||||
}
|
||||
catch(e){
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should respect root option when lookup', function(done) {
|
||||
mock({
|
||||
'/root/foo.html': 'foo',
|
||||
'/views/include.html': '{% include file %}'
|
||||
});
|
||||
app.set('views', ['/views']);
|
||||
request(app).get('/include/foo')
|
||||
.expect('foo')
|
||||
.expect(200, done);
|
||||
});
|
||||
it('should respect express settings.views when lookup', function(done) {
|
||||
it('should respect express views (Array) when lookup', function(done) {
|
||||
mock({
|
||||
'/views/include.html': '{% include file %}',
|
||||
'/partials/bar.html': 'bar'
|
||||
});
|
||||
app.set('views', ['/views', '/partials']);
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done);
|
||||
});
|
||||
it('should respect express views (String) when lookup', function(done) {
|
||||
mock({
|
||||
'/views/include.html': '{% include file %}',
|
||||
'/views/bar.html': 'bar'
|
||||
});
|
||||
app.set('views', '/views');
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done);
|
||||
});
|
||||
it('should respect express views (Undefined) when lookup', function(done) {
|
||||
var files = {};
|
||||
files[process.cwd() + '/views/include.html'] = '{% include file %}';
|
||||
files[process.cwd() + '/views/bar.html'] = 'bar';
|
||||
mock(files);
|
||||
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done);
|
||||
|
||||
+14
-17
@@ -139,10 +139,13 @@ describe('liquid', function() {
|
||||
});
|
||||
describe('cache', function() {
|
||||
it('should be disabled by default', function() {
|
||||
mock({
|
||||
'/root/files/foo.html': 'bar'
|
||||
});
|
||||
return engine.renderFile('files/foo', ctx).should.eventually.equal('bar');
|
||||
return engine.renderFile('files/foo')
|
||||
.then(x => expect(x).to.equal('foo'))
|
||||
.then(x => mock({
|
||||
'/root/files/foo.html': 'bar'
|
||||
}))
|
||||
.then(x => engine.renderFile('files/foo'))
|
||||
.then(x => expect(x).to.equal('bar'));
|
||||
});
|
||||
it('should respect cache=true option', function() {
|
||||
engine = Liquid({
|
||||
@@ -150,19 +153,13 @@ describe('liquid', function() {
|
||||
extname: '.html',
|
||||
cache: true
|
||||
});
|
||||
return engine.renderFile('files/foo', ctx)
|
||||
.then((result) => {
|
||||
return expect(result).to.equal('foo');
|
||||
})
|
||||
.then((result) => {
|
||||
mock({
|
||||
'/root/files/foo.html': 'bar'
|
||||
});
|
||||
return engine.renderFile('files/foo', ctx);
|
||||
})
|
||||
.then((result) => {
|
||||
return expect(result).to.equal('foo');
|
||||
});
|
||||
return engine.renderFile('files/foo')
|
||||
.then(x => expect(x).to.equal('foo'))
|
||||
.then(x => mock({
|
||||
'/root/files/foo.html': 'bar'
|
||||
}))
|
||||
.then(x => engine.renderFile('files/foo'))
|
||||
.then(x => expect(x).to.equal('foo'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ describe('util/underscore', function() {
|
||||
});
|
||||
});
|
||||
describe('.echo()', function(){
|
||||
it('should be transparent when called', function() {
|
||||
it('should be transparent', function() {
|
||||
expect(_.echo('foo')('bar')).to.equal('bar');
|
||||
});
|
||||
it('should log the arguments', function() {
|
||||
|
||||
Reference in New Issue
Block a user