mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 00:55:13 -07:00
feature: template file lookup error message
This commit is contained in:
@@ -63,6 +63,9 @@ var _engine = {
|
|||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
e.file = filepath;
|
e.file = filepath;
|
||||||
|
if (e.code === 'ENOENT') {
|
||||||
|
e.message = `Failed to lookup ${filepath} in: ${this.options.root}`;
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
+6
-1
@@ -48,9 +48,14 @@ describe('engine#express()', function() {
|
|||||||
var file = '/not-exist.html';
|
var file = '/not-exist.html';
|
||||||
var ctx = {};
|
var ctx = {};
|
||||||
engine.express().call(view, file, ctx, function(err) {
|
engine.express().call(view, file, ctx, function(err) {
|
||||||
|
try{
|
||||||
expect(err.code).to.equal('ENOENT');
|
expect(err.code).to.equal('ENOENT');
|
||||||
console.log(err.message);
|
expect(err.message).to.match(/Failed to lookup/);
|
||||||
done();
|
done();
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should respect root option when lookup', function(done) {
|
it('should respect root option when lookup', function(done) {
|
||||||
|
|||||||
+11
-9
@@ -21,7 +21,10 @@ describe('liquid', function() {
|
|||||||
});
|
});
|
||||||
mock({
|
mock({
|
||||||
'/root/files/foo.html': 'foo',
|
'/root/files/foo.html': 'foo',
|
||||||
'/root/files/name.html': 'My name is {{name}}.'
|
'/root/files/name.html': 'My name is {{name}}.',
|
||||||
|
'/un-readable.html': mock.file({
|
||||||
|
mode: '0000'
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -99,18 +102,17 @@ describe('liquid', function() {
|
|||||||
it('should use default extname', function() {
|
it('should use default extname', function() {
|
||||||
return engine.renderFile('files/name', ctx).should.eventually.equal('My name is harttle.');
|
return engine.renderFile('files/name', ctx).should.eventually.equal('My name is harttle.');
|
||||||
});
|
});
|
||||||
it('should accept root with no trailing slash', function() {
|
it('should throw with lookup list when file not exist', function() {
|
||||||
engine = Liquid({
|
engine = Liquid({
|
||||||
root: '/root',
|
root: ['/boo', '/root/'],
|
||||||
extname: '.html'
|
extname: '.html'
|
||||||
});
|
});
|
||||||
return expect(engine.renderFile('files/foo.html')).to.eventually.equal('foo');
|
return expect(engine.renderFile('/not/exist.html')).to
|
||||||
|
.be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i);
|
||||||
});
|
});
|
||||||
it('should accept dot path', function() {
|
it('should throw when file not readable', function() {
|
||||||
return expect(engine.renderFile('./files/foo.html')).to.eventually.equal('foo');
|
return expect(engine.renderFile('/un-readable.html')).to
|
||||||
});
|
.be.rejectedWith(/EACCES/);
|
||||||
it('should accept double-dot path', function() {
|
|
||||||
return expect(engine.renderFile('files/foo/../foo.html')).to.eventually.equal('foo');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('strict', function() {
|
describe('strict', function() {
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
const chai = require("chai");
|
||||||
|
const expect = chai.expect;
|
||||||
|
|
||||||
|
const fs = require('../../src/util/fs.js');
|
||||||
|
const pathResolve = fs.pathResolve;
|
||||||
|
|
||||||
|
describe('fs', function() {
|
||||||
|
describe('.pathResolve(root, path)', function() {
|
||||||
|
it('should accept root with no trailing slash', function() {
|
||||||
|
expect(pathResolve('/root', 'files/foo.html')).to.equal('/root/files/foo.html');
|
||||||
|
});
|
||||||
|
it('should accept root with trailing slash', function() {
|
||||||
|
expect(pathResolve('/root/', 'files/foo.html')).to.equal('/root/files/foo.html');
|
||||||
|
});
|
||||||
|
it('should accept dot path', function() {
|
||||||
|
expect(pathResolve('/root', './foo.html')).to.equal('/root/foo.html');
|
||||||
|
});
|
||||||
|
it('should accept double-dot path', function() {
|
||||||
|
expect(pathResolve('/root', 'files/../foo.html')).to.equal('/root/foo.html');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user