pkg_event.js 818 B

12345678910111213141516171819202122232425262728293031
  1. var browserify = require('../');
  2. var path = require('path');
  3. var vm = require('vm');
  4. var test = require('tap').test;
  5. var expected = [
  6. readpkg('pkg_event'),
  7. readpkg('pkg_event/node_modules/aaa'),
  8. readpkg('pkg_event/node_modules/aaa/lib')
  9. ];
  10. test('package event', function (t) {
  11. t.plan(2 + expected.length);
  12. var b = browserify(__dirname + '/pkg_event/main.js');
  13. b.on('package', function (pkg) {
  14. t.deepEqual(pkg, expected.shift());
  15. });
  16. b.bundle(function (err, src) {
  17. t.ifError(err);
  18. vm.runInNewContext(src, { console: { log: log } });
  19. function log (msg) { t.equal(msg, 555) }
  20. });
  21. });
  22. function readpkg (dir) {
  23. var pkg = require(path.join(__dirname, dir, 'package.json'));
  24. pkg.__dirname = path.join(__dirname, dir);
  25. return pkg;
  26. }