Skip to content
Snippets Groups Projects
Unverified Commit 5d9eeb03 authored by Wei Kang's avatar Wei Kang Committed by GitHub
Browse files

feat: fatal error config not found (#11462)


* fatal error and exit when config not found

* update file.ts

* fix fatal error and exit only for custom config file

* update test name to be clearer for custom file only

* revert changes for no config file found

* update test name to be clearer

* add space between test as suggested

* fix test due to invalid file

* fix typo

Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
parent 73a6b185
No related merge requests found
// @ts-ignore
module.exports = {};
......@@ -16,11 +16,6 @@ describe('workers/global/config/parse/file', () => {
});
describe('.getConfig()', () => {
it('returns empty env', () => {
expect(file.getConfig({ RENOVATE_CONFIG_FILE: 'dummylocation' })).toEqual(
{}
);
});
it('parses custom config file', () => {
const configFile = upath.resolve(__dirname, './__fixtures__/file.js');
expect(file.getConfig({ RENOVATE_CONFIG_FILE: configFile })).toEqual(
......@@ -33,7 +28,15 @@ describe('workers/global/config/parse/file', () => {
expect(res).toMatchSnapshot();
expect(res.rangeStrategy).toEqual('bump');
});
it('informs user when error in parsing config.js', () => {
it('parse and returns empty config if there is no RENOVATE_CONFIG_FILE in env', () => {
expect(file.getConfig({})).toEqual({});
});
it('fatal error and exit if error in parsing config.js', () => {
const mockProcessExit = jest
.spyOn(process, 'exit')
.mockImplementation(() => undefined as never);
const configFile = upath.resolve(tmp.path, './file3.js');
const fileContent = `module.exports = {
"platform": "github",
......@@ -47,16 +50,21 @@ describe('workers/global/config/parse/file', () => {
"repositories": [ "test/test" ],
};`;
fs.writeFileSync(configFile, fileContent, { encoding: 'utf8' });
expect(
file.getConfig({ RENOVATE_CONFIG_FILE: configFile })
).toStrictEqual({});
file.getConfig({ RENOVATE_CONFIG_FILE: configFile });
expect(mockProcessExit).toHaveBeenCalledWith(1);
fs.unlinkSync(configFile);
});
});
it('handles when invalid file location is provided', () => {
const configFile = upath.resolve(tmp.path, './file4.js');
expect(file.getConfig({ RENOVATE_CONFIG_FILE: configFile })).toStrictEqual(
{}
);
it('fatal error and exit if custom config file does not exist', () => {
const mockProcessExit = jest
.spyOn(process, 'exit')
.mockImplementation(() => undefined as never);
const configFile = upath.resolve(tmp.path, './file4.js');
file.getConfig({ RENOVATE_CONFIG_FILE: configFile });
expect(mockProcessExit).toHaveBeenCalledWith(1);
});
});
});
......@@ -18,9 +18,13 @@ export function getConfig(env: NodeJS.ProcessEnv): AllConfig {
if (err instanceof SyntaxError || err instanceof TypeError) {
logger.fatal(`Could not parse config file \n ${err.stack}`);
process.exit(1);
} else if (env.RENOVATE_CONFIG_FILE) {
logger.fatal('No custom config file found on disk');
process.exit(1);
} else {
// Do nothing
logger.debug('No config file found on disk - skipping');
}
// Do nothing
logger.debug('No config file found on disk - skipping');
}
const { isMigrated, migratedConfig } = migrateConfig(config);
if (isMigrated) {
......
......@@ -18,7 +18,12 @@ describe('workers/global/config/parse/index', () => {
jest.resetModules();
configParser = await import('./index');
defaultArgv = getArgv();
defaultEnv = { RENOVATE_CONFIG_FILE: 'abc' };
defaultEnv = {
RENOVATE_CONFIG_FILE: upath.resolve(
__dirname,
'./__fixtures__/default.js'
),
};
jest.mock('delay', () => Promise.resolve());
});
it('supports token in env', async () => {
......@@ -85,7 +90,7 @@ describe('workers/global/config/parse/index', () => {
expect(parsedConfig).toContainEntries([['privateKey', expected]]);
});
it('supports Bitbucket username/passwod', async () => {
it('supports Bitbucket username/password', async () => {
defaultArgv = defaultArgv.concat([
'--platform=bitbucket',
'--username=user',
......
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