2016-10-10 03:43:44 +02:00
|
|
|
var path = require('path');
|
|
|
|
var test = require('tape');
|
|
|
|
var resolve = require('../');
|
|
|
|
|
|
|
|
test('$NODE_PATH', function (t) {
|
|
|
|
t.plan(4);
|
2017-05-28 00:38:50 +02:00
|
|
|
|
2016-10-10 03:43:44 +02:00
|
|
|
resolve('aaa', {
|
|
|
|
paths: [
|
2017-05-28 00:38:50 +02:00
|
|
|
path.join(__dirname, '/node_path/x'),
|
|
|
|
path.join(__dirname, '/node_path/y')
|
2016-10-10 03:43:44 +02:00
|
|
|
],
|
2017-05-28 00:38:50 +02:00
|
|
|
basedir: __dirname
|
2016-10-10 03:43:44 +02:00
|
|
|
}, function (err, res) {
|
2017-05-28 00:38:50 +02:00
|
|
|
t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'));
|
2016-10-10 03:43:44 +02:00
|
|
|
});
|
2017-05-28 00:38:50 +02:00
|
|
|
|
2016-10-10 03:43:44 +02:00
|
|
|
resolve('bbb', {
|
|
|
|
paths: [
|
2017-05-28 00:38:50 +02:00
|
|
|
path.join(__dirname, '/node_path/x'),
|
|
|
|
path.join(__dirname, '/node_path/y')
|
2016-10-10 03:43:44 +02:00
|
|
|
],
|
2017-05-28 00:38:50 +02:00
|
|
|
basedir: __dirname
|
2016-10-10 03:43:44 +02:00
|
|
|
}, function (err, res) {
|
2017-05-28 00:38:50 +02:00
|
|
|
t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'));
|
2016-10-10 03:43:44 +02:00
|
|
|
});
|
2017-05-28 00:38:50 +02:00
|
|
|
|
2016-10-10 03:43:44 +02:00
|
|
|
resolve('ccc', {
|
|
|
|
paths: [
|
2017-05-28 00:38:50 +02:00
|
|
|
path.join(__dirname, '/node_path/x'),
|
|
|
|
path.join(__dirname, '/node_path/y')
|
2016-10-10 03:43:44 +02:00
|
|
|
],
|
2017-05-28 00:38:50 +02:00
|
|
|
basedir: __dirname
|
2016-10-10 03:43:44 +02:00
|
|
|
}, function (err, res) {
|
2017-05-28 00:38:50 +02:00
|
|
|
t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'));
|
2016-10-10 03:43:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// ensure that relative paths still resolve against the
|
|
|
|
// regular `node_modules` correctly
|
|
|
|
resolve('tap', {
|
|
|
|
paths: [
|
2017-05-28 00:38:50 +02:00
|
|
|
'node_path'
|
2016-10-10 03:43:44 +02:00
|
|
|
],
|
2017-05-28 00:38:50 +02:00
|
|
|
basedir: 'node_path/x'
|
2016-10-10 03:43:44 +02:00
|
|
|
}, function (err, res) {
|
2017-05-28 00:38:50 +02:00
|
|
|
var root = require('tap/package.json').main;
|
|
|
|
t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root));
|
2016-10-10 03:43:44 +02:00
|
|
|
});
|
|
|
|
});
|