This commit is contained in:
Stephen Franceschelli 2019-07-30 13:41:05 -04:00
parent 596a6da241
commit c1a589c5b6
7078 changed files with 1882834 additions and 319 deletions

5
node_modules/resolve/test/.eslintrc generated vendored Normal file
View file

@ -0,0 +1,5 @@
{
"rules": {
"max-lines": 0
}
}

82
node_modules/resolve/test/core.js generated vendored Normal file
View file

@ -0,0 +1,82 @@
var test = require('tape');
var keys = require('object-keys');
var resolve = require('../');
test('core modules', function (t) {
t.test('isCore()', function (st) {
st.ok(resolve.isCore('fs'));
st.ok(resolve.isCore('net'));
st.ok(resolve.isCore('http'));
st.ok(!resolve.isCore('seq'));
st.ok(!resolve.isCore('../'));
st.end();
});
t.test('core list', function (st) {
var cores = keys(resolve.core);
st.plan(cores.length);
for (var i = 0; i < cores.length; ++i) {
var mod = cores[i];
if (resolve.core[mod]) {
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
mod + ' supported; requiring does not throw'
);
} else {
st.throws(
function () { require(mod); }, // eslint-disable-line no-loop-func
mod + ' not supported; requiring throws'
);
}
}
st.end();
});
t.test('core via repl module', { skip: !resolve.core.repl }, function (st) {
var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
if (!libs) {
st.skip('module.builtinModules does not exist');
return st.end();
}
for (var i = 0; i < libs.length; ++i) {
var mod = libs[i];
st.ok(resolve.core[mod], mod + ' is a core module');
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
}
st.end();
});
t.test('core via builtinModules list', { skip: !resolve.core.module }, function (st) {
var libs = require('module').builtinModules;
if (!libs) {
st.skip('module.builtinModules does not exist');
return st.end();
}
var blacklist = [
'_debug_agent',
'v8/tools/tickprocessor-driver',
'v8/tools/SourceMap',
'v8/tools/tickprocessor',
'v8/tools/profile'
];
for (var i = 0; i < libs.length; ++i) {
var mod = libs[i];
if (blacklist.indexOf(mod) === -1) {
st.ok(resolve.core[mod], mod + ' is a core module');
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
}
}
st.end();
});
t.end();
});

29
node_modules/resolve/test/dotdot.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('dotdot', function (t) {
t.plan(4);
var dir = path.join(__dirname, '/dotdot/abc');
resolve('..', { basedir: dir }, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(__dirname, 'dotdot/index.js'));
});
resolve('.', { basedir: dir }, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, 'index.js'));
});
});
test('dotdot sync', function (t) {
t.plan(2);
var dir = path.join(__dirname, '/dotdot/abc');
var a = resolve.sync('..', { basedir: dir });
t.equal(a, path.join(__dirname, 'dotdot/index.js'));
var b = resolve.sync('.', { basedir: dir });
t.equal(b, path.join(dir, 'index.js'));
});

2
node_modules/resolve/test/dotdot/abc/index.js generated vendored Normal file
View file

@ -0,0 +1,2 @@
var x = require('..');
console.log(x);

1
node_modules/resolve/test/dotdot/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'whatever';

29
node_modules/resolve/test/faulty_basedir.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
var test = require('tape');
var path = require('path');
var resolve = require('../');
test('faulty basedir must produce error in windows', { skip: process.platform !== 'win32' }, function (t) {
t.plan(1);
var resolverDir = 'C:\\a\\b\\c\\d';
resolve('tape/lib/test.js', { basedir: resolverDir }, function (err, res, pkg) {
t.equal(!!err, true);
});
});
test('non-existent basedir should not throw when preserveSymlinks is false', function (t) {
t.plan(2);
var opts = {
basedir: path.join(path.sep, 'unreal', 'path', 'that', 'does', 'not', 'exist'),
preserveSymlinks: false
};
var module = './dotdot/abc';
resolve(module, opts, function (err, res) {
t.equal(err.code, 'MODULE_NOT_FOUND');
t.equal(res, undefined);
});
});

34
node_modules/resolve/test/filter.js generated vendored Normal file
View file

@ -0,0 +1,34 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('filter', function (t) {
t.plan(4);
var dir = path.join(__dirname, 'resolver');
var packageFilterArgs;
resolve('./baz', {
basedir: dir,
packageFilter: function (pkg, pkgfile) {
pkg.main = 'doom';
packageFilterArgs = [pkg, pkgfile];
return pkg;
}
}, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
var packageData = packageFilterArgs[0];
t.equal(pkg, packageData, 'first packageFilter argument is "pkg"');
t.equal(packageData.main, 'doom', 'package "main" was altered');
var packageFile = packageFilterArgs[1];
t.equal(
packageFile,
path.join(dir, 'baz/package.json'),
'second packageFilter argument is "pkgfile"'
);
t.end();
});
});

26
node_modules/resolve/test/filter_sync.js generated vendored Normal file
View file

@ -0,0 +1,26 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('filter', function (t) {
var dir = path.join(__dirname, 'resolver');
var packageFilterArgs;
var res = resolve.sync('./baz', {
basedir: dir,
packageFilter: function (pkg, dir) {
pkg.main = 'doom';
packageFilterArgs = [pkg, dir];
return pkg;
}
});
t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
var packageData = packageFilterArgs[0];
t.equal(packageData.main, 'doom', 'package "main" was altered');
var packageFile = packageFilterArgs[1];
t.equal(packageFile, path.join(dir, 'baz'), 'second packageFilter argument is "dir"');
t.end();
});

