file_event.js 835 B

123456789101112131415161718192021222324252627282930313233
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. var path = require('path');
  5. test('file event', function (t) {
  6. t.plan(8);
  7. var b = browserify(__dirname + '/entry/main.js');
  8. var files = {
  9. 'main.js': path.join(__dirname, 'entry/main.js'),
  10. 'one.js': './one',
  11. 'two.js': './two'
  12. };
  13. b.on('file', function (file, id) {
  14. var key = path.basename(file);
  15. t.equal(file, path.join(__dirname, 'entry', key));
  16. t.equal(id, files[key]);
  17. delete files[key];
  18. });
  19. b.bundle(function (err, src) {
  20. var c = {
  21. done : function (one, two) {
  22. t.equal(one, 1);
  23. t.equal(two, 2);
  24. t.end();
  25. }
  26. };
  27. vm.runInNewContext(src, c);
  28. });
  29. });