@@ -3,8 +3,10 @@ import { Context } from '../../../src/context/context'
3
3
import { HTMLToken } from '../../../src/tokens/html-token'
4
4
import { Render } from '../../../src/render/render'
5
5
import { HTML } from '../../../src/template/html'
6
- import { Emitter } from '../../../src/render/ emitter'
6
+ import { SimpleEmitter } from '../../../src/emitters/simple- emitter'
7
7
import { toThenable } from '../../../src/util/async'
8
+ import { Tag } from '../../../src/template/tag/tag'
9
+ import { TagToken } from '../../../src/types'
8
10
9
11
describe ( 'render' , function ( ) {
10
12
let render : Render
@@ -16,8 +18,52 @@ describe('render', function () {
16
18
it ( 'should render html' , async function ( ) {
17
19
const scope = new Context ( )
18
20
const token = { getContent : ( ) => '<p>' } as HTMLToken
19
- const html = await toThenable ( render . renderTemplates ( [ new HTML ( token ) ] , scope , new Emitter ( scope . opts . keepOutputType ) ) )
21
+ const html = await toThenable ( render . renderTemplates ( [ new HTML ( token ) ] , scope , new SimpleEmitter ( ) ) )
20
22
return expect ( html ) . to . equal ( '<p>' )
21
23
} )
22
24
} )
25
+
26
+ describe ( '.renderTemplatesToNodeStream()' , function ( ) {
27
+ it ( 'should render to html stream' , function ( done ) {
28
+ const scope = new Context ( )
29
+ const tpls = [
30
+ new HTML ( { getContent : ( ) => '<p>' } as HTMLToken ) ,
31
+ new HTML ( { getContent : ( ) => '</p>' } as HTMLToken )
32
+ ]
33
+ const stream = render . renderTemplatesToNodeStream ( tpls , scope )
34
+ let result = ''
35
+ stream . on ( 'data' , ( data ) => {
36
+ result += data
37
+ } )
38
+ stream . on ( 'end' , ( ) => {
39
+ expect ( result ) . to . equal ( '<p></p>' )
40
+ done ( )
41
+ } )
42
+ } )
43
+ it ( 'should render to html stream asyncly' , function ( done ) {
44
+ const scope = new Context ( )
45
+ const tpls = [
46
+ new HTML ( { getContent : ( ) => '<p>' } as HTMLToken ) ,
47
+ new Tag ( { content : 'foo' , args : '' , name : 'foo' } as TagToken , [ ] , {
48
+ tags : {
49
+ get : ( ) => ( {
50
+ render : ( ) => new Promise (
51
+ resolve => setTimeout ( ( ) => resolve ( 'async tag' ) , 10 )
52
+ )
53
+ } )
54
+ }
55
+ } as any ) ,
56
+ new HTML ( { getContent : ( ) => '</p>' } as HTMLToken )
57
+ ]
58
+ const stream = render . renderTemplatesToNodeStream ( tpls , scope )
59
+ let result = ''
60
+ stream . on ( 'data' , ( data ) => {
61
+ result += data
62
+ } )
63
+ stream . on ( 'end' , ( ) => {
64
+ expect ( result ) . to . equal ( '<p>async tag</p>' )
65
+ done ( )
66
+ } )
67
+ } )
68
+ } )
23
69
} )
0 commit comments