169
node_modules/resolve/test/mock.js generated vendored Normal file
View file

@ -0,0 +1,169 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('mock', function (t) {
t.plan(8);
var files = {};
files[path.resolve('/foo/bar/baz.js')] = 'beep';
var dirs = {};
dirs[path.resolve('/foo/bar')] = true;
function opts(basedir) {
return {
basedir: path.resolve(basedir),
isFile: function (file, cb) {
cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
},
isDirectory: function (dir, cb) {
cb(null, !!dirs[path.resolve(dir)]);
},
readFile: function (file, cb) {
cb(null, files[path.resolve(file)]);
}
};
}
resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
if (err) return t.fail(err);
t.equal(res, path.resolve('/foo/bar/baz.js'));
t.equal(pkg, undefined);
});
resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
if (err) return t.fail(err);
t.equal(res, path.resolve('/foo/bar/baz.js'));
t.equal(pkg, undefined);
});
resolve('baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
resolve('../baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
});
test('mock from package', function (t) {
t.plan(8);
var files = {};
files[path.resolve('/foo/bar/baz.js')] = 'beep';
var dirs = {};
dirs[path.resolve('/foo/bar')] = true;
function opts(basedir) {
return {
basedir: path.resolve(basedir),
isFile: function (file, cb) {
cb(null, Object.prototype.hasOwnProperty.call(files, file));
},
isDirectory: function (dir, cb) {
cb(null, !!dirs[path.resolve(dir)]);
},
'package': { main: 'bar' },
readFile: function (file, cb) {
cb(null, files[file]);
}
};
}
resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
if (err) return t.fail(err);
t.equal(res, path.resolve('/foo/bar/baz.js'));
t.equal(pkg && pkg.main, 'bar');
});
resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
if (err) return t.fail(err);
t.equal(res, path.resolve('/foo/bar/baz.js'));
t.equal(pkg && pkg.main, 'bar');
});
resolve('baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
resolve('../baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
});
test('mock package', function (t) {
t.plan(2);
var files = {};
files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep';
files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
main: './baz.js'
});
var dirs = {};
dirs[path.resolve('/foo')] = true;
dirs[path.resolve('/foo/node_modules')] = true;
function opts(basedir) {
return {
basedir: path.resolve(basedir),
isFile: function (file, cb) {
cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
},
isDirectory: function (dir, cb) {
cb(null, !!dirs[path.resolve(dir)]);
},
readFile: function (file, cb) {
cb(null, files[path.resolve(file)]);
}
};
}
resolve('bar', opts('/foo'), function (err, res, pkg) {
if (err) return t.fail(err);
t.equal(res, path.resolve('/foo/node_modules/bar/baz.js'));
t.equal(pkg && pkg.main, './baz.js');
});
});
test('mock package from package', function (t) {
t.plan(2);
var files = {};
files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep';
files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
main: './baz.js'
});
var dirs = {};
dirs[path.resolve('/foo')] = true;
dirs[path.resolve('/foo/node_modules')] = true;
function opts(basedir) {
return {
basedir: path.resolve(basedir),
isFile: function (file, cb) {
cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
},
isDirectory: function (dir, cb) {
cb(null, !!dirs[path.resolve(dir)]);
},
'package': { main: 'bar' },
readFile: function (file, cb) {
cb(null, files[path.resolve(file)]);
}
};
}
resolve('bar', opts('/foo'), function (err, res, pkg) {
if (err) return t.fail(err);
t.equal(res, path.resolve('/foo/node_modules/bar/baz.js'));
t.equal(pkg && pkg.main, './baz.js');
});
});

80
node_modules/resolve/test/mock_sync.js generated vendored Normal file
View file

@ -0,0 +1,80 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('mock', function (t) {
t.plan(4);
var files = {};
files[path.resolve('/foo/bar/baz.js')] = 'beep';
var dirs = {};
dirs[path.resolve('/foo/bar')] = true;
function opts(basedir) {
return {
basedir: path.resolve(basedir),
isFile: function (file) {
return Object.prototype.hasOwnProperty.call(files, path.resolve(file));
},
isDirectory: function (dir) {
return !!dirs[path.resolve(dir)];
},
readFileSync: function (file) {
return files[path.resolve(file)];
}
};
}
t.equal(
resolve.sync('./baz', opts('/foo/bar')),
path.resolve('/foo/bar/baz.js')
);
t.equal(
resolve.sync('./baz.js', opts('/foo/bar')),
path.resolve('/foo/bar/baz.js')
);
t.throws(function () {
resolve.sync('baz', opts('/foo/bar'));
});
t.throws(function () {
resolve.sync('../baz', opts('/foo/bar'));
});
});
test('mock package', function (t) {
t.plan(1);
var files = {};
files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep';
files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
main: './baz.js'
});
var dirs = {};
dirs[path.resolve('/foo')] = true;
dirs[path.resolve('/foo/node_modules')] = true;
function opts(basedir) {
return {
basedir: path.resolve(basedir),
isFile: function (file) {
return Object.prototype.hasOwnProperty.call(files, path.resolve(file));
},
isDirectory: function (dir) {
return !!dirs[path.resolve(dir)];
},
readFileSync: function (file) {
return files[path.resolve(file)];
}
};
}
t.equal(
resolve.sync('bar', opts('/foo')),
path.resolve('/foo/node_modules/bar/baz.js')
);
});

