UNPKG

2.4 kBJavaScriptView Raw
1var browserify = require('../');
2var vm = require('vm');
3var test = require('tap').test;
4
5test('multi bundle', function (t) {
6 t.plan(5);
7
8 var core = browserify();
9 core.require(__dirname + '/multi_bundle/b.js', { expose: true });
10
11 var app = browserify([__dirname + '/multi_bundle/a.js']);
12 // inform this bundle that b exists in another bundle
13 app.external(__dirname + '/multi_bundle/b.js');
14
15 core.bundle(function (err, src) {
16 var c = {
17 console: console,
18 t : t,
19 baton: {
20 times: 0
21 }
22 };
23
24 // loading core will cause no require to run
25 vm.runInNewContext(src, c);
26 t.equal(c.baton.times, 0);
27
28 // loading the app will require
29 app.bundle(function (err, src) {
30 vm.runInNewContext(src, c);
31
32 // b required for the first time
33 t.equal(c.baton.times, 1);
34
35 // running the file again
36 // because it is using the same b, no reloading
37 vm.runInNewContext(src, c);
38
39 // b should not have been required again
40 // because it was part of the core bundle
41 t.equal(c.baton.times, 1);
42 });
43 });
44});
45
46// re-enable this in future releases
47test('multi bundle', function (t) {
48 t.plan(8);
49
50 var core = browserify({ exposeAll: true });
51 core.require(__dirname + '/multi_bundle/a.js', { expose: true });
52
53 var app = browserify([__dirname + '/multi_bundle/c.js']);
54 // inform this bundle that b exists in another bundle
55 app.external(core);
56
57 core.bundle(function (err, src) {
58 var c = {
59 console: console,
60 t : t,
61 baton: {
62 times: 0
63 }
64 };
65
66 // loading core will cause no require to run
67 vm.runInNewContext(src, c);
68 t.equal(c.baton.times, 0);
69
70 // loading the app will require
71 app.bundle(function (err, src) {
72 vm.runInNewContext(src, c);
73
74 // b required for the first time
75 t.equal(c.baton.times, 1);
76
77 // running the file again
78 // because it is using the same b, no reloading
79 vm.runInNewContext(src, c);
80
81 // b should not have been required again
82 // because it was part of the core bundle
83 t.equal(c.baton.times, 1);
84 });
85 });
86});