global_noparse.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var path = require('path');
  4. var test = require('tap').test;
  5. test('global noparse module', function (t) {
  6. t.plan(2);
  7. var b = browserify({
  8. noParse: 'aaa'
  9. });
  10. b.require(__dirname + '/global/node_modules/aaa', { expose: 'x' });
  11. b.bundle(function (err, src) {
  12. var c = {
  13. __filename: __filename,
  14. __dirname: __dirname
  15. };
  16. vm.runInNewContext(src, c);
  17. var x = c.require('x');
  18. t.equal(x.filename, __filename);
  19. t.equal(x.dirname, __dirname);
  20. });
  21. });
  22. test('global noparse module file', function (t) {
  23. t.plan(2);
  24. var b = browserify({
  25. noParse: 'aaa/index.js'
  26. });
  27. b.require(__dirname + '/global/node_modules/aaa', { expose: 'x' });
  28. b.bundle(function (err, src) {
  29. var c = {
  30. __filename: __filename,
  31. __dirname: __dirname
  32. };
  33. vm.runInNewContext(src, c);
  34. var x = c.require('x');
  35. t.equal(x.filename, __filename);
  36. t.equal(x.dirname, __dirname);
  37. });
  38. });
  39. test('global noparse module deep file', function (t) {
  40. t.plan(2);
  41. var b = browserify({
  42. noParse: 'robot/lib/beep.js'
  43. });
  44. b.require(__dirname + '/global/node_modules/robot', { expose: 'x' });
  45. b.bundle(function (err, src) {
  46. var c = {
  47. __filename: __filename,
  48. __dirname: __dirname
  49. };
  50. vm.runInNewContext(src, c);
  51. var x = c.require('x');
  52. t.equal(x.filename, __filename);
  53. t.equal(x.dirname, __dirname);
  54. });
  55. });
  56. test('global noparse basedir', function (t) {
  57. t.plan(2);
  58. var b = browserify({
  59. basedir: __dirname + '/global',
  60. noParse: 'filename.js'
  61. });
  62. b.require(__dirname + '/global/filename.js', { expose: 'x' });
  63. b.bundle(function (err, src) {
  64. var c = {
  65. __filename: __filename,
  66. __dirname: __dirname
  67. };
  68. vm.runInNewContext(src, c);
  69. var x = c.require('x');
  70. t.equal(x.filename, __filename);
  71. t.equal(x.dirname, __dirname);
  72. });
  73. });
  74. test('global noparse function', function (t) {
  75. t.plan(2);
  76. var b = browserify({
  77. noParse: function(file) {
  78. return file === path.join(__dirname, 'global/filename.js');
  79. }
  80. });
  81. b.require(__dirname + '/global/filename.js', { expose: 'x' });
  82. b.bundle(function (err, src) {
  83. var c = {
  84. __filename: __filename,
  85. __dirname: __dirname
  86. };
  87. vm.runInNewContext(src, c);
  88. var x = c.require('x');
  89. t.equal(x.filename, __filename);
  90. t.equal(x.dirname, __dirname);
  91. });
  92. });