multi_bundle.js 2.3 KB

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