wallet-core/node_modules/resolve/test/module_dir.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('moduleDirectory strings', function (t) {
t.plan(4);
2017-05-28 00:38:50 +02:00
var dir = path.join(__dirname, 'module_dir');
2016-10-10 03:43:44 +02:00
var xopts = {
2017-05-28 00:38:50 +02:00
basedir: dir,
2016-10-10 03:43:44 +02:00
moduleDirectory: 'xmodules'
};
resolve('aaa', xopts, function (err, res, pkg) {
t.ifError(err);
2017-05-28 00:38:50 +02:00
t.equal(res, path.join(dir, '/xmodules/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
var yopts = {
2017-05-28 00:38:50 +02:00
basedir: dir,
2016-10-10 03:43:44 +02:00
moduleDirectory: 'ymodules'
};
resolve('aaa', yopts, function (err, res, pkg) {
t.ifError(err);
2017-05-28 00:38:50 +02:00
t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
2016-10-10 03:43:44 +02:00
});
});
test('moduleDirectory array', function (t) {
t.plan(6);
2017-05-28 00:38:50 +02:00
var dir = path.join(__dirname, 'module_dir');
2016-10-10 03:43:44 +02:00
var aopts = {
2017-05-28 00:38:50 +02:00
basedir: dir,
moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
2016-10-10 03:43:44 +02:00
};
resolve('aaa', aopts, function (err, res, pkg) {
t.ifError(err);
2017-05-28 00:38:50 +02:00
t.equal(res, path.join(dir, '/xmodules/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
var bopts = {
2017-05-28 00:38:50 +02:00
basedir: dir,
moduleDirectory: ['zmodules', 'ymodules', 'xmodules']
2016-10-10 03:43:44 +02:00
};
resolve('aaa', bopts, function (err, res, pkg) {
t.ifError(err);
2017-05-28 00:38:50 +02:00
t.equal(res, path.join(dir, '/ymodules/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
var copts = {
2017-05-28 00:38:50 +02:00
basedir: dir,
moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
2016-10-10 03:43:44 +02:00
};
resolve('bbb', copts, function (err, res, pkg) {
t.ifError(err);
2017-05-28 00:38:50 +02:00
t.equal(res, path.join(dir, '/zmodules/bbb/main.js'));
2016-10-10 03:43:44 +02:00
});
});