56
node_modules/resolve/test/module_dir.js generated vendored Normal file
View file

@ -0,0 +1,56 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('moduleDirectory strings', function (t) {
t.plan(4);
var dir = path.join(__dirname, 'module_dir');
var xopts = {
basedir: dir,
moduleDirectory: 'xmodules'
};
resolve('aaa', xopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, '/xmodules/aaa/index.js'));
});
var yopts = {
basedir: dir,
moduleDirectory: 'ymodules'
};
resolve('aaa', yopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
});
});
test('moduleDirectory array', function (t) {
t.plan(6);
var dir = path.join(__dirname, 'module_dir');
var aopts = {
basedir: dir,
moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
};
resolve('aaa', aopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, '/xmodules/aaa/index.js'));
});
var bopts = {
basedir: dir,
moduleDirectory: ['zmodules', 'ymodules', 'xmodules']
};
resolve('aaa', bopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
});
var copts = {
basedir: dir,
moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
};
resolve('bbb', copts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, '/zmodules/bbb/main.js'));
});
});

View file

@ -0,0 +1 @@
module.exports = function (x) { return x * 100; };

View file

@ -0,0 +1 @@
module.exports = function (x) { return x + 100; };

View file

@ -0,0 +1 @@
module.exports = function (n) { return n * 111; };

View file

@ -0,0 +1,3 @@
{
"main": "main.js"
}

143
node_modules/resolve/test/node-modules-paths.js generated vendored Normal file
View file

@ -0,0 +1,143 @@
var test = require('tape');
var path = require('path');
var parse = path.parse || require('path-parse');
var keys = require('object-keys');
var nodeModulesPaths = require('../lib/node-modules-paths');
var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
var moduleDirs = [].concat(moduleDirectories || 'node_modules');
if (paths) {
for (var k = 0; k < paths.length; ++k) {
moduleDirs.push(path.basename(paths[k]));
}
}
var foundModuleDirs = {};
var uniqueDirs = {};
var parsedDirs = {};
for (var i = 0; i < dirs.length; ++i) {
var parsed = parse(dirs[i]);
if (!foundModuleDirs[parsed.base]) { foundModuleDirs[parsed.base] = 0; }
foundModuleDirs[parsed.base] += 1;
parsedDirs[parsed.dir] = true;
uniqueDirs[dirs[i]] = true;
}
t.equal(keys(parsedDirs).length >= start.split(path.sep).length, true, 'there are >= dirs than "start" has');
var foundModuleDirNames = keys(foundModuleDirs);
t.deepEqual(foundModuleDirNames, moduleDirs, 'all desired module dirs were found');
t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique');
var counts = {};
for (var j = 0; j < foundModuleDirNames.length; ++j) {
counts[foundModuleDirs[j]] = true;
}
t.equal(keys(counts).length, 1, 'all found module directories had the same count');
};
test('node-modules-paths', function (t) {
t.test('no options', function (t) {
var start = path.join(__dirname, 'resolver');
var dirs = nodeModulesPaths(start);
verifyDirs(t, start, dirs);
t.end();
});
t.test('empty options', function (t) {
var start = path.join(__dirname, 'resolver');
var dirs = nodeModulesPaths(start, {});
verifyDirs(t, start, dirs);
t.end();
});
t.test('with paths=array option', function (t) {
var start = path.join(__dirname, 'resolver');
var paths = ['a', 'b'];
var dirs = nodeModulesPaths(start, { paths: paths });
verifyDirs(t, start, dirs, null, paths);
t.end();
});
t.test('with paths=function option', function (t) {
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
return getNodeModulesDirs().concat(path.join(absoluteStart, 'not node modules', request));
};
var start = path.join(__dirname, 'resolver');
var dirs = nodeModulesPaths(start, { paths: paths }, 'pkg');
verifyDirs(t, start, dirs, null, [path.join(start, 'not node modules', 'pkg')]);
t.end();
});
t.test('with paths=function skipping node modules resolution', function (t) {
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
return [];
};
var start = path.join(__dirname, 'resolver');
var dirs = nodeModulesPaths(start, { paths: paths });
t.deepEqual(dirs, [], 'no node_modules was computed');
t.end();
});
t.test('with moduleDirectory option', function (t) {
var start = path.join(__dirname, 'resolver');
var moduleDirectory = 'not node modules';
var dirs = nodeModulesPaths(start, { moduleDirectory: moduleDirectory });
verifyDirs(t, start, dirs, moduleDirectory);
t.end();
});
t.test('with 1 moduleDirectory and paths options', function (t) {
var start = path.join(__dirname, 'resolver');
var paths = ['a', 'b'];
var moduleDirectory = 'not node modules';
var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectory });
verifyDirs(t, start, dirs, moduleDirectory, paths);
t.end();
});
t.test('with 1+ moduleDirectory and paths options', function (t) {
var start = path.join(__dirname, 'resolver');
var paths = ['a', 'b'];
var moduleDirectories = ['not node modules', 'other modules'];
var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
verifyDirs(t, start, dirs, moduleDirectories, paths);
t.end();
});
t.test('combine paths correctly on Windows', function (t) {
var start = 'C:\\Users\\username\\myProject\\src';
var paths = [];
var moduleDirectories = ['node_modules', start];
var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');
t.end();
});
t.test('combine paths correctly on non-Windows', { skip: process.platform === 'win32' }, function (t) {
var start = '/Users/username/git/myProject/src';
var paths = [];
var moduleDirectories = ['node_modules', '/Users/username/git/myProject/src'];
var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');
t.end();
});
});

