ignore.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var browserify = require('../');
  2. var test = require('tap').test;
  3. var vm = require('vm');
  4. var path = require('path');
  5. test('ignore', function (t) {
  6. t.plan(1);
  7. var b = browserify();
  8. b.add(__dirname + '/ignore/main.js');
  9. b.ignore(path.join(__dirname, 'ignore/skip.js'));
  10. b.bundle(function (err, src) {
  11. if (err) t.fail(err);
  12. vm.runInNewContext(src, { t: t });
  13. });
  14. });
  15. test('ignore array', function(t) {
  16. t.plan(2);
  17. var b = browserify();
  18. b.add(__dirname + '/ignore/array.js');
  19. b.ignore([
  20. path.join(__dirname, 'ignore/skip.js'),
  21. path.join(__dirname, 'ignore/skip2.js')
  22. ]);
  23. b.bundle(function (err, src) {
  24. if (err) {
  25. t.fail(err);
  26. }
  27. vm.runInNewContext(src, { t: t });
  28. });
  29. });
  30. test('ignore by package or id', function (t) {
  31. t.plan(3);
  32. var b = browserify();
  33. b.add(__dirname + '/ignore/by-id.js');
  34. b.ignore('events');
  35. b.ignore('beep');
  36. b.ignore('bad id');
  37. b.bundle(function (err, src) {
  38. if (err) t.fail(err);
  39. vm.runInNewContext(src, { t: t });
  40. });
  41. });
  42. test('ignore files referenced by relative path', function (t) {
  43. // Change the current working directory relative to this file
  44. var cwd = process.cwd();
  45. process.chdir(__dirname);
  46. t.plan(1);
  47. var b = browserify();
  48. b.add(__dirname + '/ignore/by-relative.js');
  49. b.ignore('./ignore/ignored/skip.js');
  50. b.bundle(function (err, src) {
  51. if (err) t.fail(err);
  52. vm.runInNewContext(src, { t: t });
  53. });
  54. // Revert CWD
  55. process.chdir(cwd);
  56. });
  57. test('do not ignore files with relative paths that do not resolve', function (t) {
  58. // Change the current working directory to the ignore folder
  59. var cwd = process.cwd();
  60. process.chdir(__dirname + '/ignore');
  61. t.plan(2);
  62. var b = browserify();
  63. b.add(__dirname + '/ignore/double-skip.js');
  64. b.ignore('./skip.js');
  65. b.bundle(function (err, src) {
  66. if (err) t.fail(err);
  67. vm.runInNewContext(src, { t: t });
  68. });
  69. // Revert CWD
  70. process.chdir(cwd);
  71. });