resolve_exposed.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. test('resolve exposed files', function (t) {
  5. t.plan(2);
  6. var b = browserify(__dirname + '/resolve_exposed/main.js', {
  7. basedir: __dirname + '/resolve_exposed'
  8. });
  9. b.require('./x.js', { expose: 'xyz' });
  10. b.bundle(function (err, src) {
  11. t.ifError(err);
  12. var c = { console: { log: log } };
  13. vm.runInNewContext(src, c);
  14. function log (x) {
  15. t.equal(x, 333);
  16. }
  17. });
  18. });
  19. test('resolve exposed files without extension', function (t) {
  20. t.plan(2);
  21. var b = browserify(__dirname + '/resolve_exposed/main.js', {
  22. basedir: __dirname + '/resolve_exposed'
  23. });
  24. b.require('./x', {expose: 'xyz'});
  25. b.bundle(function (err, src) {
  26. t.ifError(err);
  27. var c = {console: {log: log}};
  28. vm.runInNewContext(src, c);
  29. function log(x) {
  30. t.equal(x, 333);
  31. }
  32. });
  33. });
  34. test('resolve exposed directories', function (t) {
  35. t.plan(2);
  36. var b = browserify(__dirname + '/resolve_exposed/main.js', {
  37. basedir: __dirname + '/resolve_exposed'
  38. });
  39. b.require('./y', {expose: 'xyz'});
  40. b.bundle(function (err, src) {
  41. t.ifError(err);
  42. var c = {console: {log: log}};
  43. vm.runInNewContext(src, c);
  44. function log(x) {
  45. t.equal(x, 555);
  46. }
  47. });
  48. });
  49. test('resolve exposed index from directories', function (t) {
  50. t.plan(2);
  51. var b = browserify(__dirname + '/resolve_exposed/main.js', {
  52. basedir: __dirname + '/resolve_exposed'
  53. });
  54. b.require('./y/index', {expose: 'xyz'});
  55. b.bundle(function (err, src) {
  56. t.ifError(err);
  57. var c = {console: {log: log}};
  58. vm.runInNewContext(src, c);
  59. function log(x) {
  60. t.equal(x, 555);
  61. }
  62. });
  63. });
  64. test('resolve exposed index.js from directories', function (t) {
  65. t.plan(2);
  66. var b = browserify(__dirname + '/resolve_exposed/main.js', {
  67. basedir: __dirname + '/resolve_exposed'
  68. });
  69. b.require('./y/index.js', {expose: 'xyz'});
  70. b.bundle(function (err, src) {
  71. t.ifError(err);
  72. var c = {console: {log: log}};
  73. vm.runInNewContext(src, c);
  74. function log(x) {
  75. t.equal(x, 555);
  76. }
  77. });
  78. });