70
node_modules/resolve/test/node_path.js generated vendored Normal file
View file

@ -0,0 +1,70 @@
var fs = require('fs');
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('$NODE_PATH', function (t) {
t.plan(8);
var isDir = function (dir, cb) {
if (dir === '/node_path' || dir === 'node_path/x') {
return cb(null, true);
}
fs.stat(dir, function (err, stat) {
if (!err) {
return cb(null, stat.isDirectory());
}
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
return cb(err);
});
};
resolve('aaa', {
paths: [
path.join(__dirname, '/node_path/x'),
path.join(__dirname, '/node_path/y')
],
basedir: __dirname,
isDirectory: isDir
}, function (err, res) {
t.error(err);
t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'), 'aaa resolves');
});
resolve('bbb', {
paths: [
path.join(__dirname, '/node_path/x'),
path.join(__dirname, '/node_path/y')
],
basedir: __dirname,
isDirectory: isDir
}, function (err, res) {
t.error(err);
t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'), 'bbb resolves');
});
resolve('ccc', {
paths: [
path.join(__dirname, '/node_path/x'),
path.join(__dirname, '/node_path/y')
],
basedir: __dirname,
isDirectory: isDir
}, function (err, res) {
t.error(err);
t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'), 'ccc resolves');
});
// ensure that relative paths still resolve against the regular `node_modules` correctly
resolve('tap', {
paths: [
'node_path'
],
basedir: path.join(__dirname, 'node_path/x'),
isDirectory: isDir
}, function (err, res) {
var root = require('tap/package.json').main;
t.error(err);
t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root), 'tap resolves');
});
});

1
node_modules/resolve/test/node_path/x/aaa/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'A';

1
node_modules/resolve/test/node_path/x/ccc/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'C';

1
node_modules/resolve/test/node_path/y/bbb/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'B';

1
node_modules/resolve/test/node_path/y/ccc/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'CY';

9
node_modules/resolve/test/nonstring.js generated vendored Normal file
View file

@ -0,0 +1,9 @@
var test = require('tape');
var resolve = require('../');
test('nonstring', function (t) {
t.plan(1);
resolve(555, function (err, res, pkg) {
t.ok(err);
});
});

75
node_modules/resolve/test/pathfilter.js generated vendored Normal file
View file

@ -0,0 +1,75 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
var pathFilterFactory = function (t) {
return function (pkg, x, remainder) {
t.equal(pkg.version, '1.2.3');
t.equal(x, path.join(resolverDir, 'node_modules/deep/ref'));
t.equal(remainder, 'ref');
return 'alt';
};
};
test('#62: deep module references and the pathFilter', function (t) {
t.test('deep/ref.js', function (st) {
st.plan(3);
resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) {
if (err) st.fail(err);
st.equal(pkg.version, '1.2.3');
st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
});
var res = resolve.sync('deep/ref', { basedir: resolverDir });
st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
});
t.test('deep/deeper/ref', function (st) {
st.plan(4);
resolve(
'deep/deeper/ref',
{ basedir: resolverDir },
function (err, res, pkg) {
if (err) t.fail(err);
st.notEqual(pkg, undefined);
st.equal(pkg.version, '1.2.3');
st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
}
);
var res = resolve.sync(
'deep/deeper/ref',
{ basedir: resolverDir }
);
st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
});
t.test('deep/ref alt', function (st) {
st.plan(8);
var pathFilter = pathFilterFactory(st);
var res = resolve.sync(
'deep/ref',
{ basedir: resolverDir, pathFilter: pathFilter }
);
st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
resolve(
'deep/ref',
{ basedir: resolverDir, pathFilter: pathFilter },
function (err, res, pkg) {
if (err) st.fail(err);
st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
st.end();
}
);
});
t.end();
});

View file

23
node_modules/resolve/test/precedence.js generated vendored Normal file
View file

@ -0,0 +1,23 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('precedence', function (t) {
t.plan(3);
var dir = path.join(__dirname, 'precedence/aaa');
resolve('./', { basedir: dir }, function (err, res, pkg) {
t.ifError(err);
t.equal(res, path.join(dir, 'index.js'));
t.equal(pkg.name, 'resolve');
});
});
test('./ should not load ${dir}.js', function (t) { // eslint-disable-line no-template-curly-in-string
t.plan(1);
var dir = path.join(__dirname, 'precedence/bbb');
resolve('./', { basedir: dir }, function (err, res, pkg) {
t.ok(err);
});
});

1
node_modules/resolve/test/precedence/aaa.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'wtf';

1
node_modules/resolve/test/precedence/aaa/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 'okok';

1
node_modules/resolve/test/precedence/aaa/main.js generated vendored Normal file
View file

@ -0,0 +1 @@
console.log(require('./'));

1
node_modules/resolve/test/precedence/bbb.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = '>_<';

1
node_modules/resolve/test/precedence/bbb/main.js generated vendored Normal file
View file

@ -0,0 +1 @@
console.log(require('./')); // should throw

418
node_modules/resolve/test/resolver.js generated vendored Normal file
View file

