double_bundle_json.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. var through = require('through2');
  5. var xtend = require('xtend');
  6. test('double bundle json', function (t) {
  7. t.plan(6);
  8. var expected0 = [ 'a=500', 'b=500' ];
  9. var expected1 = [ 'a=500', 'b=500' ];
  10. function log0 (msg) { t.equal(msg, expected0.shift()) }
  11. function log1 (msg) { t.equal(msg, expected1.shift()) }
  12. var cache = {};
  13. var b = browserify(__dirname + '/double_bundle_json/index.js', {
  14. cache: cache
  15. });
  16. b.pipeline.get('deps').push(through.obj(function(row, enc, next) {
  17. cache[row.file] = {
  18. source: row.source,
  19. deps: xtend(row.deps)
  20. };
  21. this.push(row);
  22. next();
  23. }));
  24. b.bundle(function (err, src0) {
  25. t.ifError(err);
  26. vm.runInNewContext(src0, { console: { log: log0 } });
  27. delete cache[__dirname + '/double_bundle_json/index.js'];
  28. b.bundle(function (err, src1) {
  29. t.ifError(err);
  30. vm.runInNewContext(src1, { console: { log: log1 } });
  31. });
  32. });
  33. });