no_builtins.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var browserify = require('../');
  2. var test = require('tap').test;
  3. var path = require('path');
  4. var vm = require('vm');
  5. test('builtins false', function (t) {
  6. t.plan(1);
  7. var file = __dirname + '/no_builtins/main.js';
  8. var b = browserify({
  9. entries: [ file ],
  10. commondir: false,
  11. builtins: false
  12. });
  13. b.bundle(function (err, src) {
  14. var c = {
  15. console: { log: function (msg) {
  16. t.equal(msg, 'beep boop\n');
  17. } },
  18. require: require,
  19. __dirname: process.cwd()
  20. };
  21. vm.runInNewContext(src, c);
  22. });
  23. });
  24. test('builtins []', function (t) {
  25. t.plan(1);
  26. var b = browserify({
  27. entries: [ __dirname + '/no_builtins/main.js' ],
  28. commondir: false,
  29. builtins: []
  30. });
  31. b.bundle(function (err, src) {
  32. var c = {
  33. console: { log: function (msg) {
  34. t.equal(msg, 'beep boop\n');
  35. } },
  36. require: require
  37. };
  38. vm.runInNewContext(src, c);
  39. });
  40. });
  41. test('builtins object', function (t) {
  42. t.plan(2);
  43. var b = browserify({
  44. entries: [ __dirname + '/no_builtins/main.js' ],
  45. commondir: false,
  46. builtins: {
  47. fs: require.resolve('./no_builtins/extra/fs.js'),
  48. tls: require.resolve('./no_builtins/extra/tls.js')
  49. }
  50. });
  51. var expected = [
  52. 'WRITE CODE EVERY DAY',
  53. 'WHATEVER'
  54. ];
  55. b.bundle(function (err, src) {
  56. var c = { console: { log: log }, require: require };
  57. function log (msg) {
  58. t.equal(msg, expected.shift());
  59. }
  60. vm.runInNewContext(src, c);
  61. });
  62. });