@ -0,0 +1,418 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('async foo', function (t) {
t.plan(12);
var dir = path.join(__dirname, 'resolver');
resolve('./foo', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo.js'));
t.equal(pkg && pkg.name, 'resolve');
});
resolve('./foo.js', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo.js'));
t.equal(pkg && pkg.name, 'resolve');
});
resolve('./foo', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo.js'));
t.equal(pkg && pkg.main, 'resolver');
});
resolve('./foo.js', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo.js'));
t.equal(pkg.main, 'resolver');
});
resolve('./foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo.js'));
});
resolve('foo', { basedir: dir }, function (err) {
t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
// Test that filename is reported as the "from" value when passed.
resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) {
t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'");
});
});
test('bar', function (t) {
t.plan(6);
var dir = path.join(__dirname, 'resolver');
resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
t.equal(pkg, undefined);
});
resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
t.equal(pkg, undefined);
});
resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
t.equal(pkg.main, 'bar');
});
});
test('baz', function (t) {
t.plan(4);
var dir = path.join(__dirname, 'resolver');
resolve('./baz', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'baz/quux.js'));
t.equal(pkg.main, 'quux.js');
});
resolve('./baz', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'baz/quux.js'));
t.equal(pkg.main, 'quux.js');
});
});
test('biz', function (t) {
t.plan(24);
var dir = path.join(__dirname, 'resolver/biz/node_modules');
resolve('./grux', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'grux/index.js'));
t.equal(pkg, undefined);
});
resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'grux/index.js'));
t.equal(pkg.main, 'biz');
});
resolve('./garply', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'garply/lib/index.js'));
t.equal(pkg.main, './lib');
});
resolve('./garply', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'garply/lib/index.js'));
t.equal(pkg.main, './lib');
});
resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'tiv/index.js'));
t.equal(pkg, undefined);
});
resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'tiv/index.js'));
t.equal(pkg.main, 'grux');
});
resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'tiv/index.js'));
t.equal(pkg, undefined);
});
resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'tiv/index.js'));
t.equal(pkg.main, './lib');
});
resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'grux/index.js'));
t.equal(pkg, undefined);
});
resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'grux/index.js'));
t.equal(pkg.main, 'tiv');
});
resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'garply/lib/index.js'));
t.equal(pkg.main, './lib');
});
resolve('garply', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'garply/lib/index.js'));
t.equal(pkg.main, './lib');
});
});
test('quux', function (t) {
t.plan(2);
var dir = path.join(__dirname, 'resolver/quux');
resolve('./foo', { basedir: dir, 'package': { main: 'quux' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo/index.js'));
t.equal(pkg.main, 'quux');
});
});
test('normalize', function (t) {
t.plan(2);
var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');
resolve('../grux', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'index.js'));
t.equal(pkg, undefined);
});
});
test('cup', function (t) {
t.plan(5);
var dir = path.join(__dirname, 'resolver');
resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'cup.coffee'));
});
resolve('./cup.coffee', { basedir: dir }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'cup.coffee'));
});
resolve('./cup', { basedir: dir, extensions: ['.js'] }, function (err, res) {
t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
// Test that filename is reported as the "from" value when passed.
resolve('./cup', { basedir: dir, extensions: ['.js'], filename: path.join(dir, 'cupboard.js') }, function (err, res) {
t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'");
});
});
test('mug', function (t) {
t.plan(3);
var dir = path.join(__dirname, 'resolver');
resolve('./mug', { basedir: dir }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'mug.js'));
});
resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(dir, '/mug.coffee'));
});
resolve('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {
t.equal(res, path.join(dir, '/mug.js'));
});
});
test('other path', function (t) {
t.plan(6);
var resolverDir = path.join(__dirname, 'resolver');
var dir = path.join(resolverDir, 'bar');
var otherDir = path.join(resolverDir, 'other_path');
resolve('root', { basedir: dir, paths: [otherDir] }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(resolverDir, 'other_path/root.js'));
});
resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) {
if (err) t.fail(err);
t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js'));
});
resolve('root', { basedir: dir }, function (err, res) {
t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
resolve('zzz', { basedir: dir, paths: [otherDir] }, function (err, res) {
t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'");
t.equal(err.code, 'MODULE_NOT_FOUND');
});
});
test('incorrect main', function (t) {
t.plan(1);
var resolverDir = path.join(__dirname, 'resolver');
var dir = path.join(resolverDir, 'incorrect_main');
resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'index.js'));
});
});
test('without basedir', function (t) {
t.plan(1);
var dir = path.join(__dirname, 'resolver/without_basedir');
var tester = require(path.join(dir, 'main.js'));
tester(t, function (err, res, pkg) {
if (err) {
t.fail(err);
} else {
t.equal(res, path.join(dir, 'node_modules/mymodule.js'));
}
});
});
test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {
t.plan(2);
var dir = path.join(__dirname, 'resolver');
resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'same_names/foo.js'));
});
resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'same_names/foo/index.js'));
});
});
test('async: #121 - treating an existing file as a dir when no basedir', function (t) {
var testFile = path.basename(__filename);
t.test('sanity check', function (st) {
st.plan(1);
resolve('./' + testFile, function (err, res, pkg) {
if (err) t.fail(err);
st.equal(res, __filename, 'sanity check');
});
});
t.test('with a fake directory', function (st) {
st.plan(4);
resolve('./' + testFile + '/blah', function (err, res, pkg) {
st.ok(err, 'there is an error');
st.notOk(res, 'no result');
st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
st.equal(
err && err.message,
'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',
'can not find nonexistent module'
);
st.end();
});
});
t.end();
});
test('async dot main', function (t) {
var start = new Date();
t.plan(3);
resolve('./resolver/dot_main', function (err, ret) {
t.notOk(err);
t.equal(ret, path.join(__dirname, 'resolver/dot_main/index.js'));
t.ok(new Date() - start < 50, 'resolve.sync timedout');
t.end();
});
});
test('async dot slash main', function (t) {
var start = new Date();
t.plan(3);
resolve('./resolver/dot_slash_main', function (err, ret) {
t.notOk(err);
t.equal(ret, path.join(__dirname, 'resolver/dot_slash_main/index.js'));
t.ok(new Date() - start < 50, 'resolve.sync timedout');
t.end();
});
});
test('not a directory', function (t) {
t.plan(6);
var path = './foo';
resolve(path, { basedir: __filename }, function (err, res, pkg) {
t.ok(err, 'a non-directory errors');
t.equal(arguments.length, 1);
t.equal(res, undefined);
t.equal(pkg, undefined);
t.equal(err && err.message, 'Cannot find module \'' + path + '\' from \'' + __filename + '\'');
t.equal(err && err.code, 'MODULE_NOT_FOUND');
});
});
test('non-string "main" field in package.json', function (t) {
t.plan(5);
var dir = path.join(__dirname, 'resolver');
resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {
t.ok(err, 'errors on non-string main');
t.equal(err.message, 'package “invalid main” `main` must be a string');
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
t.equal(res, undefined, 'res is undefined');
t.equal(pkg, undefined, 'pkg is undefined');
});
});
test('non-string "main" field in package.json', function (t) {
t.plan(5);
var dir = path.join(__dirname, 'resolver');
resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {
t.ok(err, 'errors on non-string main');
t.equal(err.message, 'package “invalid main” `main` must be a string');
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
t.equal(res, undefined, 'res is undefined');
t.equal(pkg, undefined, 'pkg is undefined');
});
});
test('browser field in package.json', function (t) {
t.plan(3);
var dir = path.join(__dirname, 'resolver');
resolve(
'./browser_field',
{
basedir: dir,
packageFilter: function packageFilter(pkg) {
if (pkg.browser) {
pkg.main = pkg.browser;
delete pkg.browser;
}
return pkg;
}
},
function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'browser_field', 'b.js'));
t.equal(pkg && pkg.main, 'b');
t.equal(pkg && pkg.browser, undefined);
}
);
});

