util.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var browserify = require('../');
  2. var test = require('tap').test;
  3. var util = require('util');
  4. var xtend = require('xtend');
  5. var vm = require('vm');
  6. test('util.inspect', function (t) {
  7. t.plan(1);
  8. var b = browserify();
  9. b.require('util');
  10. b.bundle(function (err ,src) {
  11. var c = {};
  12. vm.runInNewContext(src, c);
  13. t.equal(
  14. c.require('util').inspect([1,2,3]),
  15. util.inspect([1,2,3])
  16. );
  17. });
  18. });
  19. test('util.inherits', function (t) {
  20. t.plan(2);
  21. var b = browserify();
  22. b.require('util');
  23. b.require('events');
  24. b.bundle(function (err, src) {
  25. var c = {};
  26. vm.runInNewContext(src, c);
  27. var EE = c.require('events').EventEmitter;
  28. function Beep () {}
  29. c.require('util').inherits(Beep, EE);
  30. var beep = new Beep;
  31. t.ok(beep instanceof Beep);
  32. t.ok(beep instanceof EE);
  33. });
  34. });
  35. test('util.inherits without Object.create', function (t) {
  36. t.plan(2);
  37. var b = browserify();
  38. b.require('util');
  39. b.require('events');
  40. b.bundle(function (err, src) {
  41. var c = xtend({}, Object);
  42. delete c.create;
  43. vm.runInNewContext(src, c);
  44. var EE = c.require('events').EventEmitter;
  45. function Beep () {}
  46. Beep.prototype = {};
  47. c.require('util').inherits(Beep, EE);
  48. var beep = new Beep;
  49. t.ok(beep instanceof Beep);
  50. t.ok(beep instanceof EE);
  51. });
  52. });