Speed up test suite by using local npm.js stub

This commit is contained in:
Michael Jackson
2019-08-01 18:01:12 -07:00
parent f362fa9717
commit c3dc2dd014
16 changed files with 89 additions and 71 deletions

View File

@ -1,6 +1,8 @@
import semver from 'semver';
import asyncHandler from '../utils/asyncHandler.js';
import createPackageURL from '../utils/createPackageURL.js';
import { getPackageConfig, resolveVersion } from '../utils/npm.js';
import { getPackageConfig, getVersionsAndTags } from '../utils/npm.js';
function semverRedirect(req, res, newVersion) {
res
@ -15,6 +17,24 @@ function semverRedirect(req, res, newVersion) {
);
}
async function resolveVersion(packageName, range) {
const versionsAndTags = await getVersionsAndTags(packageName);
if (versionsAndTags) {
const { versions, tags } = versionsAndTags;
if (range in tags) {
range = tags[range];
}
return versions.includes(range)
? range
: semver.maxSatisfying(versions, range);
}
return null;
}
/**
* Check the package version/tag in the URL and make sure it's good. Also
* fetch the package config and add it to req.packageConfig. Redirect to