0
node_modules/resolve/test/resolver/baz/doom.js generated vendored Normal file
View file

3
node_modules/resolve/test/resolver/baz/package.json generated vendored Normal file
View file

@ -0,0 +1,3 @@
{
"main": "quux.js"
}

1
node_modules/resolve/test/resolver/baz/quux.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 1;

View file

View file

View file

@ -0,0 +1,5 @@
{
"name": "browser_field",
"main": "a",
"browser": "b"
}

1
node_modules/resolve/test/resolver/cup.coffee generated vendored Normal file
View file

@ -0,0 +1 @@

1
node_modules/resolve/test/resolver/dot_main/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1,3 @@
{
"main": "."
}

View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1,3 @@
{
"main": "./"
}

1
node_modules/resolve/test/resolver/foo.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1,2 @@
// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate
module.exports = 1;

View file

@ -0,0 +1,3 @@
{
"main": "wrong.js"
}

View file

@ -0,0 +1,7 @@
{
"name": "invalid main",
"main": [
"why is this a thing",
"srsly omg wtf"
]
}

0
node_modules/resolve/test/resolver/mug.coffee generated vendored Normal file
View file

0
node_modules/resolve/test/resolver/mug.js generated vendored Normal file
View file

View file

@ -0,0 +1,6 @@
{
"packages": [
"packages/*"
],
"version": "0.0.0"
}

View file

@ -0,0 +1,20 @@
{
"name": "monorepo-symlink-test",
"private": true,
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"postinstall": "lerna bootstrap",
"test": "node packages/package-a"
},
"author": "",
"license": "MIT",
"dependencies": {
"jquery": "^3.3.1",
"resolve": "../../../"
},
"devDependencies": {
"lerna": "^3.4.3"
}
}

View file

@ -0,0 +1,35 @@
'use strict';
var assert = require('assert');
var path = require('path');
var resolve = require('resolve');
var basedir = __dirname + '/node_modules/@my-scope/package-b';
var expected = path.join(__dirname, '../../node_modules/jquery/dist/jquery.js');
/*
* preserveSymlinks === false
* will search NPM package from
* - packages/package-b/node_modules
* - packages/node_modules
* - node_modules
*/
assert.equal(resolve.sync('jquery', { basedir: basedir, preserveSymlinks: false }), expected);
assert.equal(resolve.sync('../../node_modules/jquery', { basedir: basedir, preserveSymlinks: false }), expected);
/*
* preserveSymlinks === true
* will search NPM package from
* - packages/package-a/node_modules/@my-scope/packages/package-b/node_modules
* - packages/package-a/node_modules/@my-scope/packages/node_modules
* - packages/package-a/node_modules/@my-scope/node_modules
* - packages/package-a/node_modules/node_modules
* - packages/package-a/node_modules
* - packages/node_modules
* - node_modules
*/
assert.equal(resolve.sync('jquery', { basedir: basedir, preserveSymlinks: true }), expected);
assert.equal(resolve.sync('../../../../../node_modules/jquery', { basedir: basedir, preserveSymlinks: true }), expected);
console.log(' * all monorepo paths successfully resolved through symlinks');

View file

@ -0,0 +1,14 @@
{
"name": "@my-scope/package-a",
"version": "0.0.0",
"private": true,
"description": "",
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@my-scope/package-b": "^0.0.0"
}
}

View file

