mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
feat: renderFileToNodeStream(filepath, scope)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { expect, use } from 'chai'
|
||||
import { resolve } from 'path'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('.renderToNodeStream()', function () {
|
||||
it('should render to stream in Node.js', done => {
|
||||
const cjs = require('../../dist/liquid.node.cjs')
|
||||
const engine = new cjs.Liquid()
|
||||
const tpl = engine.parseFileSync(resolve(__dirname, '../stub/root/foo.html'))
|
||||
const stream = engine.renderToNodeStream(tpl)
|
||||
let html = ''
|
||||
stream.on('data', (data: string) => { html += data })
|
||||
stream.on('end', () => {
|
||||
try {
|
||||
expect(html).to.equal('foo')
|
||||
done()
|
||||
} catch (err) {
|
||||
done(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
it('should throw in browser', async function () {
|
||||
const cjs = require('../../dist/liquid.browser.umd')
|
||||
const engine = new cjs.Liquid()
|
||||
const render = () => engine.renderToNodeStream('foo')
|
||||
return expect(render).to.throw('streaming not supported in browser')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.renderFileToNodeStream()', function () {
|
||||
it('should render to stream in Node.js', async done => {
|
||||
const cjs = require('../../dist/liquid.node.cjs')
|
||||
const engine = new cjs.Liquid({
|
||||
root: resolve(__dirname, '../stub/root/')
|
||||
})
|
||||
const stream = await engine.renderFileToNodeStream('foo.html')
|
||||
let html = ''
|
||||
stream.on('data', (data: string) => { html += data })
|
||||
stream.on('end', () => {
|
||||
try {
|
||||
expect(html).to.equal('foo')
|
||||
done()
|
||||
} catch (err) {
|
||||
done(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
it('should throw in browser', async function () {
|
||||
const cjs = require('../../dist/liquid.browser.umd')
|
||||
const engine = new cjs.Liquid()
|
||||
const render = () => engine.renderFileToNodeStream('foo')
|
||||
return expect(render).to.throw('streaming not supported in browser')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user