1
+ var fs = require ( 'fs' ) ;
2
+ var path = require ( 'path' ) ;
3
+ var assert = require ( 'assert' ) ;
4
+ var Q = require ( 'q' ) ;
5
+ var rimraf = require ( 'rimraf' ) ;
6
+ var getRenderer = require ( './get_renderer' ) ;
7
+ var getPartials = require ( './get_partials' ) ;
8
+ var build = require ( "./build" ) ;
1
9
10
+ var rmdir = Q . denodeify ( rimraf ) ;
11
+ var read = Q . denodeify ( fs . readFile ) ;
2
12
3
- var getRenderer = require ( './get_renderer' ) ,
4
- getPartials = require ( './get_partials' ) ,
5
- build = require ( "./build" ) ,
6
- assert = require ( 'assert' ) ,
7
- Q = require ( 'q' ) ,
8
- path = require ( 'path' ) ,
9
- rmdir = require ( 'rimraf' ) ,
10
- fs = require ( 'fs' ) ;
13
+ require ( "./make_default_helpers_test" ) ;
11
14
12
- describe ( "documentjs/lib/generators/html/build" , function ( ) {
15
+ describe ( "documentjs/lib/generators/html/build" , function ( ) {
13
16
14
- beforeEach ( function ( done ) {
15
- rmdir ( path . join ( __dirname , ".." , "site" , "static" ) , function ( e ) {
16
- rmdir ( path . join ( __dirname , ".." , "site" , "templates" ) , done ) ;
17
+ beforeEach ( function ( ) {
18
+ return rmdir ( path . join ( __dirname , ".." , "site" , "static" ) ) . then ( function ( ) {
19
+ return rmdir ( path . join ( __dirname , ".." , "site" , "templates" ) ) ;
17
20
} ) ;
18
21
} ) ;
19
22
20
- it ( "get_renderer and get_partial work" , function ( done ) {
21
- Q . all ( [
23
+ it ( "get_renderer and get_partial work" , function ( ) {
24
+ return Q . all ( [
22
25
getRenderer ( 'build/test/templates' ) ,
23
26
getPartials ( 'build/test/templates' )
24
27
] ) . then ( function ( results ) {
25
-
26
28
var renderer = results [ 0 ] ;
27
-
28
29
var result = renderer ( { subject : "World" } ) ;
29
30
30
31
assert . equal ( result , "<html><h1>Hello World</h1></html>" ) ;
31
- done ( ) ;
32
- } , done ) . catch ( done ) ;
32
+ } ) ;
33
33
} ) ;
34
34
35
- it ( "build.renderer build.templates build.helpers" , function ( done ) {
36
-
35
+ it ( "build.renderer build.templates build.helpers" , function ( ) {
37
36
var options = {
38
- html : { templates : path . join ( __dirname , "test" , "templates_with_helpers" ) } ,
37
+ html : { templates : path . join ( __dirname , "test" , "templates_with_helpers" ) } ,
39
38
dest : "XXXXYYYZZZ" ,
40
39
forceBuild : true ,
41
40
pageConfig : {
@@ -52,13 +51,11 @@ describe("documentjs/lib/generators/html/build",function(){
52
51
} ;
53
52
54
53
55
- Q . all ( [
54
+ return Q . all ( [
56
55
build . renderer ( buildTemplatesPromise , options ) ,
57
56
build . helpers ( buildTemplatesPromise , { } , options , getCurrent )
58
57
] ) . then ( function ( results ) {
59
-
60
58
var renderer = results [ 0 ] ;
61
-
62
59
var result = renderer ( {
63
60
subject : "World" ,
64
61
src : "./index.js" ,
@@ -67,14 +64,13 @@ describe("documentjs/lib/generators/html/build",function(){
67
64
} ) ;
68
65
69
66
assert . equal ( result , "<html><h1>HELLO World</h1>\n</html>" ) ;
70
- done ( ) ;
71
- } , done ) . catch ( done ) ;
67
+ } ) ;
72
68
73
69
} ) ;
74
70
75
- it ( "Does ignoreTemplateRender" , function ( done ) {
71
+ it ( "Does ignoreTemplateRender" , function ( ) {
76
72
var options = {
77
- html : { templates : path . join ( __dirname , "test" , "render_body_option" ) } ,
73
+ html : { templates : path . join ( __dirname , "test" , "render_body_option" ) } ,
78
74
dest : "XXXXYYYZZZ" ,
79
75
forceBuild : true ,
80
76
pageConfig : {
@@ -90,41 +86,71 @@ describe("documentjs/lib/generators/html/build",function(){
90
86
return data ;
91
87
} ;
92
88
93
- Q . all ( [
89
+ return Q . all ( [
94
90
build . renderer ( buildTemplatesPromise , options ) ,
95
91
build . helpers ( buildTemplatesPromise , { } , options , getCurrent )
96
92
] ) . then ( function ( results ) {
97
-
98
93
var renderer = results [ 0 ] ;
99
-
100
94
var result = renderer ( { body : "{{message}} stuff" } ) ;
101
95
102
96
assert . equal ( result , "<html><h1>{{message}} stuff</h1>\n<p>static</p></html>" ) ;
103
- done ( ) ;
104
- } , done ) . catch ( done ) ;
97
+ } ) ;
105
98
106
99
} ) ;
107
100
108
- it ( "builds the static dist" , function ( done ) {
101
+ it ( "builds the static dist" , function ( ) {
109
102
this . timeout ( 120000 ) ;
110
- build . staticDist ( {
103
+ return build . staticDist ( {
111
104
forceBuild : true ,
112
- html : { dependencies : { "can-component" : "3.0.0-pre.9" } }
113
- } ) . then ( function ( result ) {
114
- fs . readFile ( path . join ( __dirname , ".." , result . distFolder , "bundles" , "bit-docs-site" , "static.js" ) , function ( err , res ) {
115
- if ( err ) {
116
- done ( err ) ;
117
- } else {
118
- assert . ok ( / c a n - c o m p o n e n t / . test ( res ) , "got static.js with component" ) ;
119
- done ( ) ;
105
+ html : {
106
+ dependencies : {
107
+ "can-component" : "3.0.0-pre.9"
120
108
}
121
- } ) ;
122
- } , done ) ;
109
+ }
110
+ } ) . then ( function ( result ) {
111
+ return read ( path . join ( __dirname , ".." , result . distFolder , "bundles" , "bit-docs-site" , "static.js" ) ) ;
112
+ } ) . then ( function ( res ) {
113
+ assert . ok ( / c a n - c o m p o n e n t / . test ( res ) , "got static.js with component" ) ;
114
+ } ) ;
123
115
} ) ;
124
116
125
- it ( "makes linked content" , function ( done ) {
117
+ it ( "copy absolute staticDist folders to static dist" , function ( ) {
118
+ this . timeout ( 120000 ) ;
119
+ return build . staticDist ( {
120
+ forceBuild : true ,
121
+ html : {
122
+ staticDist : [
123
+ path . join ( __dirname , '..' , 'test-static-dist' )
124
+ ]
125
+ } ,
126
+ } ) . then ( function ( result ) {
127
+ return read ( path . join ( __dirname , ".." , result . distFolder , "test.css" ) ) ;
128
+ } ) . then ( function ( res ) {
129
+ assert . ok ( / # T e s t I D / . test ( res ) , "got test.css file" ) ;
130
+ } ) ;
131
+ } ) ;
132
+
133
+ it ( "copy relative staticDist folders to static dist" , function ( ) {
134
+ this . timeout ( 120000 ) ;
135
+ return build . staticDist ( {
136
+ forceBuild : true ,
137
+ html : {
138
+ staticDist : [
139
+ './test-static-dist'
140
+ ]
141
+ } ,
142
+ } ) . then ( function ( result ) {
143
+ return read ( path . join ( __dirname , ".." , result . distFolder , "test.css" ) ) ;
144
+ } ) . then ( function ( res ) {
145
+ assert . ok ( / # T e s t I D / . test ( res ) , "got test.css file" ) ;
146
+ } ) ;
147
+ } ) ;
148
+
149
+ it ( "makes linked content" , function ( ) {
126
150
var options = {
127
- html : { templates : path . join ( __dirname , "test" , "escaped" ) } ,
151
+ html : {
152
+ templates : path . join ( __dirname , "test" , "escaped" )
153
+ } ,
128
154
dest : "XXXXYYYZZZ" ,
129
155
forceBuild : true ,
130
156
pageConfig : {
@@ -149,18 +175,14 @@ describe("documentjs/lib/generators/html/build",function(){
149
175
something : { name : "something" , title : "<something/>" }
150
176
} ;
151
177
152
-
153
- Q . all ( [
178
+ return Q . all ( [
154
179
build . renderer ( buildTemplatesPromise , options ) ,
155
180
build . helpers ( buildTemplatesPromise , docMap , options , getCurrent )
156
181
] ) . then ( function ( results ) {
157
-
158
182
var renderer = results [ 0 ] ;
159
-
160
183
var result = renderer ( docObject ) ;
184
+
161
185
assert . equal ( result , "<html><p>This is <a href=\"something.html\" title=\"something\"><something/></a></p>\n\n</html>" ) ;
162
- done ( ) ;
163
- } , done ) . catch ( done ) ;
186
+ } ) ;
164
187
} ) ;
165
-
166
188
} ) ;
0 commit comments