2017-02-09 04:30:00 +00:00
|
|
|
const argv = require('../_fixtures/config/argv');
|
2017-07-01 04:44:41 +00:00
|
|
|
const defaultConfig = require('../../lib/config/defaults').getConfig();
|
2017-01-20 13:03:18 +00:00
|
|
|
|
|
|
|
describe('config/index', () => {
|
|
|
|
describe('.parseConfigs(env, defaultArgv)', () => {
|
2017-02-09 04:30:00 +00:00
|
|
|
let configParser;
|
|
|
|
let defaultArgv;
|
2017-04-21 05:00:26 +00:00
|
|
|
let ghGot;
|
|
|
|
let glGot;
|
2017-06-29 05:29:41 +00:00
|
|
|
let githubApp;
|
2017-02-09 04:30:00 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
configParser = require('../../lib/config/index.js');
|
|
|
|
defaultArgv = argv();
|
2017-04-21 05:00:26 +00:00
|
|
|
jest.mock('gh-got');
|
|
|
|
ghGot = require('gh-got');
|
2017-06-02 20:06:15 +00:00
|
|
|
jest.mock('gl-got');
|
2017-04-21 05:00:26 +00:00
|
|
|
glGot = require('gl-got');
|
2017-06-29 05:29:41 +00:00
|
|
|
jest.mock('../../lib/config/github-app');
|
|
|
|
githubApp = require('../../lib/config/github-app');
|
|
|
|
githubApp.getRepositories = jest.fn();
|
2017-02-09 04:30:00 +00:00
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('throws for invalid platform', async () => {
|
2017-01-20 13:03:18 +00:00
|
|
|
const env = {};
|
2017-04-21 04:43:26 +00:00
|
|
|
defaultArgv.push('--platform=foo');
|
|
|
|
let err;
|
|
|
|
try {
|
2017-04-21 05:00:26 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-04-21 04:43:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
expect(err.message).toBe('Unsupported platform: foo.');
|
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('throws for no GitHub token', async () => {
|
2017-04-21 04:43:26 +00:00
|
|
|
const env = {};
|
|
|
|
let err;
|
|
|
|
try {
|
2017-04-21 05:00:26 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-04-21 04:43:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
expect(err.message).toBe('You need to supply a GitHub token.');
|
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('throws for no GitLab token', async () => {
|
2017-04-21 04:43:26 +00:00
|
|
|
const env = { RENOVATE_PLATFORM: 'gitlab' };
|
|
|
|
let err;
|
|
|
|
try {
|
2017-04-21 05:00:26 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-04-21 04:43:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
expect(err.message).toBe('You need to supply a GitLab token.');
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('supports token in env', async () => {
|
2017-01-20 13:03:18 +00:00
|
|
|
const env = { GITHUB_TOKEN: 'abc' };
|
2017-07-15 04:47:20 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('supports token in CLI options', async () => {
|
2017-02-09 04:30:00 +00:00
|
|
|
defaultArgv = defaultArgv.concat(['--token=abc']);
|
2017-04-21 04:43:26 +00:00
|
|
|
const env = {};
|
2017-07-15 04:47:20 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-06-02 20:06:15 +00:00
|
|
|
it('throws if no GitHub App key defined', async () => {
|
|
|
|
defaultArgv = defaultArgv.concat(['--github-app-id=5']);
|
|
|
|
const env = {};
|
|
|
|
let err;
|
|
|
|
try {
|
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
expect(err.message).toBe('A GitHub App Private Key must be provided');
|
|
|
|
});
|
|
|
|
it('supports github app', async () => {
|
|
|
|
const env = {};
|
|
|
|
defaultArgv = defaultArgv.concat([
|
|
|
|
'--github-app-id=5',
|
|
|
|
'--github-app-key=abc',
|
|
|
|
]);
|
2017-06-29 05:29:41 +00:00
|
|
|
githubApp.getRepositories.mockImplementationOnce(() => {
|
2017-06-02 20:06:15 +00:00
|
|
|
const result = [
|
|
|
|
{
|
|
|
|
repository: 'a/b',
|
|
|
|
token: 'token_a',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(githubApp.getRepositories.mock.calls.length).toBe(1);
|
2017-06-02 20:06:15 +00:00
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('autodiscovers github platform', async () => {
|
|
|
|
const env = {};
|
|
|
|
defaultArgv = defaultArgv.concat(['--autodiscover', '--token=abc']);
|
|
|
|
ghGot.mockImplementationOnce(() => ({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
full_name: 'a/b',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
full_name: 'c/d',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
|
|
|
expect(ghGot.mock.calls.length).toBe(1);
|
|
|
|
expect(glGot.mock.calls.length).toBe(0);
|
|
|
|
});
|
|
|
|
it('autodiscovers gitlab platform', async () => {
|
|
|
|
const env = {};
|
2017-04-21 08:12:41 +00:00
|
|
|
defaultArgv = defaultArgv.concat([
|
|
|
|
'--autodiscover',
|
|
|
|
'--platform=gitlab',
|
|
|
|
'--token=abc',
|
|
|
|
]);
|
2017-04-21 05:00:26 +00:00
|
|
|
glGot.mockImplementationOnce(() => ({
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
path_with_namespace: 'a/b',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
|
|
|
expect(ghGot.mock.calls.length).toBe(0);
|
|
|
|
expect(glGot.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
it('logs if no autodiscovered repositories', async () => {
|
|
|
|
const env = { GITHUB_TOKEN: 'abc' };
|
|
|
|
defaultArgv = defaultArgv.concat(['--autodiscover']);
|
|
|
|
ghGot.mockImplementationOnce(() => ({
|
|
|
|
body: [],
|
|
|
|
}));
|
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
|
|
|
expect(ghGot.mock.calls.length).toBe(1);
|
|
|
|
expect(glGot.mock.calls.length).toBe(0);
|
|
|
|
});
|
2017-06-22 07:03:36 +00:00
|
|
|
it('adds a log file', async () => {
|
|
|
|
const env = { GITHUB_TOKEN: 'abc', RENOVATE_LOG_FILE: 'debug.log' };
|
|
|
|
defaultArgv = defaultArgv.concat(['--autodiscover']);
|
|
|
|
ghGot.mockImplementationOnce(() => ({
|
|
|
|
body: [],
|
|
|
|
}));
|
2017-04-21 05:00:26 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(ghGot.mock.calls.length).toBe(1);
|
|
|
|
expect(glGot.mock.calls.length).toBe(0);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-06-22 07:03:36 +00:00
|
|
|
});
|
2017-07-01 04:44:41 +00:00
|
|
|
describe('mergeChildConfig(parentConfig, childConfig)', () => {
|
|
|
|
it('merges', () => {
|
2017-08-03 06:01:20 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
2017-07-01 04:44:41 +00:00
|
|
|
const childConfig = {
|
|
|
|
foo: 'bar',
|
|
|
|
pinVersions: false,
|
|
|
|
lockFileMaintenance: {
|
2017-08-02 14:14:09 +00:00
|
|
|
schedule: ['on monday'],
|
2017-07-01 04:44:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
const configParser = require('../../lib/config/index.js');
|
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.foo).toEqual('bar');
|
|
|
|
expect(config.pinVersions).toBe(false);
|
2017-08-02 14:14:09 +00:00
|
|
|
expect(config.lockFileMaintenance.schedule).toEqual(['on monday']);
|
2017-07-01 04:44:41 +00:00
|
|
|
expect(config.lockFileMaintenance).toMatchSnapshot();
|
|
|
|
});
|
2017-08-02 12:05:45 +00:00
|
|
|
it('merges depTypes', () => {
|
2017-08-03 06:01:20 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
2017-07-13 20:18:24 +00:00
|
|
|
const childConfig = {
|
2017-08-02 12:05:45 +00:00
|
|
|
dependencies: {},
|
|
|
|
devDependencies: { foo: 1 },
|
|
|
|
peerDependencies: {},
|
2017-07-13 20:18:24 +00:00
|
|
|
};
|
|
|
|
const configParser = require('../../lib/config/index.js');
|
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.depTypes).toMatchSnapshot();
|
|
|
|
});
|
2017-08-06 04:41:45 +00:00
|
|
|
it('merges packageRules', () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
packageRules: [{ a: 1 }, { a: 2 }],
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
packageRules: [{ a: 3 }, { a: 4 }],
|
|
|
|
};
|
|
|
|
const configParser = require('../../lib/config/index.js');
|
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.packageRules.map(rule => rule.a)).toMatchObject([
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
]);
|
|
|
|
});
|
2017-08-07 08:39:32 +00:00
|
|
|
it('skips null parent packageRules', () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
packageRules: null,
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
packageRules: [{ a: 3 }, { a: 4 }],
|
|
|
|
};
|
|
|
|
const configParser = require('../../lib/config/index.js');
|
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.packageRules).toHaveLength(2);
|
|
|
|
});
|
2017-07-01 04:44:41 +00:00
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|