-
Notifications
You must be signed in to change notification settings - Fork 23
/
multibuild_test.js
2307 lines (1971 loc) · 57.3 KB
/
multibuild_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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var asap = require("pdenodeify");
var assert = require("assert");
var comparify = require("comparify");
var fs = require("fs-extra");
var multiBuild = require("../lib/build/multi");
var rmdir = require("rimraf");
var path = require("path");
var testHelpers = require("./helpers");
var fileExists = require("./file_exists");
var escapeRegExp = require("lodash/escapeRegExp");
var find = testHelpers.find;
var open = testHelpers.open;
describe("multi build", function(){
this.timeout(5000);
it("should work", function(done){
asap(rmdir)(path.join(__dirname, "bundle", "dist"))
.then(function() {
return multiBuild({
config: path.join(__dirname, "bundle", "stealconfig.js"),
main: "bundle"
}, {
minify: false,
quiet: true
});
})
.then(function() {
var exists = fs.existsSync(
path.join(__dirname,"bundle/dist/bundles/bundle.js")
);
if(!exists) {
done(new Error("no bundle info"));
return;
}
open(
"test/bundle/bundle.html#a",
function(browser, close) {
find(
browser,
"appA",
function(appA) {
assert(true, "got A");
assert.equal(appA.name, "a", "got the module");
assert.equal(appA.ab.name, "a_b", "a got ab");
assert.equal(appA.clean, undefined, "removed dev code");
assert.equal(appA.dirty, undefined, "removed dev code");
close();
},
close
);
},
done
);
}, done);
});
it("should work with CommonJS", function(done){
rmdir(__dirname + "/commonjs/bundle", function(error){
if(error) {
return done(error);
}
multiBuild({
config: __dirname + "/commonjs/config.js",
main: "main"
}, {
quiet: true
}).then(function(){
open("test/commonjs/prod.html", function(browser, close){
find(browser, "app", function(app){
assert.equal(app.foo, "bar", "Correct object placed on the window");
close();
}, close);
}, done);
}).catch(done);
});
});
it("allows you to transpile modules on your own", function(done){
rmdir(__dirname + "/self_transpile/dist", function(error){
if(error) {
return done(error);
}
multiBuild({
config: __dirname + "/self_transpile/config.js",
main: "index"
}, {
quiet: true,
minify: false,
transpile: function(source){
if(source.indexOf("import") >= 0) {
source = "require('two');";
} else {
source = '"format amd";';
}
return { code: source };
}
}).then(function(){
fs.readFile(__dirname + "/self_transpile/dist/bundles/index.js",
"utf8", function(error, contents){
if(error) return done(error);
var hasRequire = /require\('two'\)/.test(contents);
assert.ok(hasRequire, "converted the way my transpile does");
done();
});
})
.catch(done);
});
});
it("doesn't include the traceur runtime if it's not being used", function(done){
rmdir(__dirname + "/simple-es6/dist", function(error){
if(error) {
return done(error);
}
multiBuild({
config: __dirname + "/simple-es6/config.js",
main: "main",
transpiler: "traceur"
}, {
quiet: true
}).then(function(){
fs.readFile(__dirname + "/simple-es6/dist/bundles/main.js", function(error, contents){
assert.equal(error, null, "Able to open the file");
assert.equal(/\$traceurRuntime/.test(contents), false,
"Traceur not included");
done();
});
}).catch(done);
});
});
it("should minify and envify by default", function() {
var config = {
config: path.join(__dirname, "minify", "config.js"),
main: "minify"
};
return asap(rmdir)(path.join(__dirname, "minify", "dist"))
.then(function() {
process.env.ENVIFY_VAR = "test_value";
return multiBuild(config, { quiet: true });
})
.then(function() {
delete process.env.ENVIFY_VAR;
var main = path.join(__dirname, "minify", "dist", "bundles", "minify.js");
var actualJS = fs.readFileSync(main, "utf8");
var hasLongVariable = actualJS.indexOf("thisObjectHasABigName") !== -1;
var hasGlobalLongVariable = actualJS.indexOf("anotherVeryLongName") !== -1;
var hasDevCode = actualJS.indexOf("remove this") !== -1;
var hasEnvifyCode = actualJS.indexOf("when envify is turned on this should be removed") !== -1;
assert(!hasEnvifyCode, "should not include envify test code.");
assert(!hasDevCode, "Minified source has dev code removed.");
assert(!hasLongVariable, "Minified source renamed long variable.");
assert(!hasGlobalLongVariable, "Minified source includes a global that was minified.");
});
});
it("should allow minification to be turned off", function() {
var config = {
config: path.join(__dirname, "minify", "config.js"),
main: "minify"
};
var options = {
minify: false,
quiet: true
};
return asap(rmdir)(path.join(__dirname, "minify", "dist"))
.then(function() {
return multiBuild(config, options);
})
.then(function() {
var main = path.join(__dirname, "minify", "dist", "bundles", "minify.js");
var actualJS = fs.readFileSync(main, "utf8");
var hasLongVariable = actualJS.indexOf("thisObjectHasABigName") !== -1;
assert(hasLongVariable, "Source includes long variable name.");
});
});
it("should apply envify when minification is off", function() {
var config = {
config: path.join(__dirname, "minify", "config.js"),
main: "minify"
};
var options = {
quiet: true,
minify: false
};
return asap(rmdir)(path.join(__dirname, "minify", "dist"))
.then(function() {
process.env.ENVIFY_VAR = "test_value";
return multiBuild(config, options);
})
.then(function() {
delete process.env.ENVIFY_VAR;
var main = path.join(__dirname, "minify", "dist", "bundles", "minify.js");
var actualJS = fs.readFileSync(main, "utf8");
var hasEnvVariable = actualJS.indexOf("process.env.ENVIFY_VAR") !== -1;
assert(!hasEnvVariable, "Node env variable should have been inlined");
});
});
it("should allow to turn envify off", function() {
var config = {
config: path.join(__dirname, "minify", "config.js"),
main: "minify"
};
var options = {
quiet: true,
minify: false,
envify: false
};
return asap(rmdir)(path.join(__dirname, "minify", "dist"))
.then(function() {
process.env.ENVIFY_VAR = "test_value";
return multiBuild(config, options);
})
.then(function() {
delete process.env.ENVIFY_VAR;
var main = path.join(__dirname, "minify", "dist", "bundles", "minify.js");
var actualJS = fs.readFileSync(main, "utf8");
var hasEnvVariable = actualJS.indexOf("process.env.ENVIFY_VAR") !== -1;
assert(hasEnvVariable, "source should have node environment variable");
});
});
it("should allow setting uglify-js options", function() {
var config = {
config: path.join(__dirname, "minify", "config.js"),
main: "minify"
};
var options = {
quiet: true,
uglifyOptions: {
mangle: false // skip mangling names.
}
};
return asap(rmdir)(path.join(__dirname, "minify", "dist"))
.then(function() {
return multiBuild(config, options);
})
.then(function() {
var main = path.join(__dirname, "minify", "dist", "bundles", "minify.js");
var actualJS = fs.readFileSync(main, "utf8");
var hasLongVariable = actualJS.indexOf("thisObjectHasABigName") !== -1;
var hasAnotherLongVariable = actualJS.indexOf("anotherLongObjectName") !== -1;
assert(hasLongVariable, "Skip mangling names in dependencies graph files");
assert(hasAnotherLongVariable, "skip mangling names in stealconfig and main files");
});
});
it("Allows specifying an alternative dist directory", function(done){
var config = {
config: __dirname + "/other_bundle/stealconfig.js",
main: "bundle"
};
var options = {
dest: __dirname + "/other_bundle/other_dist",
quiet: true
};
rmdir(__dirname + "/other_bundle/other_dist", function(error){
if(error) {
done(error);
return;
}
multiBuild(config, options).then(function(){
open("test/other_bundle/bundle.html#a",function(browser, close){
find(browser,"appA", function(appA){
assert(true, "got A");
assert.equal(appA.name, "a", "got the module");
assert.equal(appA.ab.name, "a_b", "a got ab");
close();
}, close);
}, done);
});
});
});
it("Throws if you use bundlesPath configuration", function(done){
multiBuild({
config: __dirname + "/some/fake/dir/package.json!npm",
bundlesPath: __dirname + "/some/fake/dir/bundles"
}, {
quiet: false
})
.then(function(){
assert.ok(false, "This should not have succeeded");
}, function(err){
var msg = err.message;
assert.ok(/bundlesPath has been removed/.test(msg),
"Rejected because bundlesPath is used");
})
.then(done);
});
it("Allows specifying dist as the current folder", function(done){
this.timeout(5000);
var config = {
config: __dirname + "/other_bundle/stealconfig.js",
main: "bundle"
};
var options = {
dest: __dirname + "/other_bundle",
quiet: true
};
rmdir(__dirname + "/other_bundle/bundles", function(error){
if(error) {
done(error);
return;
}
multiBuild(config, options).then(function(){
open("test/other_bundle/bundle-dist.html#a",function(browser, close){
find(browser,"appA", function(appA){
assert(true, "got A");
assert.equal(appA.name, "a", "got the module");
assert.equal(appA.ab.name, "a_b", "a got ab");
close();
}, close);
}, done);
});
});
});
it("supports bundling steal", function(done) {
var base = path.join(__dirname, "bundle");
asap(rmdir)(path.join(base, "dist"))
.then(function() {
return multiBuild({
main: "bundle",
config: path.join(base, "stealconfig.js")
}, {
quiet: true,
minify: false,
bundleSteal: true,
dest: path.join(base, "dist")
});
})
.then(function(){
open("test/bundle/packaged_steal.html#a",function(browser, close){
find(browser,"appA", function(appA){
var loader = browser.window.System;
assert(true, "got A");
assert.equal(appA.name, "a", "got the module");
assert.equal(appA.ab.name, "a_b", "a got ab");
// environment is set to production
assert.equal(
loader.env,
"window-production",
"bundle steal is always production"
);
close();
}, close);
}, done);
})
.catch(done);
});
it("allows bundling steal and loading from alternate locations", function(done){
rmdir(__dirname+"/bundle/alternate", function(error){
if(error){
done(error);
}
multiBuild({
config: __dirname+"/bundle/stealconfig.js",
main: "bundle"
},{
bundleSteal: true,
dest: __dirname + "/bundle/alternate",
quiet: true,
minify: false
}).then(function(){
open("test/bundle/folder/packaged_steal.html#a",function(browser, close){
find(browser,"appA", function(appA){
var loader = browser.window.System;
assert(true, "got A");
assert.equal(appA.name, "a", "got the module");
assert.equal(appA.ab.name, "a_b", "a got ab");
// environment is set to production
assert.equal(loader.env, 'window-production', "bundle steal is always production");
close();
}, close);
}, done);
}).catch(function(e){
done(e);
});
});
});
it("builds and can load transpiled ES6 modules", function(done){
this.timeout(60000);
var base = path.join(__dirname, "basics");
asap(rmdir)(path.join(base, "dist"))
.then(function() {
return multiBuild({
config: path.join(__dirname, "stealconfig.js"),
main: "basics/basics"
}, {
quiet: true,
minify: false,
dest: path.join(base, "dist")
});
})
.then(function() {
open("test/basics/prod.html",function(browser, close){
find(browser,"MODULE", function(module){
assert.equal(
module.name,
"module",
"module name is right"
);
assert.equal(
module.es6module.name,
"es6Module",
"steal loads ES6"
);
assert.equal(
module.es6module.amdModule.name,
"amdmodule",
"ES6 loads amd"
);
close();
}, close);
}, done);
}, done);
});
it("System.instantiate works when bundling steal", function(done){
rmdir(__dirname+"/dist", function(error){
if(error){
return done(error);
}
multiBuild({
config: __dirname+"/stealconfig.js",
main: "basics/basics"
}, {
bundleSteal: true,
quiet: true,
minify: false
}).then(function(){
open("test/basics/prod-inst.html",function(browser, close){
find(browser,"MODULE", function(){
assert(true, "module");
// We marked stealconfig.js as instantiated so it shouldn't have it's properties
var System = browser.window.System;
assert.equal(System.map["mapd/mapd"], undefined, "Mapping not applied");
close();
}, close);
}, done);
});
});
});
it("Returns an error when building a main that doesn\'t exist", function(done){
var config = {
config: __dirname + "/stealconfig.js",
main: "some/fake/app"
};
var options = {
quiet: true
};
// Temporarily swallow console.logs to prevent 404 showing.
var log = console.log;
console.log = function(){};
multiBuild(config, options).then(function onFulfilled(){
// If we get then the error wasn't caught properly
assert(false, "Build completed successfully when there should have been an error");
}, function onRejected(err){
assert(err instanceof Error, "Caught an error when loading a fake main");
}).then(function() {
// Set back console.log
console.log = log;
}).then(done);
});
it("removes steal.dev references", function(done){
rmdir(__dirname + "/bundle/dist", function(error){
if(error){
done(error);
}
multiBuild({
main: "bundle",
config: __dirname + "/bundle/stealconfig.js"
}, {
quiet: true
}).then(function(){
fs.readFile(__dirname + "/bundle/dist/bundles/app_a.js", function(error, content){
assert(!error, "able to open the file");
assert.equal(
/steal.dev/.test(content),
false,
"it should remove steal.dev references"
);
done();
});
}, done);
});
});
it("works with an unnormalized main", function(done){
rmdir(__dirname+"/dist", function(error){
if(error){
done(error);
}
multiBuild({
config: __dirname+"/stealconfig.js",
main: "basics/"
}, {
quiet: true,
minify: false
}).then(function(){
open("test/basics/prod.html",function(browser, close){
find(browser,"MODULE", function(module){
assert(true, "module");
assert.equal(module.name, "module", "module name is right");
assert.equal(module.es6module.name, "es6Module", "steal loads ES6");
assert.equal(module.es6module.amdModule.name, "amdmodule", "ES6 loads amd");
close();
}, close);
}, done);
}, done);
});
});
it("works with a project with json", function(done){
rmdir(__dirname+"/json/dist", function(error){
if(error) return done(error);
multiBuild({
config: __dirname + "/json/package.json!npm"
}, {
quiet: true,
minify: false
}).then(function(){
open("test/json/prod.html", function(browser, close){
find(browser, "MODULE", function(module){
assert(!!module.data, "json data exists");
assert.equal(module.data.foo, "bar", "correctly parsed");
close();
}, close);
}, done);
});
});
});
it("can define own translate with meta", function(done){
rmdir(__dirname+"/meta_translate/dist", function(error){
if(error) return done(error);
multiBuild({
configMain: "@empty",
main: "main",
baseURL: __dirname + "/meta_translate",
meta: {
a: {
translate: function(load){
load.metadata.format = "amd";
return "define([], function(){\n" +
"return 'b';\n});";
}
}
}
}, {
quiet: true,
minify: false
}).then(function(){
open("test/meta_translate/prod.html", function(browser, close){
find(browser, "MODULE", function(module){
assert.equal(module.a, "b", "translate worked");
close();
}, close);
}, done);
});
});
});
it("can load projects that use require('./package'); convention", function(done){
rmdir(__dirname + "/pkg_json/dist", function(err){
if(err) return done(err);
var p = multiBuild({
config: __dirname + "/pkg_json/package.json!npm"
}, {
quiet: true,
minify: false
});
p.then(function(){
done();
});
});
});
describe("sideBundle", function(){
it("sideBundle: true will move a module into a side bundle", function(done){
rmdir(__dirname+"/side_bundle/dist", function(error){
if(error) return done(error);
multiBuild({
config: __dirname + "/side_bundle/package.json!npm"
}, {
quiet: true,
minify: false
}).then(function(){
open("test/side_bundle/prod.html", function(browser, close){
find(browser, "MODULE", function(){
var loader = browser.window.System;
comparify(loader.bundles, {
"bundles/b": [ "d", "b" ]
}, true);
close();
}, close);
}, done);
});
});
});
it("can be declared in a child package", function(done){
rmdir(__dirname+"/side_bundle/dist", function(error){
if(error) return done(error);
multiBuild({
config: __dirname + "/side_bundle_dep/package.json!npm"
}, {
quiet: true,
minify: false
}).then(function(){
open("test/side_bundle_dep/prod.html", function(browser, close){
find(browser, "MODULE", function(){
var loader = browser.window.System;
comparify(loader.bundles, {
"bundles/dep/b": [ "dep@1.0.0#c","dep@1.0.0#d","dep@1.0.0#b" ]
}, true);
close();
}, close);
}, done);
});
});
});
});
it("returns a buildResult", function(done){
rmdir(__dirname+"/bundle/dist", function(error){
if(error){
done(error);
}
multiBuild({
config: __dirname+"/bundle/stealconfig.js",
main: "bundle"
}, {
quiet: true
}).then(function(data){
assert(!!data.bundles, "bundles");
assert(!!data.configuration, "configuration");
assert(!!data.graph, "graph");
assert(!!data.loader, "loader");
assert(!!data.steal, "steal");
}).then(done);
});
});
it("virtual modules can become bundles", function(done){
rmdir(__dirname+"/virtual/dist", function(error){
if(error) {
return done(error);
}
multiBuild({
config: __dirname + "/virtual/config.js",
main: "main"
}, {
quiet: true
}).then(function(){
assert(true, "it worked");
open("test/virtual/prod.html", function(browser, close){
find(browser, "MODULE", function(module){
assert(typeof module.b, "undefined", "b module not included in the main bundle");
close();
}, close);
}, done);
}).then(null, done);
});
});
it("envs configuration works", function(done){
rmdir(__dirname+"/envs/dist", function(error){
if(error) {
return done(error);
}
multiBuild({
config: __dirname + "/envs/config.js",
main: "main"
}, {
quiet: true
}).then(function(){
open("test/envs/prod.html", function(browser, close){
find(browser, "MODULE", function(module){
assert.equal(module.FOO, "bar", "envs configuration was set");
close();
}, close);
}, done);
}).then(null, done);
});
});
it("Is able to load progressively loaded app with progressively loaded package.json data", function(done){
rmdir(__dirname+"/progressive_package/dist", function(error){
if(error) return done(error);
multiBuild({
config: __dirname + "/progressive_package/package.json!npm"
}, {
minify: false,
quiet: true
}).then(function(){
open("test/progressive_package/prod.html", function(browser, close){
find(browser, "MODULE", function(module){
var a = module.a;
var b = module.b;
assert.equal(a.name, "dep2", "loaded dep2");
assert.equal(a.dep3, "dep3", "loaded dep3");
assert.equal(b.name, "dep4", "loaded dep4");
assert.equal(b.dep5, "dep5", "loaded dep5");
assert.equal(module.foo, "bar", "configDependency code ran");
close();
}, close);
}, done);
})
.catch(done);
});
});
it("Loads an ES6 module that consumes CJS modules using {}", function(done){
rmdir(__dirname + "/es_cjs/dist", function(error){
if(error) return done(error);
multiBuild({
config: __dirname + "/es_cjs/package.json!npm"
}, {
minify: false,
quiet: true
}).then(function(){
open("test/es_cjs/prod.html", function(browser, close){
find(browser, "MODULE", function(mod){
assert.equal(mod.x, "foo", "got module that uses " +
"{} for imports");
assert.equal(mod.y, "bar", "got module using default");
close();
}, close);
}, done);
});
});
});
it("Circular refs works with Babel", function(done){
rmdir(__dirname+"/circular/dist", function(error){
if(error){
done(error);
return;
}
multiBuild({
config: __dirname+"/circular/package.json!npm",
}, {
quiet: true,
minify: false
}).then(function(){
open("test/circular/prod.html",function(browser, close){
find(browser,"circularWorks", function(result){
assert.equal(result, true, "circular refs worked");
close();
}, close);
}, done);
}, done);
});
});
it("circular refs using default imports work with Babel (#802)", function(done) {
var base = path.join(__dirname, "circular_default");
asap(rmdir)(path.join(base, "dist"))
.then(function() {
return multiBuild({
config: path.join(base, "stealconfig.js"),
}, {
quiet: true,
minify: false,
dest: path.join(base, "dist")
});
})
.then(function() {
open("test/circular_default/prod.html", function(browser, close) {
find(browser, "circular", function(circular) {
assert.equal(
circular.foo,
circular.bar,
"circular refs worked"
);
close();
}, close);
}, done);
}, done);
});
describe("with plugins", function(){
this.timeout(60000);
it("work on the client", function(done){
open("test/plugins/site.html", function(browser, close){
find(browser,"PLUGTEXT", function(plugText){
assert.equal(plugText, "client-Holler", "client can do plugins");
close();
}, close);
}, done);
});
it("work built", function(done){
// remove the bundles dir
rmdir(__dirname+"/plugins/dist/bundles", function(error){
if(error){
done(error);
}
// build the project that
// uses a plugin
multiBuild({
config: __dirname+"/plugins/config.js",
main: "main"
}, {
quiet: true,
minify: false
}).then(function(){
// open the prod page and make sure
// the plugin processed the input correctly
open("test/plugins/prod.html", function(browser, close){
find(browser,"PLUGTEXT", function(plugText){
assert.equal(plugText, "server-Holler", "server can do plugins");
close();
}, close);
}, done);
}).catch(function(e){
done(e);
});
});
});
it("work built using steal", function(done){
// remove the bundles dir
rmdir(__dirname+"/plugins/dist", function(error){
if(error){
done(error);
}
// build the project that
// uses a plugin
multiBuild({
config: __dirname+"/plugins/config.js",
main: "main-steal",
paths: {
"plug/plug": "plug.js"
}
}, {
quiet: true
}).then(function(){
// open the prod page and make sure
// the plugin processed the input correctly
open("test/plugins/prod-steal.html", function(browser, close){
find(browser,"PLUGTEXT", function(plugText){
assert.equal(plugText, "server-Holler", "server can do plugins");
close();
}, close);
}, done);
}).catch(function(e){
done(e);
});
});
});
it("plugins that are part of the main are part of the main bundle", function(done){
rmdir(__dirname+"/plugin_main_bundle/dist", function(error){
if(error) {
return done(error);
}
multiBuild({
config: __dirname + "/plugin_main_bundle/config.js",
main: "main"
}, {
minify: false,
quiet: true
}).then(function(buildResult){
var mainBundle = buildResult.bundles[0];
var found = false;
for(var i = 0, len = mainBundle.nodes.length; i < len; i++) {
var node = mainBundle.nodes[i];
if(node.load.name === "plug") {
found = true;
}