From 1580a4fae325cce7ef8059334ce06b0df15a0ddb Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Fri, 28 May 2021 10:02:51 +0200 Subject: [PATCH] test: fix await tests in init/merge --- .../init/__snapshots__/merge.spec.ts.snap | 73 +++++++++++++++---- lib/workers/repository/init/merge.spec.ts | 32 ++++---- 2 files changed, 74 insertions(+), 31 deletions(-) diff --git a/lib/workers/repository/init/__snapshots__/merge.spec.ts.snap b/lib/workers/repository/init/__snapshots__/merge.spec.ts.snap index 8fe8176366..9f136f5d06 100644 --- a/lib/workers/repository/init/__snapshots__/merge.spec.ts.snap +++ b/lib/workers/repository/init/__snapshots__/merge.spec.ts.snap @@ -1,19 +1,62 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`workers/repository/init/merge detectRepoFileConfig() finds .github/renovate.json 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() finds .gitlab/renovate.json 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() finds .renovaterc.json 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() finds and parse renovate.json5 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() returns config if not found 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() returns error if cannot parse 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() throws error if duplicate keys 1`] = `Promise {}`; - -exports[`workers/repository/init/merge detectRepoFileConfig() uses package.json config if found 1`] = `Promise {}`; +exports[`workers/repository/init/merge detectRepoFileConfig() finds .github/renovate.json 1`] = ` +Object { + "configFileName": ".github/renovate.json", + "configFileParsed": Object {}, +} +`; + +exports[`workers/repository/init/merge detectRepoFileConfig() finds .gitlab/renovate.json 1`] = ` +Object { + "configFileName": ".gitlab/renovate.json", + "configFileParsed": Object {}, +} +`; + +exports[`workers/repository/init/merge detectRepoFileConfig() finds .renovaterc.json 1`] = ` +Object { + "configFileName": ".renovaterc.json", + "configFileParsed": Object {}, +} +`; + +exports[`workers/repository/init/merge detectRepoFileConfig() finds and parse renovate.json5 1`] = ` +Object { + "configFileName": "renovate.json5", + "configFileParsed": Object {}, +} +`; + +exports[`workers/repository/init/merge detectRepoFileConfig() returns config if not found 1`] = `Object {}`; + +exports[`workers/repository/init/merge detectRepoFileConfig() returns error if cannot parse 1`] = ` +Object { + "configFileName": "renovate.json", + "configFileParseError": Object { + "validationError": "Invalid JSON (parsing failed)", + "validationMessage": "Syntax error near cannot par", + }, +} +`; + +exports[`workers/repository/init/merge detectRepoFileConfig() throws error if duplicate keys 1`] = ` +Object { + "configFileName": ".renovaterc", + "configFileParseError": Object { + "validationError": "Duplicate keys in JSON", + "validationMessage": "\\"Syntax error: duplicated keys \\\\\\"enabled\\\\\\" near \\\\\\": false }\\"", + }, +} +`; + +exports[`workers/repository/init/merge detectRepoFileConfig() uses package.json config if found 1`] = ` +Object { + "configFileName": "package.json", + "configFileParsed": Object { + "prHourlyLimit": 10, + }, +} +`; exports[`workers/repository/init/merge mergeRenovateConfig() throws error if misconfigured 1`] = `[Error: config-validation]`; diff --git a/lib/workers/repository/init/merge.spec.ts b/lib/workers/repository/init/merge.spec.ts index c55b93d36d..e45fd77aca 100644 --- a/lib/workers/repository/init/merge.spec.ts +++ b/lib/workers/repository/init/merge.spec.ts @@ -33,12 +33,12 @@ jest.mock('../../../config/migrate-validate'); describe(getName(), () => { describe('detectRepoFileConfig()', () => { - it('returns config if not found', () => { + it('returns config if not found', async () => { git.getFileList.mockResolvedValue(['package.json']); fs.readLocalFile.mockResolvedValue('{}'); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('uses package.json config if found', () => { + it('uses package.json config if found', async () => { git.getFileList.mockResolvedValue(['package.json']); const pJson = JSON.stringify({ name: 'something', @@ -47,47 +47,47 @@ describe(getName(), () => { }, }); fs.readLocalFile.mockResolvedValue(pJson); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('returns error if cannot parse', () => { + it('returns error if cannot parse', async () => { git.getFileList.mockResolvedValue(['package.json', 'renovate.json']); fs.readLocalFile.mockResolvedValue('cannot parse'); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('throws error if duplicate keys', () => { + it('throws error if duplicate keys', async () => { git.getFileList.mockResolvedValue(['package.json', '.renovaterc']); fs.readLocalFile.mockResolvedValue( '{ "enabled": true, "enabled": false }' ); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('finds and parse renovate.json5', () => { + it('finds and parse renovate.json5', async () => { git.getFileList.mockResolvedValue(['package.json', 'renovate.json5']); fs.readLocalFile.mockResolvedValue(`{ // this is json5 format }`); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('finds .github/renovate.json', () => { + it('finds .github/renovate.json', async () => { git.getFileList.mockResolvedValue([ 'package.json', '.github/renovate.json', ]); fs.readLocalFile.mockResolvedValue('{}'); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('finds .gitlab/renovate.json', () => { + it('finds .gitlab/renovate.json', async () => { git.getFileList.mockResolvedValue([ 'package.json', '.gitlab/renovate.json', ]); fs.readLocalFile.mockResolvedValue('{}'); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); - it('finds .renovaterc.json', () => { + it('finds .renovaterc.json', async () => { git.getFileList.mockResolvedValue(['package.json', '.renovaterc.json']); fs.readLocalFile.mockResolvedValue('{}'); - expect(detectRepoFileConfig()).toMatchSnapshot(); + expect(await detectRepoFileConfig()).toMatchSnapshot(); }); }); describe('checkForRepoConfigError', () => { -- GitLab