@ -0,0 +1,14 @@
{
"name": "@my-scope/package-b",
"private": true,
"version": "0.0.0",
"description": "",
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@my-scope/package-a": "^0.0.0"
}
}

View file

View file

1
node_modules/resolve/test/resolver/quux/foo/index.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 1;

1
node_modules/resolve/test/resolver/same_names/foo.js generated vendored Normal file
View file

@ -0,0 +1 @@
module.exports = 42;

View file

@ -0,0 +1 @@
module.exports = 1;

View file

View file

@ -0,0 +1,5 @@
var resolve = require('../../../');
module.exports = function (t, cb) {
resolve('mymodule', null, cb);
};

329
node_modules/resolve/test/resolver_sync.js generated vendored Normal file
View file

@ -0,0 +1,329 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('foo', function (t) {
var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('./foo', { basedir: dir }),
path.join(dir, 'foo.js')
);
t.equal(
resolve.sync('./foo.js', { basedir: dir }),
path.join(dir, 'foo.js')
);
t.equal(
resolve.sync('./foo.js', { basedir: dir, filename: path.join(dir, 'bar.js') }),
path.join(dir, 'foo.js')
);
t.throws(function () {
resolve.sync('foo', { basedir: dir });
});
// Test that filename is reported as the "from" value when passed.
t.throws(
function () {
resolve.sync('foo', { basedir: dir, filename: path.join(dir, 'bar.js') });
},
{
name: 'Error',
message: "Cannot find module 'foo' from '" + path.join(dir, 'bar.js') + "'"
}
);
t.end();
});
test('bar', function (t) {
var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('foo', { basedir: path.join(dir, 'bar') }),
path.join(dir, 'bar/node_modules/foo/index.js')
);
t.end();
});
test('baz', function (t) {
var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('./baz', { basedir: dir }),
path.join(dir, 'baz/quux.js')
);
t.end();
});
test('biz', function (t) {
var dir = path.join(__dirname, 'resolver/biz/node_modules');
t.equal(
resolve.sync('./grux', { basedir: dir }),
path.join(dir, 'grux/index.js')
);
t.equal(
resolve.sync('tiv', { basedir: path.join(dir, 'grux') }),
path.join(dir, 'tiv/index.js')
);
t.equal(
resolve.sync('grux', { basedir: path.join(dir, 'tiv') }),
path.join(dir, 'grux/index.js')
);
t.end();
});
test('normalize', function (t) {
var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');
t.equal(
resolve.sync('../grux', { basedir: dir }),
path.join(dir, 'index.js')
);
t.end();
});
test('cup', function (t) {
var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('./cup', {
basedir: dir,
extensions: ['.js', '.coffee']
}),
path.join(dir, 'cup.coffee')
);
t.equal(
resolve.sync('./cup.coffee', { basedir: dir }),
path.join(dir, 'cup.coffee')
);
t.throws(function () {
resolve.sync('./cup', {
basedir: dir,
extensions: ['.js']
});
});
t.end();
});
test('mug', function (t) {
var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('./mug', { basedir: dir }),
path.join(dir, 'mug.js')
);
t.equal(
resolve.sync('./mug', {
basedir: dir,
extensions: ['.coffee', '.js']
}),
path.join(dir, 'mug.coffee')
);
t.equal(
resolve.sync('./mug', {
basedir: dir,
extensions: ['.js', '.coffee']
}),
path.join(dir, 'mug.js')
);
t.end();
});
test('other path', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var dir = path.join(resolverDir, 'bar');
var otherDir = path.join(resolverDir, 'other_path');
t.equal(
resolve.sync('root', {
basedir: dir,
paths: [otherDir]
}),
path.join(resolverDir, 'other_path/root.js')
);
t.equal(
resolve.sync('lib/other-lib', {
basedir: dir,
paths: [otherDir]
}),
path.join(resolverDir, 'other_path/lib/other-lib.js')
);
t.throws(function () {
resolve.sync('root', { basedir: dir });
});
t.throws(function () {
resolve.sync('zzz', {
basedir: dir,
paths: [otherDir]
});
});
t.end();
});
test('incorrect main', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var dir = path.join(resolverDir, 'incorrect_main');
t.equal(
resolve.sync('./incorrect_main', { basedir: resolverDir }),
path.join(dir, 'index.js')
);
t.end();
});
var stubStatSync = function stubStatSync(fn) {
var fs = require('fs');
var statSync = fs.statSync;
try {
fs.statSync = function () {
throw new EvalError('Unknown Error');
};
return fn();
} finally {
fs.statSync = statSync;
}
};
test('#79 - re-throw non ENOENT errors from stat', function (t) {
var dir = path.join(__dirname, 'resolver');
stubStatSync(function () {
t.throws(function () {
resolve.sync('foo', { basedir: dir });
}, /Unknown Error/);
});
t.end();
});
test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {
var dir = path.join(__dirname, 'resolver');
t.equal(
resolve.sync('./foo', { basedir: path.join(dir, 'same_names') }),
path.join(dir, 'same_names/foo.js')
);
t.equal(
resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }),
path.join(dir, 'same_names/foo/index.js')
);
t.end();
});
test('sync: #121 - treating an existing file as a dir when no basedir', function (t) {
var testFile = path.basename(__filename);
t.test('sanity check', function (st) {
st.equal(
resolve.sync('./' + testFile),
__filename,
'sanity check'
);
st.end();
});
t.test('with a fake directory', function (st) {
function run() { return resolve.sync('./' + testFile + '/blah'); }
st.throws(run, 'throws an error');
try {
run();
} catch (e) {
st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
st.equal(
e.message,
'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',
'can not find nonexistent module'
);
}
st.end();
});
t.end();
});
test('sync dot main', function (t) {
var start = new Date();
t.equal(resolve.sync('./resolver/dot_main'), path.join(__dirname, 'resolver/dot_main/index.js'));
t.ok(new Date() - start < 50, 'resolve.sync timedout');
t.end();
});
test('sync dot slash main', function (t) {
var start = new Date();
t.equal(resolve.sync('./resolver/dot_slash_main'), path.join(__dirname, 'resolver/dot_slash_main/index.js'));
t.ok(new Date() - start < 50, 'resolve.sync timedout');
t.end();
});
test('not a directory', function (t) {
var path = './foo';
try {
resolve.sync(path, { basedir: __filename });
t.fail();
} catch (err) {
t.ok(err, 'a non-directory errors');
t.equal(err && err.message, 'Cannot find module \'' + path + "' from '" + __filename + "'");
t.equal(err && err.code, 'MODULE_NOT_FOUND');
}
t.end();
});
test('non-string "main" field in package.json', function (t) {
var dir = path.join(__dirname, 'resolver');
try {
var result = resolve.sync('./invalid_main', { basedir: dir });
t.equal(result, undefined, 'result should not exist');
t.fail('should not get here');
} catch (err) {
t.ok(err, 'errors on non-string main');
t.equal(err.message, 'package “invalid main” `main` must be a string');
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
}
t.end();
});
test('non-string "main" field in package.json', function (t) {
var dir = path.join(__dirname, 'resolver');
try {
var result = resolve.sync('./invalid_main', { basedir: dir });
t.equal(result, undefined, 'result should not exist');
t.fail('should not get here');
} catch (err) {
t.ok(err, 'errors on non-string main');
t.equal(err.message, 'package “invalid main” `main` must be a string');
t.equal(err.code, 'INVALID_PACKAGE_MAIN');
}
t.end();
});
test('browser field in package.json', function (t) {
var dir = path.join(__dirname, 'resolver');
var res = resolve.sync('./browser_field', {
basedir: dir,
packageFilter: function packageFilter(pkg) {
if (pkg.browser) {
pkg.main = pkg.browser;
delete pkg.browser;
}
return pkg;
}
});
t.equal(res, path.join(dir, 'browser_field', 'b.js'));
t.end();
});

