mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -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,97 @@
|
||||
import * as chai from 'chai'
|
||||
import * as request from 'supertest'
|
||||
import * as express from 'express'
|
||||
import * as mock from 'mock-fs'
|
||||
import Liquid from '../../dist/liquid.common.js'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('express()', function () {
|
||||
var app, engine
|
||||
|
||||
beforeEach(function () {
|
||||
app = express()
|
||||
engine = new Liquid({
|
||||
root: '/root',
|
||||
extname: '.html'
|
||||
})
|
||||
|
||||
app.set('view engine', 'html')
|
||||
app.engine('html', engine.express())
|
||||
|
||||
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 () {
|
||||
mock.restore()
|
||||
})
|
||||
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)
|
||||
})
|
||||
it('should pass error when file not found', function (done) {
|
||||
const view = {
|
||||
root: []
|
||||
}
|
||||
const file = '/not-exist.html'
|
||||
const ctx = {}
|
||||
engine.express().call(view, file, ctx, function (err) {
|
||||
try {
|
||||
expect(err.code).to.equal('ENOENT')
|
||||
expect(err.message).to.match(/Failed to lookup/)
|
||||
done()
|
||||
} 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 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) {
|
||||
const 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