module_dir.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var path = require('path');
  2. var test = require('tape');
  3. var resolve = require('../');
  4. test('moduleDirectory strings', function (t) {
  5. t.plan(4);
  6. var dir = path.join(__dirname, 'module_dir');
  7. var xopts = {
  8. basedir: dir,
  9. moduleDirectory: 'xmodules'
  10. };
  11. resolve('aaa', xopts, function (err, res, pkg) {
  12. t.ifError(err);
  13. t.equal(res, path.join(dir, '/xmodules/aaa/index.js'));
  14. });
  15. var yopts = {
  16. basedir: dir,
  17. moduleDirectory: 'ymodules'
  18. };
  19. resolve('aaa', yopts, function (err, res, pkg) {
  20. t.ifError(err);
  21. t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
  22. });
  23. });
  24. test('moduleDirectory array', function (t) {
  25. t.plan(6);
  26. var dir = path.join(__dirname, 'module_dir');
  27. var aopts = {
  28. basedir: dir,
  29. moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
  30. };
  31. resolve('aaa', aopts, function (err, res, pkg) {
  32. t.ifError(err);
  33. t.equal(res, path.join(dir, '/xmodules/aaa/index.js'));
  34. });
  35. var bopts = {
  36. basedir: dir,
  37. moduleDirectory: ['zmodules', 'ymodules', 'xmodules']
  38. };
  39. resolve('aaa', bopts, function (err, res, pkg) {
  40. t.ifError(err);
  41. t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
  42. });
  43. var copts = {
  44. basedir: dir,
  45. moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
  46. };
  47. resolve('bbb', copts, function (err, res, pkg) {
  48. t.ifError(err);
  49. t.equal(res, path.join(dir, '/zmodules/bbb/main.js'));
  50. });
  51. });