mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
* spelling: according Signed-off-by: Josh Soref <[email protected]> * spelling: asynchronously Signed-off-by: Josh Soref <[email protected]> * spelling: background Signed-off-by: Josh Soref <[email protected]> * spelling: camel Signed-off-by: Josh Soref <[email protected]> * spelling: cannot Signed-off-by: Josh Soref <[email protected]> * spelling: case-sensitive Signed-off-by: Josh Soref <[email protected]> * spelling: comparison Signed-off-by: Josh Soref <[email protected]> * spelling: demos Signed-off-by: Josh Soref <[email protected]> * spelling: forloop Signed-off-by: Josh Soref <[email protected]> * spelling: formatters Signed-off-by: Josh Soref <[email protected]> * spelling: github Signed-off-by: Josh Soref <[email protected]> * spelling: guidelines Signed-off-by: Josh Soref <[email protected]> * spelling: hashes Signed-off-by: Josh Soref <[email protected]> * spelling: https Signed-off-by: Josh Soref <[email protected]> * spelling: javascript Signed-off-by: Josh Soref <[email protected]> * spelling: keep Signed-off-by: Josh Soref <[email protected]> * spelling: natural Signed-off-by: Josh Soref <[email protected]> * spelling: neither Signed-off-by: Josh Soref <[email protected]> * spelling: no longer Signed-off-by: Josh Soref <[email protected]> * spelling: nonexistent Signed-off-by: Josh Soref <[email protected]> * spelling: output Signed-off-by: Josh Soref <[email protected]> * spelling: polymorphism Signed-off-by: Josh Soref <[email protected]> * spelling: precache Signed-off-by: Josh Soref <[email protected]> * spelling: programmatically Signed-off-by: Josh Soref <[email protected]> * spelling: punctuation Signed-off-by: Josh Soref <[email protected]> * spelling: registration Signed-off-by: Josh Soref <[email protected]> * spelling: rendered Signed-off-by: Josh Soref <[email protected]> * spelling: synchronously Signed-off-by: Josh Soref <[email protected]> * spelling: thrown Signed-off-by: Josh Soref <[email protected]> * spelling: trimmed Signed-off-by: Josh Soref <[email protected]> * spelling: unbalanced Signed-off-by: Josh Soref <[email protected]> * chore: use example.com * chore: fix reference for sidebar.registration --------- Signed-off-by: Josh Soref <[email protected]> Co-authored-by: Harttle <[email protected]>
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { Context } from '../context'
|
|
import { HTMLToken, TagToken } from '../tokens'
|
|
import { Render } from './render'
|
|
import { Tag, HTML } from '../template'
|
|
import { SimpleEmitter } from '../emitters'
|
|
import { toPromise } from '../util'
|
|
|
|
describe('render', function () {
|
|
let render: Render
|
|
beforeEach(function () {
|
|
render = new Render()
|
|
})
|
|
|
|
describe('.renderTemplates()', function () {
|
|
it('should render html', async function () {
|
|
const scope = new Context()
|
|
const token = { getContent: () => '<p>' } as HTMLToken
|
|
const html = await toPromise(render.renderTemplates([new HTML(token)], scope, new SimpleEmitter()))
|
|
return expect(html).toBe('<p>')
|
|
})
|
|
})
|
|
|
|
describe('.renderTemplatesToNodeStream()', function () {
|
|
it('should render to html stream', function (done) {
|
|
const scope = new Context()
|
|
const tpls = [
|
|
new HTML({ getContent: () => '<p>' } as HTMLToken),
|
|
new HTML({ getContent: () => '</p>' } as HTMLToken)
|
|
]
|
|
const stream = render.renderTemplatesToNodeStream(tpls, scope)
|
|
let result = ''
|
|
stream.on('data', (data) => {
|
|
result += data
|
|
})
|
|
stream.on('end', () => {
|
|
expect(result).toBe('<p></p>')
|
|
done()
|
|
})
|
|
})
|
|
it('should render to html stream asynchronously', function (done) {
|
|
const scope = new Context()
|
|
class CustomTag extends Tag {
|
|
render () {
|
|
return new Promise(
|
|
resolve => setTimeout(() => resolve('async tag'), 10)
|
|
)
|
|
}
|
|
}
|
|
const tpls = [
|
|
new HTML({ getContent: () => '<p>' } as HTMLToken),
|
|
new CustomTag({ content: 'foo', args: '', name: 'foo' } as TagToken, [], {} as any),
|
|
new HTML({ getContent: () => '</p>' } as HTMLToken)
|
|
]
|
|
const stream = render.renderTemplatesToNodeStream(tpls, scope)
|
|
let result = ''
|
|
stream.on('data', (data) => {
|
|
result += data
|
|
})
|
|
stream.on('end', () => {
|
|
expect(result).toBe('<p>async tag</p>')
|
|
done()
|
|
})
|
|
})
|
|
})
|
|
})
|