Speed up test suite by using local npm.js stub
This commit is contained in:
33
modules/__mocks__/npmMock.js
Normal file
33
modules/__mocks__/npmMock.js
Normal file
@ -0,0 +1,33 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
function getPackageInfo(packageName) {
|
||||
const file = path.resolve(__dirname, `./metadata/${packageName}.json`);
|
||||
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getVersionsAndTags(packageName) {
|
||||
const info = getPackageInfo(packageName);
|
||||
return info
|
||||
? { versions: Object.keys(info.versions), tags: info['dist-tags'] }
|
||||
: [];
|
||||
}
|
||||
|
||||
export function getPackageConfig(packageName, version) {
|
||||
const info = getPackageInfo(packageName);
|
||||
return info ? info.versions[version] : null;
|
||||
}
|
||||
|
||||
export function getPackage(packageName, version) {
|
||||
const file = path.resolve(
|
||||
__dirname,
|
||||
`./packages/${packageName}-${version}.tgz`
|
||||
);
|
||||
|
||||
return fs.existsSync(file) ? fs.createReadStream(file) : null;
|
||||
}
|
Reference in New Issue
Block a user