paths_transform.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. function ensureTransform(t, buf) {
  5. var srcAsString = (buf||'').toString('utf-8'),
  6. containsAX = srcAsString.indexOf('AX') > -1,
  7. containsAZ = srcAsString.indexOf('AZ') > -1;
  8. t.notOk(containsAX,"should not contain AX's");
  9. t.ok(containsAZ,"should contain AZ's");
  10. }
  11. test('absolute paths with transform property', function (t) {
  12. t.plan(6);
  13. var b = browserify({
  14. transform: ['tr'],
  15. basedir: __dirname,
  16. paths: [ __dirname + '/paths/x', __dirname + '/paths/y' ],
  17. entries: __dirname + '/paths/main.js'
  18. });
  19. b.bundle(function (err, src) {
  20. t.ifError(err);
  21. ensureTransform(t,src);
  22. vm.runInNewContext(src, { t: t });
  23. });
  24. });
  25. test('relative paths with transform property', function (t) {
  26. t.plan(6);
  27. var b = browserify({
  28. transform: ['tr'],
  29. basedir: __dirname,
  30. paths: [ './paths/x', './paths/y' ],
  31. entries: __dirname + '/paths/main.js'
  32. });
  33. b.bundle(function (err, src) {
  34. t.ifError(err);
  35. ensureTransform(t,src);
  36. vm.runInNewContext(src, { t: t });
  37. });
  38. });
  39. test('absolute paths with transform method', function (t) {
  40. t.plan(6);
  41. var b = browserify({
  42. basedir: __dirname,
  43. paths: [ __dirname + '/paths/x', __dirname + '/paths/y' ],
  44. entries: __dirname + '/paths/main.js'
  45. });
  46. b.transform('tr');
  47. b.bundle(function (err, src) {
  48. t.ifError(err);
  49. ensureTransform(t,src);
  50. vm.runInNewContext(src, { t: t });
  51. });
  52. });
  53. test('relative paths with transform method', function (t) {
  54. t.plan(6);
  55. var b = browserify({
  56. basedir: __dirname,
  57. paths: ['./paths/x', './paths/y' ],
  58. entries: __dirname + '/paths/main.js'
  59. });
  60. b.transform('tr');
  61. b.bundle(function (err, src) {
  62. t.ifError(err);
  63. ensureTransform(t,src);
  64. vm.runInNewContext(src, { t: t });
  65. });
  66. });