mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -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);
|
||||
|
||||
Reference in New Issue
Block a user