Skip to content
Snippets Groups Projects
Unverified Commit 527c355b authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

refactor: move getRangeStrategy to manager (#2072)

parent b6ee52e7
No related merge requests found
......@@ -44,3 +44,16 @@ for (const f of managerFunctions) {
return null;
};
}
module.exports.getRangeStrategy = config => {
const { manager, rangeStrategy } = config;
if (managers[manager].getRangeStrategy) {
// Use manager's own function if it exists
return managers[manager].getRangeStrategy(config);
}
if (rangeStrategy === 'auto') {
// default to 'replace' for auto
return 'replace';
}
return config.rangeStrategy;
};
const { extractDependencies, postExtract } = require('./extract');
const { updateDependency } = require('./update');
const { getRangeStrategy } = require('./range');
module.exports = {
extractDependencies,
postExtract,
getRangeStrategy,
updateDependency,
supportsLockFileMaintenance: true,
};
const versioning = require('../../../../versioning/semver');
const moment = require('moment');
const { getRollbackUpdate } = require('./rollback');
const { getRangeStrategy } = require('./range');
const { getRangeStrategy } = require('../../../../manager');
const { filterVersions } = require('./filter');
const npmApi = require('../../../../datasource/npm');
const github = require('../../../../datasource/github');
......
const {
getRangeStrategy,
} = require('../../../../../lib/workers/repository/process/lookup/range');
const { getRangeStrategy } = require('../../../lib/manager/npm');
describe('getRangeStrategy', () => {
it('returns same if not auto', () => {
......
const { getRangeStrategy } = require('../../lib/manager');
describe('getRangeStrategy', () => {
it('returns same if not auto', () => {
const config = { manager: 'npm', rangeStrategy: 'widen' };
expect(getRangeStrategy(config)).toEqual('widen');
});
it('returns manager strategy', () => {
const config = {
manager: 'npm',
rangeStrategy: 'auto',
depType: 'dependencies',
packageJsonType: 'app',
};
expect(getRangeStrategy(config)).toEqual('pin');
});
it('defaults to replace', () => {
const config = { manager: 'circleci', rangeStrategy: 'auto' };
expect(getRangeStrategy(config)).toEqual('replace');
});
it('returns rangeStrategy if not auto', () => {
const config = { manager: 'circleci', rangeStrategy: 'future' };
expect(getRangeStrategy(config)).toEqual('future');
});
});
......@@ -15,6 +15,7 @@ let config;
describe('manager/npm/lookup', () => {
beforeEach(() => {
config = { ...require('../../../../../lib/config/defaults').getConfig() };
config.manager = 'npm';
config.rangeStrategy = 'replace';
jest.resetAllMocks();
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment