1
1
var fs = require ( 'fs' ) ,
2
2
path = require ( 'path' ) ,
3
3
mock = require ( 'mock-fs' ) ,
4
- promisify = require ( 'vow-node' ) . promisify ,
5
- http = require ( 'http' ) ,
6
- serveStatic = require ( 'serve-static' ) ,
7
- finalhandler = require ( 'finalhandler' ) ,
8
4
TestNode = require ( 'enb/lib/test/mocks/test-node' ) ,
9
5
FileList = require ( 'enb/lib/file-list' ) ,
10
6
bhClientModule = require ( '../../techs/bh-client-module' ) ,
@@ -14,20 +10,9 @@ var fs = require('fs'),
14
10
chaiFilename = require . resolve ( 'chai/chai.js' ) ,
15
11
ymFilename = require . resolve ( 'ym/modules.js' ) ,
16
12
writeFile = require ( '../lib/write-file' ) ,
17
- runPhantom = require ( '../lib/run-phantom' ) ,
18
- serve , server , listen ;
13
+ runServer = require ( '../lib/run-server' ) ;
19
14
20
15
describe ( 'bh-client-module' , function ( ) {
21
- beforeEach ( function ( ) {
22
- serve = serveStatic ( process . cwd ( ) , { index : false } ) ;
23
- server = http . createServer ( function ( req , res ) {
24
- var done = finalhandler ( req , res ) ;
25
-
26
- serve ( req , res , done ) ;
27
- } ) ;
28
- listen = promisify ( server . listen . bind ( server ) ) ;
29
- } ) ;
30
-
31
16
afterEach ( function ( ) {
32
17
mock . restore ( ) ;
33
18
} ) ;
@@ -117,31 +102,6 @@ describe('bh-client-module', function () {
117
102
return runTest ( test , options , template , lib ) ;
118
103
} ) ;
119
104
120
- it ( 'sourcemap' , function ( ) {
121
- var options = {
122
- sourcemap : true ,
123
- bhFile : 'bh.js'
124
- } ,
125
- scheme = {
126
- blocks : { } ,
127
- bundle : { } ,
128
- 'bh.js' : 'module.exports = BH;'
129
- } ,
130
- bundle , fileList ;
131
-
132
- mock ( scheme ) ;
133
-
134
- bundle = new TestNode ( 'bundle' ) ;
135
- fileList = new FileList ( ) ;
136
- fileList . loadFromDirSync ( 'blocks' ) ;
137
- bundle . provideTechData ( '?.files' , fileList ) ;
138
-
139
- return bundle . runTechAndGetContent ( bhClientModule , options )
140
- . spread ( function ( bh ) {
141
- bh . toString ( ) . must . include ( 'sourceMappingURL' ) ;
142
- } ) ;
143
- } ) ;
144
-
145
105
describe ( 'caches' , function ( ) {
146
106
var mockBhCore , scheme , bundle , fileList ;
147
107
@@ -158,14 +118,11 @@ describe('bh-client-module', function () {
158
118
'index.html' : fs . readFileSync ( htmlFilename , 'utf-8' ) ,
159
119
'mocha.js' : fs . readFileSync ( mochaFilename , 'utf-8' ) ,
160
120
'chai.js' : fs . readFileSync ( chaiFilename , 'utf-8' ) ,
161
- 'ym.js' : fs . readFileSync ( ymFilename , 'utf-8' )
121
+ 'ym.js' : fs . readFileSync ( ymFilename , 'utf-8' ) ,
122
+ 'some-ym-lib.js' : ''
162
123
} ;
163
124
} ) ;
164
125
165
- afterEach ( function ( ) {
166
- server . close ( ) ;
167
- } ) ;
168
-
169
126
it ( 'must use cached bhFile' , function ( ) {
170
127
scheme [ 'test.js' ] = generateTest ( { block : 'block' } , '<div class="block"></div>' ) ;
171
128
@@ -196,16 +153,10 @@ describe('bh-client-module', function () {
196
153
return bundle . runTechAndGetContent ( bhClientModule , { bhFile : 'mock.bh.js' } ) ;
197
154
} )
198
155
. spread ( function ( bh ) {
199
- fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
200
156
// TODO: удалить, когда пофиксится https://github.com/enb-make/enb/issues/224
157
+ fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
201
158
202
- return listen ( 3000 ) ;
203
- } )
204
- . then ( function ( ) {
205
- return runPhantom ( 'http://localhost:3000/index.html' ) ;
206
- } )
207
- . fail ( function ( err ) {
208
- throw err ;
159
+ return runServer ( 3000 ) ;
209
160
} ) ;
210
161
} ) ;
211
162
@@ -239,16 +190,10 @@ describe('bh-client-module', function () {
239
190
return bundle . runTechAndGetContent ( bhClientModule , { bhFile : 'mock.bh.js' } ) ;
240
191
} )
241
192
. spread ( function ( bh ) {
242
- fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
243
193
// TODO: удалить, когда пофиксится https://github.com/enb-make/enb/issues/224
194
+ fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
244
195
245
- return listen ( 3000 ) ;
246
- } )
247
- . then ( function ( ) {
248
- return runPhantom ( 'http://localhost:3000/index.html' ) ;
249
- } )
250
- . fail ( function ( err ) {
251
- throw err ;
196
+ return runServer ( 3000 ) ;
252
197
} ) ;
253
198
} ) ;
254
199
@@ -279,16 +224,10 @@ describe('bh-client-module', function () {
279
224
return bundle . runTechAndGetContent ( bhClientModule ) ;
280
225
} )
281
226
. spread ( function ( bh ) {
282
- fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
283
227
// TODO: удалить, когда пофиксится https://github.com/enb-make/enb/issues/224
228
+ fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
284
229
285
- return listen ( 3000 ) ;
286
- } )
287
- . then ( function ( ) {
288
- return runPhantom ( 'http://localhost:3000/index.html' ) ;
289
- } )
290
- . fail ( function ( err ) {
291
- throw err ;
230
+ return runServer ( 3000 ) ;
292
231
} ) ;
293
232
} ) ;
294
233
} ) ;
@@ -320,9 +259,7 @@ function runTest(testContent, options, template, lib) {
320
259
options . bhFile = 'bh.js' ;
321
260
}
322
261
323
- if ( lib ) {
324
- scheme [ 'some-ym-lib.js' ] = lib ;
325
- }
262
+ scheme [ 'some-ym-lib.js' ] = lib || '' ;
326
263
327
264
scheme [ bhCoreFilename ] = fs . readFileSync ( bhCoreFilename , 'utf-8' ) ;
328
265
@@ -335,19 +272,10 @@ function runTest(testContent, options, template, lib) {
335
272
336
273
return bundle . runTechAndGetContent ( bhClientModule , options )
337
274
. spread ( function ( bh ) {
338
- fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
339
275
// TODO: удалить, когда пофиксится https://github.com/enb-make/enb/issues/224
276
+ fs . writeFileSync ( 'bundle/bundle.bh.js' , bh ) ;
340
277
341
- return listen ( 3000 ) ;
342
- } )
343
- . then ( function ( ) {
344
- return runPhantom ( 'http://localhost:3000/index.html' ) ;
345
- } )
346
- . then ( function ( ) {
347
- server . close ( ) ;
348
- } )
349
- . fail ( function ( err ) {
350
- throw err ;
278
+ return runServer ( 3000 ) ;
351
279
} ) ;
352
280
}
353
281
@@ -364,4 +292,3 @@ function generateTest(json, result) {
364
292
'});'
365
293
] . join ( '\n' ) ;
366
294
}
367
-
0 commit comments