node_path.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var path = require('path');
  2. var test = require('tape');
  3. var resolve = require('../');
  4. test('$NODE_PATH', function (t) {
  5. t.plan(4);
  6. resolve('aaa', {
  7. paths: [
  8. path.join(__dirname, '/node_path/x'),
  9. path.join(__dirname, '/node_path/y')
  10. ],
  11. basedir: __dirname
  12. }, function (err, res) {
  13. t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'));
  14. });
  15. resolve('bbb', {
  16. paths: [
  17. path.join(__dirname, '/node_path/x'),
  18. path.join(__dirname, '/node_path/y')
  19. ],
  20. basedir: __dirname
  21. }, function (err, res) {
  22. t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'));
  23. });
  24. resolve('ccc', {
  25. paths: [
  26. path.join(__dirname, '/node_path/x'),
  27. path.join(__dirname, '/node_path/y')
  28. ],
  29. basedir: __dirname
  30. }, function (err, res) {
  31. t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'));
  32. });
  33. // ensure that relative paths still resolve against the
  34. // regular `node_modules` correctly
  35. resolve('tap', {
  36. paths: [
  37. 'node_path'
  38. ],
  39. basedir: 'node_path/x'
  40. }, function (err, res) {
  41. var root = require('tap/package.json').main;
  42. t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root));
  43. });
  44. });