38
node_modules/resolve/test/shadowed_core.js generated vendored Normal file
View file

@ -0,0 +1,38 @@
var test = require('tape');
var resolve = require('../');
var path = require('path');
test('shadowed core modules still return core module', function (t) {
t.plan(2);
resolve('util', { basedir: path.join(__dirname, 'shadowed_core') }, function (err, res) {
t.ifError(err);
t.equal(res, 'util');
});
});
test('shadowed core modules still return core module [sync]', function (t) {
t.plan(1);
var res = resolve.sync('util', { basedir: path.join(__dirname, 'shadowed_core') });
t.equal(res, 'util');
});
test('shadowed core modules return shadow when appending `/`', function (t) {
t.plan(2);
resolve('util/', { basedir: path.join(__dirname, 'shadowed_core') }, function (err, res) {
t.ifError(err);
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
});
});
test('shadowed core modules return shadow when appending `/` [sync]', function (t) {
t.plan(1);
var res = resolve.sync('util/', { basedir: path.join(__dirname, 'shadowed_core') });
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
});

View file

13
node_modules/resolve/test/subdirs.js generated vendored Normal file
View file

@ -0,0 +1,13 @@
var test = require('tape');
var resolve = require('../');
var path = require('path');
test('subdirs', function (t) {
t.plan(2);
var dir = path.join(__dirname, '/subdirs');
resolve('a/b/c/x.json', { basedir: dir }, function (err, res) {
t.ifError(err);
t.equal(res, path.join(dir, 'node_modules/a/b/c/x.json'));
});
});

56
node_modules/resolve/test/symlinks.js generated vendored Normal file
View file

@ -0,0 +1,56 @@
var path = require('path');
var fs = require('fs');
var test = require('tape');
var resolve = require('../');
var symlinkDir = path.join(__dirname, 'resolver', 'symlinked', 'symlink');
try {
fs.unlinkSync(symlinkDir);
} catch (err) {}
try {
fs.symlinkSync('./_/symlink_target', symlinkDir, 'dir');
} catch (err) {
// if fails then it is probably on Windows and lets try to create a junction
fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction');
}
test('symlink', function (t) {
t.plan(2);
resolve('foo', { basedir: symlinkDir, preserveSymlinks: false }, function (err, res, pkg) {
t.error(err);
t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js'));
});
});
test('sync symlink when preserveSymlinks = true', function (t) {
t.plan(4);
resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) {
t.ok(err, 'there is an error');
t.notOk(res, 'no result');
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
t.equal(
err && err.message,
'Cannot find module \'foo\' from \'' + symlinkDir + '\'',
'can not find nonexistent module'
);
});
});
test('sync symlink', function (t) {
var start = new Date();
t.doesNotThrow(function () {
t.equal(resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: false }), path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js'));
});
t.ok(new Date() - start < 50, 'resolve.sync timedout');
t.end();
});
test('sync symlink when preserveSymlinks = true', function (t) {
t.throws(function () {
resolve.sync('foo', { basedir: symlinkDir });
}, /Cannot find module 'foo'/);
t.end();
});