node_path.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. __dirname + '/node_path/x',
  9. __dirname + '/node_path/y'
  10. ],
  11. basedir: __dirname,
  12. }, function (err, res) {
  13. t.equal(res, __dirname + '/node_path/x/aaa/index.js');
  14. });
  15. resolve('bbb', {
  16. paths: [
  17. __dirname + '/node_path/x',
  18. __dirname + '/node_path/y'
  19. ],
  20. basedir: __dirname,
  21. }, function (err, res) {
  22. t.equal(res, __dirname + '/node_path/y/bbb/index.js');
  23. });
  24. resolve('ccc', {
  25. paths: [
  26. __dirname + '/node_path/x',
  27. __dirname + '/node_path/y'
  28. ],
  29. basedir: __dirname,
  30. }, function (err, res) {
  31. t.equal(res, __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. t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap/lib/main.js'));
  42. });
  43. });