UEA-PRODEM

This commit is contained in:
2026-06-10 12:14:46 -03:00
parent f54126b9d8
commit 9947565694
5319 changed files with 148520 additions and 129332 deletions
+41 -3
View File
@@ -239,7 +239,7 @@ test('symlinked', function (t) {
});
test('readPackage', function (t) {
t.plan(3);
t.plan(4);
var files = {};
files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep';
@@ -281,14 +281,14 @@ test('readPackage', function (t) {
});
});
var readPackage = function (readFile, file, cb) {
function readPackage(readFile, file, cb) {
var barPackage = path.join('bar', 'package.json');
if (file.slice(-barPackage.length) === barPackage) {
cb(null, { main: './something-else.js' });
} else {
cb(null, JSON.parse(files[path.resolve(file)]));
}
};
}
t.test('with readPackage', function (st) {
st.plan(3);
@@ -312,4 +312,42 @@ test('readPackage', function (t) {
st.throws(function () { throw err; }, TypeError, 'errors when both readFile and readPackage are provided');
});
});
t.test('readPackage error in loadpkg does not invoke callback twice', function (st) {
st.plan(1);
var callCount = 0;
var readPackageError = new Error('read package error');
function failReadPackage(rf, file, cb) {
cb(readPackageError);
}
var relFiles = {};
relFiles[path.resolve('/foo/bar/baz.js')] = 'beep';
relFiles[path.resolve('/foo/bar/package.json')] = '{}';
var relDirs = {};
relDirs[path.resolve('/foo/bar')] = true;
resolve('./baz', {
basedir: path.resolve('/foo/bar'),
isFile: function (file, cb) {
cb(null, Object.prototype.hasOwnProperty.call(relFiles, path.resolve(file)));
},
isDirectory: function (dir, cb) {
cb(null, !!relDirs[path.resolve(dir)]);
},
readPackage: failReadPackage,
realpath: function (file, cb) {
cb(null, file);
}
}, function () {
callCount += 1;
});
setTimeout(function () {
st.equal(callCount, 1, 'callback is invoked exactly once');
}, 50);
});
});
+23 -3
View File
@@ -140,7 +140,7 @@ test('symlinked', function (t) {
});
test('readPackageSync', function (t) {
t.plan(3);
t.plan(4);
var files = {};
files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep';
@@ -179,12 +179,12 @@ test('readPackageSync', function (t) {
);
});
var readPackageSync = function (readFileSync, file) {
function readPackageSync(readFileSync, file) {
if (file.indexOf(path.join('bar', 'package.json')) >= 0) {
return { main: './something-else.js' };
}
return JSON.parse(files[path.resolve(file)]);
};
}
t.test('with readPackage', function (st) {
st.plan(1);
@@ -210,5 +210,25 @@ test('readPackageSync', function (t) {
'errors when both readFile and readPackage are provided'
);
});
t.test('readPackageSync error propagates correctly', function (st) {
st.plan(1);
var readPackageError = new Error('read package error');
function failReadPackageSync() {
throw readPackageError;
}
var options = opts('/foo');
delete options.readFileSync;
options.readPackageSync = failReadPackageSync;
st.throws(
function () { resolve.sync('bar', options); },
readPackageError,
'readPackageSync error is thrown'
);
});
});
+6 -6
View File
@@ -5,7 +5,7 @@ var keys = require('object-keys');
var nodeModulesPaths = require('../lib/node-modules-paths');
var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
function verifyDirs(t, start, dirs, moduleDirectories, paths) {
var moduleDirs = [].concat(moduleDirectories || 'node_modules');
if (paths) {
for (var k = 0; k < paths.length; ++k) {
@@ -33,7 +33,7 @@ var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
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) {
@@ -65,9 +65,9 @@ test('node-modules-paths', function (t) {
});
t.test('with paths=function option', function (t) {
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
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');
@@ -78,9 +78,9 @@ test('node-modules-paths', function (t) {
});
t.test('with paths=function skipping node modules resolution', function (t) {
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
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');
+2 -2
View File
@@ -6,7 +6,7 @@ var resolve = require('../');
test('$NODE_PATH', function (t) {
t.plan(8);
var isDir = function (dir, cb) {
function isDir(dir, cb) {
if (dir === '/node_path' || dir === 'node_path/x') {
return cb(null, true);
}
@@ -17,7 +17,7 @@ test('$NODE_PATH', function (t) {
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
return cb(err);
});
};
}
resolve('aaa', {
paths: [
+2 -2
View File
@@ -4,14 +4,14 @@ var resolve = require('../');
var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
var pathFilterFactory = function (t) {
function pathFilterFactory(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) {
+2 -2
View File
@@ -268,9 +268,9 @@ test('path iterator', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var exactIterator = function (x, start, getPackageCandidates, opts) {
function exactIterator(x, start, getPackageCandidates, opts) {
return [path.join(resolverDir, x)];
};
}
resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) {
if (err) t.fail(err);
+2 -2
View File
@@ -2,7 +2,7 @@ var a = require.resolve('buffer/').replace(process.cwd(), '$CWD');
var b;
var c;
var test = function test() {
function test() {
console.log(a, ': require.resolve, preserveSymlinks ' + (process.execArgv.indexOf('preserve-symlinks') > -1 ? 'true' : 'false'));
console.log(b, ': preserveSymlinks true');
console.log(c, ': preserveSymlinks false');
@@ -11,7 +11,7 @@ var test = function test() {
throw 'async: no match';
}
console.log('async: success! a matched either b or c\n');
};
}
require('resolve')('buffer/', { preserveSymlinks: true }, function (err, result) {
if (err) { throw err; }
+4 -4
View File
@@ -281,9 +281,9 @@ test('other path', function (t) {
test('path iterator', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var exactIterator = function (x, start, getPackageCandidates, opts) {
function exactIterator(x, start, getPackageCandidates, opts) {
return [path.join(resolverDir, x)];
};
}
t.equal(
resolve.sync('baz', { packageIterator: exactIterator }),
@@ -393,7 +393,7 @@ test('main: false', function (t) {
t.end();
});
var stubStatSync = function stubStatSync(fn) {
function stubStatSync(fn) {
var statSync = fs.statSync;
try {
fs.statSync = function () {
@@ -403,7 +403,7 @@ var stubStatSync = function stubStatSync(fn) {
} finally {
fs.statSync = statSync;
}
};
}
test('#79 - re-throw non ENOENT errors from stat', function (t) {
var dir = path.join(__dirname, 'resolver');