pathfilter.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var path = require('path');
  2. var test = require('tape');
  3. var resolve = require('../');
  4. var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
  5. var pathFilterFactory = function (t) {
  6. return function (pkg, x, remainder) {
  7. t.equal(pkg.version, '1.2.3');
  8. t.equal(x, path.join(resolverDir, 'node_modules/deep/ref'));
  9. t.equal(remainder, 'ref');
  10. return 'alt';
  11. };
  12. };
  13. test('#62: deep module references and the pathFilter', function (t) {
  14. t.test('deep/ref.js', function (st) {
  15. st.plan(3);
  16. resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) {
  17. if (err) st.fail(err);
  18. st.equal(pkg.version, '1.2.3');
  19. st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
  20. });
  21. var res = resolve.sync('deep/ref', { basedir: resolverDir });
  22. st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
  23. });
  24. t.test('deep/deeper/ref', function (st) {
  25. st.plan(4);
  26. resolve(
  27. 'deep/deeper/ref',
  28. { basedir: resolverDir },
  29. function (err, res, pkg) {
  30. if (err) t.fail(err);
  31. st.notEqual(pkg, undefined);
  32. st.equal(pkg.version, '1.2.3');
  33. st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
  34. }
  35. );
  36. var res = resolve.sync(
  37. 'deep/deeper/ref',
  38. { basedir: resolverDir }
  39. );
  40. st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
  41. });
  42. t.test('deep/ref alt', function (st) {
  43. st.plan(8);
  44. var pathFilter = pathFilterFactory(st);
  45. var res = resolve.sync(
  46. 'deep/ref',
  47. { basedir: resolverDir, pathFilter: pathFilter }
  48. );
  49. st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
  50. resolve(
  51. 'deep/ref',
  52. { basedir: resolverDir, pathFilter: pathFilter },
  53. function (err, res, pkg) {
  54. if (err) st.fail(err);
  55. st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
  56. st.end();
  57. }
  58. );
  59. });
  60. t.end();
  61. });