1 var fs = require('fs');
2 var path = require('path');
3 var test = require('tape');
4 var resolve = require('../');
6 test('$NODE_PATH', function (t) {
9 var isDir = function (dir, cb) {
10 if (dir === '/node_path' || dir === 'node_path/x') {
11 return cb(null, true);
13 fs.stat(dir, function (err, stat) {
15 return cb(null, stat.isDirectory());
17 if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
24 path.join(__dirname, '/node_path/x'),
25 path.join(__dirname, '/node_path/y')
29 }, function (err, res) {
31 t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'), 'aaa resolves');
36 path.join(__dirname, '/node_path/x'),
37 path.join(__dirname, '/node_path/y')
41 }, function (err, res) {
43 t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'), 'bbb resolves');
48 path.join(__dirname, '/node_path/x'),
49 path.join(__dirname, '/node_path/y')
53 }, function (err, res) {
55 t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'), 'ccc resolves');
58 // ensure that relative paths still resolve against the regular `node_modules` correctly
63 basedir: path.join(__dirname, 'node_path/x'),
65 }, function (err, res) {
66 var root = require('tap/package.json').main;
68 t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root), 'tap resolves');