multi_entry.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var path = require('path');
  4. var test = require('tap').test;
  5. var fs = require('fs');
  6. var testFiles = [
  7. path.join(__dirname, 'multi_entry/a.js'),
  8. path.join(__dirname, 'multi_entry/b.js'),
  9. path.join(__dirname, 'multi_entry/c.js')
  10. ];
  11. test('multi entry', function (t) {
  12. t.plan(6);
  13. var b = browserify([
  14. testFiles[0],
  15. testFiles[1]
  16. ]);
  17. b.add(testFiles[2]);
  18. b.on('dep', function(row) {
  19. if (row.entry) {
  20. t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
  21. }
  22. });
  23. b.bundle(function (err, src) {
  24. var c = {
  25. times : 0,
  26. t : t
  27. };
  28. vm.runInNewContext(src, c);
  29. });
  30. });
  31. test('multi entry relative', function (t) {
  32. t.plan(6);
  33. var rTestFiles = testFiles.map(function(x) {
  34. return x.replace(__dirname + '/', '');
  35. });
  36. var b = browserify({
  37. entries: [rTestFiles[0], rTestFiles[1]],
  38. basedir: __dirname
  39. });
  40. b.add(rTestFiles[2]);
  41. b.on('dep', function(row) {
  42. if (row.entry) {
  43. t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
  44. }
  45. });
  46. b.bundle(function (err, src) {
  47. var c = {
  48. times : 0,
  49. t : t
  50. };
  51. vm.runInNewContext(src, c);
  52. });
  53. });
  54. test('multi entry relative cwd', function (t) {
  55. t.plan(6);
  56. var rTestFiles = testFiles.map(function(x) {
  57. return x.replace(__dirname + '/', './');
  58. });
  59. var b = browserify({
  60. entries: [rTestFiles[0], rTestFiles[1]],
  61. basedir: __dirname
  62. });
  63. b.add(rTestFiles[2]);
  64. b.on('dep', function(row) {
  65. if (row.entry) {
  66. t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
  67. }
  68. });
  69. b.bundle(function (err, src) {
  70. var c = {
  71. times : 0,
  72. t : t
  73. };
  74. vm.runInNewContext(src, c);
  75. });
  76. });
  77. test('entries as streams', function (t) {
  78. t.plan(6);
  79. // commondir blows up with streams and without basedir
  80. var opts = { basedir: __dirname + '/multi_entry' };
  81. var b = browserify([
  82. fs.createReadStream(testFiles[0]),
  83. fs.createReadStream(testFiles[1])
  84. ], opts);
  85. b.add(fs.createReadStream(testFiles[2]));
  86. b.on('dep', function(row) {
  87. if (row.entry) {
  88. t.similar(
  89. row.file,
  90. RegExp(path.join(__dirname, 'multi_entry/_stream_').replace(/\\/g, '\\\\') + '[\\d].js'),
  91. 'should be full entry path'
  92. );
  93. }
  94. });
  95. b.bundle(function (err, src) {
  96. var c = {
  97. times : 0,
  98. t : t
  99. };
  100. vm.runInNewContext(src, c);
  101. });
  102. });