mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
chore(TypeScript): refactor objects into classes
fix: `Nil`(null, undefined) now renders as empty string change: `parser.parseValue()` renamed to `parser.parseOutput` change: registered tags/filters become static and shared across different liquid instances
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
var chai = require('chai')
|
||||
var mock = require('mock-fs')
|
||||
var Liquid = require('../..')
|
||||
var expect = chai.expect
|
||||
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('#renderFile()', function () {
|
||||
var engine
|
||||
beforeEach(function () {
|
||||
engine = new Liquid({
|
||||
root: '/root/',
|
||||
extname: '.html'
|
||||
})
|
||||
mock({
|
||||
'/root/files/bar': 'bar',
|
||||
'/root/files/foo.html': 'foo',
|
||||
'/root/files/name.html': 'My name is {{name}}.',
|
||||
'/un-readable.html': mock.file({
|
||||
mode: '0000'
|
||||
})
|
||||
})
|
||||
})
|
||||
afterEach(function () {
|
||||
mock.restore()
|
||||
})
|
||||
it('should render file', function () {
|
||||
return expect(engine.renderFile('/root/files/foo.html', {}))
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should find files without extname', function () {
|
||||
var engine = new Liquid({ root: '/root' })
|
||||
return expect(engine.renderFile('/root/files/bar', {}))
|
||||
.to.eventually.equal('bar')
|
||||
})
|
||||
it('should accept relative path', function () {
|
||||
return expect(engine.renderFile('files/foo.html'))
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should resolve array as root', function () {
|
||||
engine = new Liquid({
|
||||
root: ['/boo', '/root/'],
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(engine.renderFile('files/foo.html'))
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should default root to cwd', function () {
|
||||
var files = {}
|
||||
files[process.cwd() + '/foo.html'] = 'FOO'
|
||||
mock(files)
|
||||
|
||||
engine = new Liquid({
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(engine.renderFile('foo.html'))
|
||||
.to.eventually.equal('FOO')
|
||||
})
|
||||
it('should render file with context', function () {
|
||||
return expect(engine.renderFile('/root/files/name.html', { name: 'harttle' }))
|
||||
.to.eventually.equal('My name is harttle.')
|
||||
})
|
||||
it('should use default extname', function () {
|
||||
return expect(engine.renderFile('files/name', { name: 'harttle' })).to.eventually.equal('My name is harttle.')
|
||||
})
|
||||
it('should throw with lookup list when file not exist', function () {
|
||||
engine = new Liquid({
|
||||
root: ['/boo', '/root/'],
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(engine.renderFile('/not/exist.html')).to
|
||||
.be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i)
|
||||
})
|
||||
it('should throw when file not readable', function () {
|
||||
return expect(engine.renderFile('/un-readable.html')).to
|
||||
.be.rejectedWith(/EACCES/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user