-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
843 lines (671 loc) · 26.6 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
'use strict';
var assert = require('assert');
var gutil = require('gulp-util');
var revCollector = require('./index');
var path = require('path');
var isEqual = require('lodash.isequal');
var cssManifestBody = '{"style.css":"style-1d87bebe.css"}';
var jsManifestBody = '{"script1.js": "script1-61e0be79.js", "script2.js": "script2-a42f5380.js"}';
var imgManifestBody = '{"image.gif": "image-35c3af8134.gif"}';
var htmlFileBody = '<html><head><link rel="stylesheet" href="/css/style.css" /><script src="/js/script1.js"></script><script src="/scripts/script2.js"></script></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><link rel="stylesheet" href="/css/style-af457da8.css" /><script src="/js/script1-ce78a5c3.js"></script><script src="/js/script2.js"></script></head><body><img src="cdn/image-35c3af8134.gif" /></body></html>';
var unresolvedHtmlFileBody = '<html><head><style>body { background-image: url(image.gif); }</style></head><body></body></html>';
var unquotedHtmlFileBody = '<html><head></head><body><img src=image.gif></body></html>';
var cssSortManifestBody = '{"style.css":"style-1d87bebe.css", "style.css.css":"style-ebeb78d1.css.css"}';
var jsSortManifestBody = '{"script1.js": "script1-61e0be79.js", "script2.js": "script2-a42f5380.js", "script1.js.js": "script1-98eb0e16.js.js", "script2.js.js": "script2-0835f24a.js.js"}';
var imgSortManifestBody = '{"image.gif": "image-35c3af8134.gif", "image.gif.gif": "image-4318fa3c53.gif"}';
var htmlSortFileBody = '<html><head><link rel="stylesheet" href="/css/style.css.css" /><script src="/js/script1.js.js"></script><script src="/scripts/script2.js.js"></script></head><body><img src="cdn/image.gif.gif" /></body></html>';
var cssSfxManifestBody = '{"style.css":"style-1d87bebe-rev.css"}';
var jsSfxManifestBody = '{"script1.js": "script1-61e0be79-rev.js", "script2.js": "script2-a42f5380-rev.js"}';
var htmlSfxRevedFileBody = '<html><head><link rel="stylesheet" href="/css/style-af457da8-rev.css" /><script src="/js/script1-ce78a5c3-rev.js"></script><script src="/js/script2.js"></script></head><body></body></html>';
var doubleCssManifestBody = '{"style.css":"style-1d87bebe.css", "bebe.css":"bebe-c4092d8d.css"}';
var doubleHtmlFileBody = '<html><head><link rel="stylesheet" href="/css/style.css" /><link rel="stylesheet" href="/css/bebe.css" /></head><body></body></html>';
var collectedManifestStandard = {
'style.css': 'style-1d87bebe.css',
'script1.js': 'script1-61e0be79.js',
'script2.js': 'script2-a42f5380.js'
};
it('should replace links in .html file wo params', function (cb) {
var stream = revCollector();
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(cssManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(jsManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/img/rev-manifest.json',
contents: new Buffer(imgManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/style\.css/.test(contents),
'The CSS file name should be replaced'
);
assert(
/\/css\/style-1d87bebe\.css/.test(contents),
'The CSS file name should be correct replaced'
);
assert(
!/script1\.js/.test(contents),
'The JS#1 file name should be replaced'
);
assert(
/\/js\/script1-61e0be79\.js/.test(contents),
'The JS#1 file name should be correct replaced'
);
assert(
!/script2\.js/.test(contents),
'The JS#2 file name should be replaced'
);
assert(
/\/scripts\/script2-a42f5380\.js/.test(contents),
'The JS#2 file name should be correct replaced'
);
assert(
!/image\.gif/.test(contents),
'The image file name should be replaced'
);
assert(
/cdn\/image-35c3af8134\.gif/.test(contents),
'The image file name should be correctly replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should replace asset links which are not wrapped in quotes', function (cb) {
var stream = revCollector();
stream.write(new gutil.File({
path: 'rev/img/rev-manifest.json',
contents: new Buffer(imgManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(unquotedHtmlFileBody)
}));
stream.on('data', function (file) {
var contents = file.contents.toString('utf8');
assert(
!/image\.gif/.test(contents),
'The image file name should be replaced'
);
assert(
/image-35c3af8134\.gif/.test(contents),
'The unquoted image file name should be correctly replaced'
);
});
stream.on('end', cb);
stream.end();
});
it('should generate correct collected manifest file', function (cb) {
var stream = revCollector({
collectedManifest: 'collectedManifest.json'
});
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(cssManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(jsManifestBody)
}));
stream.on('data', function (file) {
var fpath = file.path;
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
var collectedManifest = JSON.parse(contents);
assert(isEqual(collectedManifest, collectedManifestStandard), 'The collected manifest content should be correct');
assert.equal(fpath, 'collectedManifest.json', 'Only collectedManifest.json file should pass through the stream');
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
// https://github.com/shonny-ua/gulp-rev-collector/issues/30
it('should generate correct collected manifest file, even if the map includes different extensions', function (cb) {
var stream = revCollector();
var fileCount = 0;
var revisionMap = {
"assets/less/common.less": "assets/css/common-2c0d21e40c.css"
};
var htmlFileBody = '<html><head><link rel="stylesheet" href="/assets/less/common.less" /></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><link rel="stylesheet" href="/assets/css/common-2c0d21e40c.css" /></head><body><img src="cdn/image.gif" /></body></html>';
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var fpath = file.path;
var contents = file.contents.toString('utf8');
var ext = path.extname(file.path);
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/assets\/less\/common\.less/.test(contents),
'The LESS file name should be replaced'
);
assert(
/assets\/css\/common-2c0d21e40c\.css/.test(contents),
'The LESS 2 CSS file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should generate correct collected manifest file, even if the map includes different exotic extensions', function (cb) {
var stream = revCollector({
extMap: {
'.loss': '.css'
}
});
var fileCount = 0;
var revisionMap = {
"assets/less/common.loss": "assets/css/common-2c0d21e40c.css"
};
var htmlFileBody = '<html><head><link rel="stylesheet" href="/assets/less/common.loss" /></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><link rel="stylesheet" href="/assets/css/common-2c0d21e40c.css" /></head><body><img src="cdn/image.gif" /></body></html>';
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var fpath = file.path;
var contents = file.contents.toString('utf8');
var ext = path.extname(file.path);
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/assets\/less\/common\.loss/.test(contents),
'The LESS file name should be replaced'
);
assert(
/assets\/css\/common-2c0d21e40c\.css/.test(contents),
'The LESS 2 CSS file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
// https://github.com/shonny-ua/gulp-rev-collector/issues/32
it('should generate correct collected manifest file, even if f the name of the JS file contains “-”', function (cb) {
var stream = revCollector({
// collectedManifest: 'collectedManifest.json'
});
var fileCount = 0;
var revisionMap = {
"assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js"
};
var htmlFileBody = '<html><head><script src="/assets/js/com-mon.js"></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><script src="/assets/js/com-mon.js": "assets/js/common-2c0d21e40c.js"></head><body><img src="cdn/image.gif" /></body></html>';
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var fpath = file.path;
var contents = file.contents.toString('utf8');
var ext = path.extname(file.path);
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/assets\/js\/com-mon\.js/.test(contents),
'The JS file name should be replaced'
);
assert(
/assets\/js\/com-mon-2c0d21e40c.js/.test(contents),
'The JS file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
// https://github.com/shonny-ua/gulp-rev-collector/issues/33
it('should generate correct collected manifest file, even if the map includes multiple extensions', function (cb) {
var stream = revCollector({
replaceReved: true
});
var fileCount = 0;
var revisionMap = {
"maps/js/app.js.map": "maps/js/app-aaaaaaaaaa.js.map",
"maps/css/app.min.css": "maps/css/app-aaaaaaaaaa.min.css",
"maps/css/appless.max.less": "maps/css/appless-aaaaaaaaaa.max.css"
};
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer('<sctipt src="maps/js/app-bbbbbbbbbb.js.map"></script><link rel="stylesheet" href="/maps/css/app-bbbbbbbbbb.min.css" /><link rel="stylesheet" href="/maps/css/appless-bbbbbbbbbb.max.css" />')
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/maps\/js\/app-bbbbbbbbbb\.js\.map/.test(contents),
'The js.map file name should be replaced'
);
assert(
/maps\/js\/app-aaaaaaaaaa\.js\.map/.test(contents),
'The js.map file name should be correct replaced'
);
assert(
!/maps\/css\/app-bbbbbbbbbb\.min\.css/.test(contents),
'The min.css file name should be replaced'
);
assert(
/maps\/css\/app-aaaaaaaaaa\.min\.css/.test(contents),
'The min.css file name should be correct replaced'
);
assert(
!/maps\/css\/appless-bbbbbbbbbb\.max\.css/.test(contents),
'The max.css (by less) file name should be replaced'
);
assert(
/maps\/css\/appless-aaaaaaaaaa\.max\.css/.test(contents),
'The max.css file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should match longer rev patterns before shorter ones', function (cb) {
var stream = revCollector();
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(cssSortManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(jsSortManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlSortFileBody)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/style\.css\.css/.test(contents),
'The CSS file name should be replaced'
);
assert(
/\/css\/style-ebeb78d1\.css\.css/.test(contents),
'The CSS file name should be correct replaced'
);
assert(
!/script1\.js\.js/.test(contents),
'The JS#1 file name should be replaced'
);
assert(
/\/js\/script1-98eb0e16\.js\.js/.test(contents),
'The JS#1 file name should be correct replaced'
);
assert(
!/script2\.js\.js/.test(contents),
'The JS#2 file name should be replaced'
);
assert(
/\/scripts\/script2-0835f24a\.js\.js/.test(contents),
'The JS#2 file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should replace reved links in .html file with "replaceReved" param', function (cb) {
var stream = revCollector({
replaceReved: true
});
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(cssManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(jsManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlRevedFileBody)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/style-af457da8\.css/.test(contents),
'The CSS file name should be replaced'
);
assert(
/\/css\/style-1d87bebe\.css/.test(contents),
'The CSS file name should be correct replaced'
);
assert(
!/script1-ce78a5c3\.js/.test(contents),
'The JS#1 file name should be replaced'
);
assert(
/\/js\/script1-61e0be79\.js/.test(contents),
'The JS#1 file name should be correct replaced'
);
assert(
!/script2\.js/.test(contents),
'The JS#2 file name should be replaced'
);
assert(
/\/js\/script2-a42f5380\.js/.test(contents),
'The JS#2 file name should be correct replace'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should replace links in .html file with "dirReplacements"', function (cb) {
var stream = revCollector({
dirReplacements: {
'/css': '/dist/styles',
'/js/': '/dist/',
'cdn/': function(manifest_value) {
return '//cdn' + (Math.floor(Math.random() * 9) + 1) + '.' + 'example.dot' + '/img/' + manifest_value;
}
}
});
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(cssManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(jsManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/img/rev-manifest.json',
contents: new Buffer(imgManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/style\.css/.test(contents),
'The CSS file name should be replaced'
);
assert(
/\/dist\/styles\/style-1d87bebe\.css/.test(contents),
'The CSS file name should be correct replaced'
);
assert(
!/script1\.js/.test(contents),
'The JS#1 file name should be replaced'
);
assert(
/\/dist\/script1-61e0be79\.js/.test(contents),
'The JS#1 file name should be correct replaced'
);
assert(
/\/scripts\/script2\.js/.test(contents),
'The JS#2 file name should be replaced'
);
assert(
!/\/script2-a42f5380\.js/.test(contents),
'The JS#2 file name should be correct replaced'
);
assert(
!/image\.gif/.test(contents),
'The ING file name should be replaced'
);
assert(
/\/\/cdn[0-9]\.example\.dot\/img\/image-35c3af8134\.gif/.test(contents),
'The IMG file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should replace reved links in .html file with "revSuffix" and "replaceReved" param', function (cb) {
var stream = revCollector({
replaceReved: true,
revSuffix: '-[0-9a-f]{8}-rev'
});
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(cssSfxManifestBody)
}));
stream.write(new gutil.File({
path: 'rev/js/rev-manifest.json',
contents: new Buffer(jsSfxManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlSfxRevedFileBody)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/style-af457da8-rev\.css/.test(contents),
'The CSS file name should be replaced'
);
assert(
/\/css\/style-1d87bebe-rev\.css/.test(contents),
'The CSS file name should be correct replaced'
);
assert(
!/script1-ce78a5c3-rev\.js/.test(contents),
'The JS#1 file name should be replaced'
);
assert(
/\/js\/script1-61e0be79-rev\.js/.test(contents),
'The JS#1 file name should be correct replaced'
);
assert(
!/script2\.js/.test(contents),
'The JS#2 file name should be replaced'
);
assert(
/\/js\/script2-a42f5380-rev\.js/.test(contents),
'The JS#2 file name should be correct replace'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
it('should replace all links in .html file once', function (cb) {
var stream = revCollector();
var fileCount = 0;
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(doubleCssManifestBody)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(doubleHtmlFileBody)
}));
stream.on('data', function (file) {
var ext = path.extname(file.path);
var contents = file.contents.toString('utf8');
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/style\.css/.test(contents),
'The CSS#1 file name should be replaced'
);
assert(
/\/css\/style-1d87bebe\.css/.test(contents),
'The CSS#1 file name should be correct replaced'
);
assert(
!/[^7]bebe\.css/.test(contents),
'The CSS#1& file name should be replaced once'
);
assert(
!/\/css\/style-1d87bebe-c4092d8d\.css/.test(contents),
'The CSS#1 file name should be replaced once'
);
assert(
/\/css\/bebe-c4092d8d\.css/.test(contents),
'The CSS#2 file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
// test concat static resource, like convert '/js/??/com/a.js,b.js,c.js' -> '/js/??/com/a-[hash].js,b-[hash].js,c-[hash].js'
it('should replace all concat-links which are wrapped in quotes', function (cb) {
var stream = revCollector({
concatPrefixes: {
'/js/??': '/js',
'/css/??': '/css'
}
});
var manifestData = JSON.stringify({
"js/com/script1.js": "js/com/script1-bcd227a67c.js",
"js/com/script2.js": "js/com/script2-6173da6e13.js",
"js/com/script3.js": "js/com/script3-abcdef1234.js"
});
var htmlHasConcatData = '<html><body>' +
'<!-- 123 --> <script src="${cdnUrl}/js/??/com/script1.js,/com/script2.js,/com/script3.js${qs}" type="application/javascript"></script>' +
'<!-- 23 --> <script src="/js/??/com/script2.js,/com/script3.js"></script>' +
'<!-- /*13*/ "/js/??/com/script1.js,/com/script3.js" -->' +
'<script>/*3120, 0 has not version*/ let a = `${aha}/js/??/com/script3.js,/com/script1.js,/com/script2.js,/com/script0.js`;</script>' +
'<script>/*12*/ $.get("/js/??/com/script1.js,/com/script2.js", callback);</script>' +
'</body></html>';
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(manifestData)
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlHasConcatData)
}));
stream.on('data', function (file) {
var contents = file.contents.toString();
assert(
!/\/js\/com\/script3\.js/.test(contents),
'The concat path should be replaced'
);
assert(
/\/script3-abcdef1234\.js/.test(contents),
'The concat path should be correctly replaced'
);
assert(
!~contents.indexOf('/js/??/com/script1.js,/com/script2.js,/com/script3.js'),
'The concat path should be correctly replaced'
);
assert(
!~contents.indexOf('/js/??/com/script1.js,/com/script2.js,/com/script3.js'),
'The concat path should be correctly replaced'
);
assert(
!~contents.indexOf('/js/??/com/script2.js,/com/script3.js'),
'The concat path should be correctly replaced'
);
assert(
!~contents.indexOf('/js/??/com/script3.js,/com/script1.js,/com/script2.js,/com/script0.js'),
'The concat path should be correctly replaced'
);
assert(
!~contents.indexOf('/js/??/com/script1.js,/com/script2.js'),
'The concat path should be correctly replaced'
);
assert(
~contents.indexOf('/js/??/com/script1-bcd227a67c.js,/com/script2-6173da6e13.js,/com/script3-abcdef1234.js'),
'The concat path should be correctly replaced'
);
assert(
~contents.indexOf('/js/??/com/script1-bcd227a67c.js,/com/script2-6173da6e13.js,/com/script3-abcdef1234.js'),
'The concat path should be correctly replaced'
);
assert(
~contents.indexOf('/js/??/com/script2-6173da6e13.js,/com/script3-abcdef1234.js'),
'The concat path should be correctly replaced'
);
assert(
~contents.indexOf('/js/??/com/script3-abcdef1234.js,/com/script1-bcd227a67c.js,/com/script2-6173da6e13.js,/com/script0.js'),
'The concat path should be correctly replaced'
);
assert(
~contents.indexOf('/js/??/com/script1-bcd227a67c.js,/com/script2-6173da6e13.js'),
'The concat path should be correctly replaced'
);
// console.log(contents);
});
stream.on('end', cb);
stream.end();
});