multi_entry_cross_require.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var path = require('path');
  4. var test = require('tap').test;
  5. var testFiles = [
  6. path.join(__dirname, 'multi_entry_cross_require/a.js'),
  7. path.join(__dirname, 'multi_entry_cross_require/lib/b.js'),
  8. path.join(__dirname, 'multi_entry_cross_require/c.js')
  9. ];
  10. test('multi entry cross require', function (t) {
  11. t.plan(8);
  12. var b = browserify([
  13. testFiles[0],
  14. testFiles[1]
  15. ]);
  16. b.add(testFiles[2]);
  17. b.on('dep', function(row) {
  18. if (row.entry) {
  19. t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
  20. }
  21. });
  22. b.bundle(function (err, src) {
  23. if (err) throw err;
  24. var c = {
  25. times : 0,
  26. t : t
  27. };
  28. vm.runInNewContext(src, c);
  29. });
  30. });
  31. test('multi entry cross require - relative cwd', function (t) {
  32. t.plan(8);
  33. var dsTestFiles = testFiles.map(function(x) {
  34. return x.replace(__dirname + '/', './');
  35. });
  36. var b = browserify({
  37. entries: [dsTestFiles[0], dsTestFiles[1]],
  38. basedir: __dirname
  39. });
  40. b.add(dsTestFiles[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. if (err) throw err;
  48. var c = {
  49. times : 0,
  50. t : t
  51. };
  52. vm.runInNewContext(src, c);
  53. });
  54. });
  55. test('multi entry cross require - relative', function (t) {
  56. t.plan(8);
  57. var rTestFiles = testFiles.map(function(x) {
  58. return x.replace(__dirname + '/', '');
  59. });
  60. var b = browserify({
  61. entries: [rTestFiles[0], rTestFiles[1]],
  62. basedir: __dirname
  63. });
  64. b.add(rTestFiles[2]);
  65. b.on('dep', function(row) {
  66. if (row.entry) {
  67. t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
  68. }
  69. });
  70. b.bundle(function (err, src) {
  71. if (err) throw err;
  72. var c = {
  73. times : 0,
  74. t : t
  75. };
  76. vm.runInNewContext(src, c);
  77. });
  78. });