From 03b0d2a24e72b78e77a2b0e2e383bfa8b86e1251 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh <rahultesnik@gmail.com> Date: Tue, 21 Jun 2022 15:09:30 +0530 Subject: [PATCH] refactor(lib/workers): fix null-check for tests (#16163) Co-authored-by: Michael Kriese <michael.kriese@visualon.de> --- lib/config/migration.ts | 6 +- lib/workers/global/index.spec.ts | 2 +- .../config-migration/branch/index.spec.ts | 2 +- .../config-migration/branch/index.ts | 2 +- .../branch/migrated-data.spec.ts | 13 +- .../config-migration/pr/index.spec.ts | 4 +- .../repository/dependency-dashboard.spec.ts | 4 +- .../repository/errors-warnings.spec.ts | 6 +- .../repository/extract/file-match.spec.ts | 2 +- .../repository/extract/manager-files.ts | 5 +- lib/workers/repository/finalise/prune.ts | 2 +- lib/workers/repository/init/merge.spec.ts | 4 +- lib/workers/repository/init/semantic.spec.ts | 4 +- .../repository/init/vulnerability.spec.ts | 13 +- .../model/semantic-commit-message.spec.ts | 6 +- .../onboarding/branch/index.spec.ts | 10 +- .../repository/onboarding/pr/index.spec.ts | 2 +- lib/workers/repository/process/fetch.spec.ts | 2 +- lib/workers/repository/process/fetch.ts | 2 +- lib/workers/repository/process/limits.spec.ts | 3 +- lib/workers/repository/process/limits.ts | 1 + .../process/vulnerabilities.spec.ts | 4 +- .../update/branch/artifacts.spec.ts | 5 +- .../update/branch/check-existing.spec.ts | 5 +- .../repository/update/branch/commit.spec.ts | 20 ++- .../execute-post-upgrade-commands.spec.ts | 14 +- .../update/branch/get-updated.spec.ts | 26 +-- .../repository/update/branch/index.spec.ts | 160 ++++++++++-------- .../repository/update/branch/reuse.spec.ts | 2 +- .../repository/update/pr/automerge.spec.ts | 9 +- .../update/pr/body/updates-table.spec.ts | 3 +- .../update/pr/changelog/github.spec.ts | 6 +- .../update/pr/changelog/gitlab.spec.ts | 4 +- .../update/pr/changelog/index.spec.ts | 2 +- .../update/pr/changelog/release-notes.spec.ts | 13 +- .../update/pr/changelog/release-notes.ts | 1 + .../repository/update/pr/code-owners.spec.ts | 2 +- .../repository/update/pr/labels.spec.ts | 5 +- .../repository/updates/flatten.spec.ts | 3 +- .../repository/updates/generate.spec.ts | 95 ++++++----- tsconfig.strict.json | 4 +- 41 files changed, 270 insertions(+), 208 deletions(-) diff --git a/lib/config/migration.ts b/lib/config/migration.ts index ac75c9d1db..88cbae7d3e 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -59,7 +59,7 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig { const payload = migrateConfig( packageFile as RenovateConfig ).migratedConfig; - for (const subrule of payload.packageRules || []) { + for (const subrule of payload.packageRules ?? []) { subrule.paths = [(packageFile as any).packageFile]; migratedConfig.packageRules.push(subrule); } @@ -157,7 +157,7 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig { // validated non-null // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion delete migratedConfig.node!.enabled; - migratedConfig.travis = migratedConfig.travis || {}; + migratedConfig.travis = migratedConfig.travis ?? {}; migratedConfig.travis.enabled = true; // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion if (Object.keys(migratedConfig.node!).length) { @@ -259,7 +259,7 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig { } if (is.nonEmptyObject(migratedConfig['gradle-lite'])) { migratedConfig.gradle = mergeChildConfig( - migratedConfig.gradle || {}, + migratedConfig.gradle ?? {}, migratedConfig['gradle-lite'] ); } diff --git a/lib/workers/global/index.spec.ts b/lib/workers/global/index.spec.ts index 348071e1c2..680648a2dc 100644 --- a/lib/workers/global/index.spec.ts +++ b/lib/workers/global/index.spec.ts @@ -176,7 +176,7 @@ describe('workers/global/index', () => { endpoint: 'https://github.com/', writeDiscoveredRepos: '/tmp/renovate-output.json', }); - fs.writeFile.mockReturnValueOnce(null); + fs.writeFile.mockResolvedValueOnce(); expect(await globalWorker.start()).toBe(0); expect(fs.writeFile).toHaveBeenCalledTimes(1); diff --git a/lib/workers/repository/config-migration/branch/index.spec.ts b/lib/workers/repository/config-migration/branch/index.spec.ts index d7b21af6e2..1fed94518b 100644 --- a/lib/workers/repository/config-migration/branch/index.spec.ts +++ b/lib/workers/repository/config-migration/branch/index.spec.ts @@ -20,7 +20,7 @@ jest.mock('./rebase'); jest.mock('./create'); jest.mock('../../../../util/git'); -const migratedData: MigratedData = Fixtures.getJson('./migrated-data.json'); +const migratedData = Fixtures.getJson<MigratedData>('./migrated-data.json'); describe('workers/repository/config-migration/branch/index', () => { describe('checkConfigMigrationBranch', () => { diff --git a/lib/workers/repository/config-migration/branch/index.ts b/lib/workers/repository/config-migration/branch/index.ts index 8e66b83e36..1149201eaa 100644 --- a/lib/workers/repository/config-migration/branch/index.ts +++ b/lib/workers/repository/config-migration/branch/index.ts @@ -10,7 +10,7 @@ import { rebaseMigrationBranch } from './rebase'; export async function checkConfigMigrationBranch( config: RenovateConfig, - migratedConfigData: MigratedData + migratedConfigData: MigratedData | null ): Promise<string | null> { logger.debug('checkConfigMigrationBranch()'); if (!migratedConfigData) { diff --git a/lib/workers/repository/config-migration/branch/migrated-data.spec.ts b/lib/workers/repository/config-migration/branch/migrated-data.spec.ts index e0aee9ab31..0e4074c741 100644 --- a/lib/workers/repository/config-migration/branch/migrated-data.spec.ts +++ b/lib/workers/repository/config-migration/branch/migrated-data.spec.ts @@ -40,7 +40,7 @@ describe('workers/repository/config-migration/branch/migrated-data', () => { it('Calls getAsync a first when migration not needed', async () => { mockedFunction(migrateConfig).mockReturnValueOnce({ isMigrated: false, - migratedConfig: null, + migratedConfig: {}, }); await expect(MigratedDataFactory.getAsync()).resolves.toBeNull(); }); @@ -62,12 +62,12 @@ describe('workers/repository/config-migration/branch/migrated-data', () => { describe('MigratedData class', () => { it('gets the filename from the class instance', async () => { const data = await MigratedDataFactory.getAsync(); - expect(data.filename).toBe('renovate.json'); + expect(data?.filename).toBe('renovate.json'); }); it('gets the content from the class instance', async () => { const data = await MigratedDataFactory.getAsync(); - expect(data.content).toBe(migratedData.content); + expect(data?.content).toBe(migratedData.content); }); }); @@ -80,9 +80,10 @@ describe('workers/repository/config-migration/branch/migrated-data', () => { it('Resets the factory and gets a new value with default indentation', async () => { mockedFunction(detectIndent).mockReturnValueOnce({ - type: null, + type: undefined, amount: 0, - indent: null, + // TODO: incompatible types (#7154) + indent: null as never, }); MigratedDataFactory.reset(); await expect(MigratedDataFactory.getAsync()).resolves.toEqual( @@ -103,7 +104,7 @@ describe('workers/repository/config-migration/branch/migrated-data', () => { it('Returns nothing due to fs error', async () => { mockedFunction(detectRepoFileConfig).mockResolvedValueOnce({ - configFileName: null, + configFileName: undefined, }); mockedFunction(readLocalFile).mockRejectedValueOnce(null); MigratedDataFactory.reset(); diff --git a/lib/workers/repository/config-migration/pr/index.spec.ts b/lib/workers/repository/config-migration/pr/index.spec.ts index 18abc84bb3..fd7c8691c1 100644 --- a/lib/workers/repository/config-migration/pr/index.spec.ts +++ b/lib/workers/repository/config-migration/pr/index.spec.ts @@ -61,7 +61,7 @@ describe('workers/repository/config-migration/pr/index', () => { it('creates PR with default PR title', async () => { await ensureConfigMigrationPr( - { ...config, onboardingPrTitle: null }, + { ...config, onboardingPrTitle: '' }, migratedData ); expect(platform.getBranchPr).toHaveBeenCalledTimes(1); @@ -229,7 +229,7 @@ describe('workers/repository/config-migration/pr/index', () => { }); it('deletes branch when PR already exists but cannot find it', async () => { - err.response.body = { + response.body = { errors: [{ message: 'A pull request already exists' }], }; platform.createPr.mockRejectedValue(err); diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index 0c7d8e61c9..9a51cecdec 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -5,6 +5,7 @@ import { RenovateConfig, getConfig, logger, + mockedFunction, platform, } from '../../../test/util'; import { GlobalConfig } from '../../config/global'; @@ -517,7 +518,8 @@ describe('workers/repository/dependency-dashboard', () => { config.dependencyDashboard = true; config.dependencyDashboardChecks = { branchName2: 'approve-branch' }; config.dependencyDashboardIssue = 1; - platform.getIssue.mockResolvedValueOnce({ + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + mockedFunction(platform.getIssue!).mockResolvedValueOnce({ title: 'Dependency Dashboard', body: `This issue contains a list of Renovate updates and their statuses. diff --git a/lib/workers/repository/errors-warnings.spec.ts b/lib/workers/repository/errors-warnings.spec.ts index b316427391..6442bb8477 100644 --- a/lib/workers/repository/errors-warnings.spec.ts +++ b/lib/workers/repository/errors-warnings.spec.ts @@ -45,7 +45,7 @@ describe('workers/repository/errors-warnings', () => { packageFile: 'package.json', deps: [ { - warnings: [{ message: 'Warning 1', topic: undefined }], + warnings: [{ message: 'Warning 1', topic: '' }], }, {}, ], @@ -54,7 +54,7 @@ describe('workers/repository/errors-warnings', () => { packageFile: 'backend/package.json', deps: [ { - warnings: [{ message: 'Warning 1', topic: undefined }], + warnings: [{ message: 'Warning 1', topic: '' }], }, ], }, @@ -64,7 +64,7 @@ describe('workers/repository/errors-warnings', () => { packageFile: 'Dockerfile', deps: [ { - warnings: [{ message: 'Warning 2', topic: undefined }], + warnings: [{ message: 'Warning 2', topic: '' }], }, ], }, diff --git a/lib/workers/repository/extract/file-match.spec.ts b/lib/workers/repository/extract/file-match.spec.ts index 7137a1233f..40ba83eea6 100644 --- a/lib/workers/repository/extract/file-match.spec.ts +++ b/lib/workers/repository/extract/file-match.spec.ts @@ -64,7 +64,7 @@ describe('workers/repository/extract/file-match', () => { }); it('deduplicates', () => { - config.fileMatch.push('package.json'); + config.fileMatch?.push('package.json'); const res = fileMatch.getMatchingFiles(config, fileList); expect(res).toMatchSnapshot(); expect(res).toHaveLength(2); diff --git a/lib/workers/repository/extract/manager-files.ts b/lib/workers/repository/extract/manager-files.ts index d45d06de85..355c7145a0 100644 --- a/lib/workers/repository/extract/manager-files.ts +++ b/lib/workers/repository/extract/manager-files.ts @@ -11,7 +11,7 @@ import type { WorkerExtractConfig } from '../../types'; export async function getManagerPackageFiles( config: WorkerExtractConfig -): Promise<PackageFile[]> { +): Promise<PackageFile[] | null> { const { enabled, manager, fileList } = config; logger.trace(`getPackageFiles(${manager})`); if (!enabled) { @@ -42,8 +42,7 @@ export async function getManagerPackageFiles( } } } - // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion - return allPackageFiles!; + return allPackageFiles; } const packageFiles: PackageFile[] = []; for (const packageFile of fileList) { diff --git a/lib/workers/repository/finalise/prune.ts b/lib/workers/repository/finalise/prune.ts index edf6b39725..c7327e3a24 100644 --- a/lib/workers/repository/finalise/prune.ts +++ b/lib/workers/repository/finalise/prune.ts @@ -91,7 +91,7 @@ async function cleanUpBranches( export async function pruneStaleBranches( config: RenovateConfig, - branchList: string[] + branchList: string[] | null | undefined ): Promise<void> { logger.debug('Removing any stale branches'); logger.trace({ config }, `pruneStaleBranches`); diff --git a/lib/workers/repository/init/merge.spec.ts b/lib/workers/repository/init/merge.spec.ts index c82dd31040..3086a7eebb 100644 --- a/lib/workers/repository/init/merge.spec.ts +++ b/lib/workers/repository/init/merge.spec.ts @@ -186,14 +186,14 @@ describe('workers/repository/init/merge', () => { migrateAndValidate.migrateAndValidate.mockResolvedValueOnce({ errors: [{ topic: 'dep', message: 'test error' }], }); - let e: Error; + let e: Error | undefined; try { await mergeRenovateConfig(config); } catch (err) { e = err; } expect(e).toBeDefined(); - expect(e.toString()).toBe('Error: config-validation'); + expect(e?.toString()).toBe('Error: config-validation'); }); it('migrates nested config', async () => { diff --git a/lib/workers/repository/init/semantic.spec.ts b/lib/workers/repository/init/semantic.spec.ts index 0abb8dece0..cb2a03ee5e 100644 --- a/lib/workers/repository/init/semantic.spec.ts +++ b/lib/workers/repository/init/semantic.spec.ts @@ -20,7 +20,7 @@ describe('workers/repository/init/semantic', () => { }); it('detects false if unknown', async () => { - config.semanticCommits = null; + config.semanticCommits = undefined; git.getCommitMessages.mockResolvedValueOnce(['foo', 'bar']); git.getCommitMessages.mockResolvedValueOnce([ 'fix: foo', @@ -33,7 +33,7 @@ describe('workers/repository/init/semantic', () => { }); it('detects true if known', async () => { - config.semanticCommits = null; + config.semanticCommits = undefined; git.getCommitMessages.mockResolvedValue(['fix: foo', 'refactor: bar']); const res = await detectSemanticCommits(); expect(res).toBe('enabled'); diff --git a/lib/workers/repository/init/vulnerability.spec.ts b/lib/workers/repository/init/vulnerability.spec.ts index f1f7e627bd..722a012952 100644 --- a/lib/workers/repository/init/vulnerability.spec.ts +++ b/lib/workers/repository/init/vulnerability.spec.ts @@ -23,12 +23,16 @@ describe('workers/repository/init/vulnerability', () => { }); it('returns if alerts are disabled', async () => { - config.vulnerabilityAlerts.enabled = false; + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + config.vulnerabilityAlerts!.enabled = false; expect(await detectVulnerabilityAlerts(config)).toEqual(config); }); it('returns if no alerts', async () => { - delete config.vulnerabilityAlerts.enabled; + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + delete config.vulnerabilityAlerts!.enabled; platform.getVulnerabilityAlerts.mockResolvedValue([]); expect(await detectVulnerabilityAlerts(config)).toEqual(config); }); @@ -43,7 +47,8 @@ describe('workers/repository/init/vulnerability', () => { it('returns alerts and remediations', async () => { config.transitiveRemediation = true; - delete config.vulnerabilityAlerts.enabled; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + delete config.vulnerabilityAlerts!.enabled; platform.getVulnerabilityAlerts.mockResolvedValue([ partial<VulnerabilityAlert>({}), { @@ -73,7 +78,7 @@ describe('workers/repository/init/vulnerability', () => { vulnerableManifestPath: 'backend/package-lock.json', securityAdvisory: { references: [], - severity: null, + severity: '', }, securityVulnerability: { package: { ecosystem: 'NPM', name: 'yargs-parser' }, diff --git a/lib/workers/repository/model/semantic-commit-message.spec.ts b/lib/workers/repository/model/semantic-commit-message.spec.ts index db76829ba5..ffff30f325 100644 --- a/lib/workers/repository/model/semantic-commit-message.spec.ts +++ b/lib/workers/repository/model/semantic-commit-message.spec.ts @@ -29,7 +29,7 @@ describe('workers/repository/model/semantic-commit-message', () => { const instance = SemanticCommitMessage.fromString('feat: ticket 123'); expect(SemanticCommitMessage.is(instance)).toBeTrue(); - expect(instance.toJSON()).toEqual({ + expect(instance?.toJSON()).toEqual({ body: '', footer: '', scope: '', @@ -44,7 +44,7 @@ describe('workers/repository/model/semantic-commit-message', () => { ); expect(SemanticCommitMessage.is(instance)).toBeTrue(); - expect(instance.toJSON()).toEqual({ + expect(instance?.toJSON()).toEqual({ body: '', footer: '', scope: 'dashboard', @@ -57,7 +57,7 @@ describe('workers/repository/model/semantic-commit-message', () => { const instance = SemanticCommitMessage.fromString('fix(deps): '); expect(SemanticCommitMessage.is(instance)).toBeTrue(); - expect(instance.toJSON()).toEqual({ + expect(instance?.toJSON()).toEqual({ body: '', footer: '', scope: 'deps', diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index ad8d1074a7..45a73f45cd 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -77,9 +77,10 @@ describe('workers/repository/onboarding/branch/index', () => { fs.readLocalFile.mockResolvedValue('{}'); await checkOnboardingBranch(config); const file = git.commitFiles.mock.calls[0][0].files[0] as FileAddition; - const contents = file.contents.toString(); + const contents = file.contents?.toString(); expect(contents).toBeJsonString(); - expect(JSON.parse(contents)).toEqual({ + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + expect(JSON.parse(contents!)).toEqual({ $schema: 'https://docs.renovatebot.com/renovate-schema.json', }); }); @@ -110,9 +111,10 @@ describe('workers/repository/onboarding/branch/index', () => { configFileNames[0] ); const file = git.commitFiles.mock.calls[0][0].files[0] as FileAddition; - const contents = file.contents.toString(); + const contents = file.contents?.toString(); expect(contents).toBeJsonString(); - expect(JSON.parse(contents)).toEqual({ + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + expect(JSON.parse(contents!)).toEqual({ $schema: 'https://docs.renovatebot.com/renovate-schema.json', extends: ['some/renovate-config'], }); diff --git a/lib/workers/repository/onboarding/pr/index.spec.ts b/lib/workers/repository/onboarding/pr/index.spec.ts index e1f7872797..97a7026040 100644 --- a/lib/workers/repository/onboarding/pr/index.spec.ts +++ b/lib/workers/repository/onboarding/pr/index.spec.ts @@ -224,7 +224,7 @@ describe('workers/repository/onboarding/pr/index', () => { }); it('deletes branch when PR already exists but cannot find it', async () => { - err.response.body = { + response.body = { errors: [{ message: 'A pull request already exists' }], }; platform.createPr.mockRejectedValueOnce(err); diff --git a/lib/workers/repository/process/fetch.spec.ts b/lib/workers/repository/process/fetch.spec.ts index 4c85f5d86e..284a06c42d 100644 --- a/lib/workers/repository/process/fetch.spec.ts +++ b/lib/workers/repository/process/fetch.spec.ts @@ -80,7 +80,7 @@ describe('workers/repository/process/fetch', () => { { depName: 'abcd' }, { currentValue: '2.8.11', datasource: 'docker' }, { depName: ' ' }, - { depName: null }, + {}, { depName: undefined }, { depName: { oh: 'no' } as unknown as string }, ], diff --git a/lib/workers/repository/process/fetch.ts b/lib/workers/repository/process/fetch.ts index e022f19da3..55905525ea 100644 --- a/lib/workers/repository/process/fetch.ts +++ b/lib/workers/repository/process/fetch.ts @@ -52,7 +52,7 @@ async function fetchDepUpdates( ...(await lookupUpdates(depConfig as LookupUpdateConfig)), }; } - dep.updates = dep.updates || []; + dep.updates = dep.updates ?? []; } return dep; } diff --git a/lib/workers/repository/process/limits.spec.ts b/lib/workers/repository/process/limits.spec.ts index dfccd38352..b5592370f4 100644 --- a/lib/workers/repository/process/limits.spec.ts +++ b/lib/workers/repository/process/limits.spec.ts @@ -130,7 +130,8 @@ describe('workers/repository/process/limits', () => { it('returns prConcurrentLimit if errored', () => { config.branchConcurrentLimit = 2; - const res = limits.getConcurrentBranchesRemaining(config, null); + // TODO: #7154 + const res = limits.getConcurrentBranchesRemaining(config, null as never); expect(res).toBe(2); }); }); diff --git a/lib/workers/repository/process/limits.ts b/lib/workers/repository/process/limits.ts index 3557c05cf4..c26c7d5231 100644 --- a/lib/workers/repository/process/limits.ts +++ b/lib/workers/repository/process/limits.ts @@ -116,6 +116,7 @@ export function getConcurrentBranchesRemaining( return concurrentRemaining; } catch (err) { + // TODO: #7154 should never throw logger.error({ err }, 'Error checking concurrent branches'); return limit; } diff --git a/lib/workers/repository/process/vulnerabilities.spec.ts b/lib/workers/repository/process/vulnerabilities.spec.ts index 428c4f86f8..c87f780aee 100644 --- a/lib/workers/repository/process/vulnerabilities.spec.ts +++ b/lib/workers/repository/process/vulnerabilities.spec.ts @@ -12,7 +12,9 @@ jest.mock('@jamiemagee/osv-offline', () => { return { __esModule: true, OsvOffline: class { - static create = () => createMock(); + static create() { + return createMock(); + } }, }; }); diff --git a/lib/workers/repository/update/branch/artifacts.spec.ts b/lib/workers/repository/update/branch/artifacts.spec.ts index efbff23b66..2a0e942dfe 100644 --- a/lib/workers/repository/update/branch/artifacts.spec.ts +++ b/lib/workers/repository/update/branch/artifacts.spec.ts @@ -10,13 +10,14 @@ describe('workers/repository/update/branch/artifacts', () => { beforeEach(() => { GlobalConfig.set({}); jest.resetAllMocks(); + // TODO #7154 incompatible types config = { ...getConfig(), manager: 'some-manager', branchName: 'renovate/pin', upgrades: [], artifactErrors: [{ lockFile: 'some' }], - }; + } as BranchConfig; }); describe('setArtifactsErrorStatus', () => { @@ -41,7 +42,7 @@ describe('workers/repository/update/branch/artifacts', () => { it('skips status (no errors)', async () => { platform.getBranchStatusCheck.mockResolvedValueOnce(null); - config.artifactErrors.length = 0; + config.artifactErrors = []; await setArtifactErrorStatus(config); expect(platform.setBranchStatus).not.toHaveBeenCalled(); }); diff --git a/lib/workers/repository/update/branch/check-existing.spec.ts b/lib/workers/repository/update/branch/check-existing.spec.ts index 213fe459fd..e5ff1625d4 100644 --- a/lib/workers/repository/update/branch/check-existing.spec.ts +++ b/lib/workers/repository/update/branch/check-existing.spec.ts @@ -10,11 +10,12 @@ describe('workers/repository/update/branch/check-existing', () => { let config: BranchConfig; beforeEach(() => { - config = partial<BranchConfig>({ + // TODO #7154 incompatible types + config = { ...defaultConfig, branchName: 'some-branch', prTitle: 'some-title', - }); + } as BranchConfig; jest.resetAllMocks(); }); diff --git a/lib/workers/repository/update/branch/commit.spec.ts b/lib/workers/repository/update/branch/commit.spec.ts index e3cf9fff0c..47df38f4bb 100644 --- a/lib/workers/repository/update/branch/commit.spec.ts +++ b/lib/workers/repository/update/branch/commit.spec.ts @@ -1,7 +1,7 @@ import { defaultConfig, git, - partial, + mockedFunction, platform, } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; @@ -15,7 +15,8 @@ describe('workers/repository/update/branch/commit', () => { let config: BranchConfig; beforeEach(() => { - config = partial<BranchConfig>({ + // TODO #7154 incompatible types + config = { ...defaultConfig, branchName: 'renovate/some-branch', commitMessage: 'some commit message', @@ -24,7 +25,8 @@ describe('workers/repository/update/branch/commit', () => { semanticCommitScope: 'b', updatedPackageFiles: [], updatedArtifacts: [], - }); + upgrades: [], + } as BranchConfig; jest.resetAllMocks(); git.commitFiles.mockResolvedValueOnce('123test'); platform.commitFiles = jest.fn(); @@ -37,7 +39,7 @@ describe('workers/repository/update/branch/commit', () => { }); it('commits files', async () => { - config.updatedPackageFiles.push({ + config.updatedPackageFiles?.push({ type: 'addition', path: 'package.json', contents: 'some contents', @@ -48,7 +50,7 @@ describe('workers/repository/update/branch/commit', () => { }); it('commits via platform', async () => { - config.updatedPackageFiles.push({ + config.updatedPackageFiles?.push({ type: 'addition', path: 'package.json', contents: 'some contents', @@ -56,12 +58,16 @@ describe('workers/repository/update/branch/commit', () => { config.platformCommit = true; await commitFilesToBranch(config); expect(platform.commitFiles).toHaveBeenCalledTimes(1); - expect(platform.commitFiles.mock.calls).toMatchSnapshot(); + // TODO #7154 + expect( + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + mockedFunction(platform.commitFiles!).mock.calls + ).toMatchSnapshot(); }); it('dry runs', async () => { GlobalConfig.set({ dryRun: 'full' }); - config.updatedPackageFiles.push({ + config.updatedPackageFiles?.push({ type: 'addition', path: 'package.json', contents: 'some contents', diff --git a/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts b/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts index 00a12a45ce..0e29fd3e1f 100644 --- a/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts +++ b/lib/workers/repository/update/branch/execute-post-upgrade-commands.spec.ts @@ -1,4 +1,4 @@ -import { fs, git } from '../../../../../test/util'; +import { fs, git, partial } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { StatusResult } from '../../../../util/git/types'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; @@ -31,11 +31,13 @@ describe('workers/repository/update/branch/execute-post-upgrade-commands', () => upgrades: [], branchName: 'main', }; - git.getRepoStatus.mockResolvedValueOnce({ - modified: [], - not_added: [], - deleted: [], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: [], + not_added: [], + deleted: [], + }) + ); GlobalConfig.set({ localDir: __dirname, allowedPostUpgradeCommands: ['some-command'], diff --git a/lib/workers/repository/update/branch/get-updated.spec.ts b/lib/workers/repository/update/branch/get-updated.spec.ts index 509f510004..3431b67353 100644 --- a/lib/workers/repository/update/branch/get-updated.spec.ts +++ b/lib/workers/repository/update/branch/get-updated.spec.ts @@ -41,7 +41,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.upgrades.push({ packageFile: 'index.html', manager: 'html', - branchName: undefined, + branchName: '', }); autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file'); const res = await getUpdatedPackageFiles(config); @@ -56,7 +56,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.upgrades.push({ packageFile: 'index.html', manager: 'html', - branchName: undefined, + branchName: '', }); autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); const res = await getUpdatedPackageFiles(config); @@ -69,7 +69,7 @@ describe('workers/repository/update/branch/get-updated', () => { }); it('handles autoreplace failure', async () => { - config.upgrades.push({ manager: 'html', branchName: undefined }); + config.upgrades.push({ manager: 'html', branchName: '' }); autoReplace.doAutoReplace.mockResolvedValueOnce(null); await expect(getUpdatedPackageFiles(config)).rejects.toThrow(); }); @@ -79,7 +79,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.upgrades.push({ packageFile: 'index.html', manager: 'html', - branchName: undefined, + branchName: '', }); autoReplace.doAutoReplace.mockResolvedValueOnce(null); autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file'); @@ -133,7 +133,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.upgrades.push({ packageFile: 'composer.json', manager: 'composer', - branchName: undefined, + branchName: '', }); autoReplace.doAutoReplace.mockResolvedValueOnce('some new content'); composer.updateArtifacts.mockResolvedValueOnce([ @@ -278,7 +278,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.reuseExistingBranch = true; config.upgrades.push({ manager: 'composer', - branchName: undefined, + branchName: '', }); autoReplace.doAutoReplace.mockResolvedValueOnce('some new content'); composer.updateArtifacts.mockResolvedValueOnce([ @@ -318,7 +318,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.upgrades.push({ packageFile: 'composer.json', manager: 'composer', - branchName: undefined, + branchName: '', isLockfileUpdate: true, }); composer.updateLockedDependency.mockReturnValueOnce({ @@ -356,7 +356,7 @@ describe('workers/repository/update/branch/get-updated', () => { config.upgrades.push({ packageFile: 'abc.tf', manager: 'terraform', - branchName: undefined, + branchName: '', isLockfileUpdate: true, }); terraform.updateArtifacts.mockResolvedValueOnce([ @@ -392,7 +392,7 @@ describe('workers/repository/update/branch/get-updated', () => { packageFile: 'package.json', lockFiles: ['package-lock.json'], manager: 'npm', - branchName: undefined, + branchName: '', isLockfileUpdate: true, }); npm.updateLockedDependency.mockResolvedValue({ @@ -415,7 +415,7 @@ describe('workers/repository/update/branch/get-updated', () => { packageFile: 'package.json', lockFile: 'package-lock.json', manager: 'npm', - branchName: undefined, + branchName: '', isLockfileUpdate: true, }); npm.updateLockedDependency.mockResolvedValueOnce({ @@ -438,7 +438,7 @@ describe('workers/repository/update/branch/get-updated', () => { packageFile: 'package.json', lockFile: 'package-lock.json', manager: 'npm', - branchName: undefined, + branchName: '', isLockfileUpdate: true, }); git.getFile.mockResolvedValue('some content'); @@ -460,7 +460,7 @@ describe('workers/repository/update/branch/get-updated', () => { it('bumps versions in updateDependency managers', async () => { config.upgrades.push({ packageFile: 'package.json', - branchName: undefined, + branchName: '', bumpVersion: 'patch', manager: 'npm', }); @@ -481,7 +481,7 @@ describe('workers/repository/update/branch/get-updated', () => { it('bumps versions in autoReplace managers', async () => { config.upgrades.push({ packageFile: 'Chart.yaml', - branchName: undefined, + branchName: '', bumpVersion: 'patch', manager: 'helmv3', }); diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index bf65bf8d4f..9bce40e433 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -69,9 +69,12 @@ const limits = mocked(_limits); const adminConfig: RepoGlobalConfig = { localDir: '', cacheDir: '' }; -function findFileContent(files: FileChange[], path: string): string | null { - const f = files.find((file) => file.path === path); - if (f.type === 'addition') { +function findFileContent( + files: FileChange[] | undefined, + path: string +): string | null { + const f = files?.find((file) => file.path === path); + if (f?.type === 'addition' && f.contents) { return f.contents.toString(); } return null; @@ -95,7 +98,7 @@ describe('workers/repository/update/branch/index', () => { branchName: 'renovate/some-branch', errors: [], warnings: [], - upgrades: [{ depName: 'some-dep-name' }], + upgrades: [{ depName: 'some-dep-name' }] as BranchUpgradeConfig[], } as BranchConfig; schedule.isScheduledNow.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValue('123test'); @@ -471,7 +474,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -487,7 +490,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(false); automerge.tryBranchAutomerge.mockResolvedValueOnce('automerged'); @@ -505,7 +508,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -523,7 +526,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -546,7 +549,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -569,7 +572,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -592,7 +595,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -615,7 +618,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); commit.commitFilesToBranch.mockResolvedValueOnce(null); @@ -638,7 +641,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); expect( await branchWorker.processBranch({ @@ -662,7 +665,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); automerge.tryBranchAutomerge.mockResolvedValueOnce('failed'); @@ -684,7 +687,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); automerge.tryBranchAutomerge.mockResolvedValueOnce('stale'); @@ -885,7 +888,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); automerge.tryBranchAutomerge.mockResolvedValueOnce('failed'); @@ -934,7 +937,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); platform.getBranchPr.mockResolvedValueOnce({ @@ -970,7 +973,7 @@ describe('workers/repository/update/branch/index', () => { } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); platform.getBranchPr.mockResolvedValueOnce({ @@ -1002,13 +1005,16 @@ describe('workers/repository/update/branch/index', () => { }); it('branch pr no schedule', async () => { - getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ - updatedPackageFiles: [{}], - artifactErrors: [], - } as PackageFilesResult); + getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce( + partial<PackageFilesResult>({ + updatedPackageFiles: [partial<FileChange>({})], + artifactErrors: [], + updatedArtifacts: [], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); platform.getBranchPr.mockResolvedValueOnce({ @@ -1037,13 +1043,16 @@ describe('workers/repository/update/branch/index', () => { }); it('skips branch update if stopUpdatingLabel presents', async () => { - getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ - updatedPackageFiles: [{}], - artifactErrors: [], - } as PackageFilesResult); + getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce( + partial<PackageFilesResult>({ + updatedPackageFiles: [partial<FileChange>({})], + artifactErrors: [], + updatedArtifacts: [], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); platform.getBranchPr.mockResolvedValueOnce({ @@ -1072,13 +1081,16 @@ describe('workers/repository/update/branch/index', () => { }); it('updates branch if stopUpdatingLabel presents and PR rebase/retry box checked', async () => { - getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ - updatedPackageFiles: [{}], - artifactErrors: [], - } as PackageFilesResult); + getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce( + partial<PackageFilesResult>({ + updatedPackageFiles: [partial<FileChange>({})], + artifactErrors: [], + updatedArtifacts: [], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], - updatedArtifacts: [{}], + updatedArtifacts: [partial<FileChange>({})], } as WriteExistingFilesResult); git.branchExists.mockReturnValue(true); platform.getBranchPr.mockResolvedValueOnce({ @@ -1118,6 +1130,7 @@ describe('workers/repository/update/branch/index', () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ updatedPackageFiles: [updatedPackageFile], artifactErrors: [], + updatedArtifacts: [], } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], @@ -1139,11 +1152,13 @@ describe('workers/repository/update/branch/index', () => { }, } as Pr); git.isBranchModified.mockResolvedValueOnce(true); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['modified_file'], - not_added: [], - deleted: ['deleted_file'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['modified_file'], + not_added: [], + deleted: ['deleted_file'], + }) + ); fs.readLocalFile.mockResolvedValueOnce('modified file content'); fs.localPathExists .mockResolvedValueOnce(true) @@ -1228,11 +1243,13 @@ describe('workers/repository/update/branch/index', () => { }, } as never); git.isBranchModified.mockResolvedValueOnce(true); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['modified_file'], - not_added: [], - deleted: ['deleted_file'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['modified_file'], + not_added: [], + deleted: ['deleted_file'], + }) + ); fs.readLocalFile.mockResolvedValueOnce('modified file content'); fs.localPathExists @@ -1287,6 +1304,7 @@ describe('workers/repository/update/branch/index', () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ updatedPackageFiles: [updatedPackageFile], artifactErrors: [], + updatedArtifacts: [], } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], @@ -1308,11 +1326,13 @@ describe('workers/repository/update/branch/index', () => { }, } as Pr); git.isBranchModified.mockResolvedValueOnce(true); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['modified_file'], - not_added: [], - deleted: ['deleted_file'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['modified_file'], + not_added: [], + deleted: ['deleted_file'], + }) + ); fs.readLocalFile.mockResolvedValueOnce('modified file content'); fs.localPathExists @@ -1370,6 +1390,7 @@ describe('workers/repository/update/branch/index', () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ updatedPackageFiles: [updatedPackageFile], artifactErrors: [], + updatedArtifacts: [], } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], @@ -1392,16 +1413,20 @@ describe('workers/repository/update/branch/index', () => { } as Pr); git.isBranchModified.mockResolvedValueOnce(true); git.getRepoStatus - .mockResolvedValueOnce({ - modified: ['modified_file', 'modified_then_deleted_file'], - not_added: [], - deleted: ['deleted_file', 'deleted_then_created_file'], - } as StatusResult) - .mockResolvedValueOnce({ - modified: ['modified_file', 'deleted_then_created_file'], - not_added: [], - deleted: ['deleted_file', 'modified_then_deleted_file'], - } as StatusResult); + .mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['modified_file', 'modified_then_deleted_file'], + not_added: [], + deleted: ['deleted_file', 'deleted_then_created_file'], + }) + ) + .mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['modified_file', 'deleted_then_created_file'], + not_added: [], + deleted: ['deleted_file', 'modified_then_deleted_file'], + }) + ); fs.readLocalFile .mockResolvedValueOnce('modified file content' as never) @@ -1491,18 +1516,18 @@ describe('workers/repository/update/branch/index', () => { findFileContent(updatedArtifacts, 'deleted_then_created_file') ).toBe('this file was once deleted'); expect( - updatedArtifacts.find( + updatedArtifacts?.find( (f) => f.type === 'deletion' && f.path === 'deleted_then_created_file' ) ).toBeUndefined(); expect( - updatedArtifacts.find( + updatedArtifacts?.find( (f) => f.type === 'addition' && f.path === 'modified_then_deleted_file' ) ).toBeUndefined(); expect( - updatedArtifacts.find( + updatedArtifacts?.find( (f) => f.type === 'deletion' && f.path === 'modified_then_deleted_file' ) @@ -1518,6 +1543,7 @@ describe('workers/repository/update/branch/index', () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ updatedPackageFiles: [updatedPackageFile], artifactErrors: [], + updatedArtifacts: [], } as PackageFilesResult); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], @@ -1539,11 +1565,13 @@ describe('workers/repository/update/branch/index', () => { }, } as Pr); git.isBranchModified.mockResolvedValueOnce(true); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['modified_file', 'modified_then_deleted_file'], - not_added: [], - deleted: ['deleted_file', 'deleted_then_created_file'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['modified_file', 'modified_then_deleted_file'], + not_added: [], + deleted: ['deleted_file', 'deleted_then_created_file'], + }) + ); fs.readLocalFile .mockResolvedValueOnce('modified file content') diff --git a/lib/workers/repository/update/branch/reuse.spec.ts b/lib/workers/repository/update/branch/reuse.spec.ts index 63d540061c..1945f185b4 100644 --- a/lib/workers/repository/update/branch/reuse.spec.ts +++ b/lib/workers/repository/update/branch/reuse.spec.ts @@ -35,7 +35,7 @@ describe('workers/repository/update/branch/reuse', () => { it('returns true if no PR', async () => { git.branchExists.mockReturnValueOnce(true); - platform.getBranchPr.mockReturnValue(null); + platform.getBranchPr.mockResolvedValue(null); const res = await shouldReuseExistingBranch(config); expect(res.reuseExistingBranch).toBeTrue(); }); diff --git a/lib/workers/repository/update/pr/automerge.spec.ts b/lib/workers/repository/update/pr/automerge.spec.ts index 8017691b65..f8ca6da2c4 100644 --- a/lib/workers/repository/update/pr/automerge.spec.ts +++ b/lib/workers/repository/update/pr/automerge.spec.ts @@ -8,8 +8,6 @@ import * as prAutomerge from './automerge'; jest.mock('../../../../util/git'); -const defaultConfig = getConfig(); - describe('workers/repository/update/pr/automerge', () => { describe('checkAutoMerge(pr, config)', () => { const spy = jest.spyOn(schedule, 'isScheduledNow'); @@ -17,9 +15,10 @@ describe('workers/repository/update/pr/automerge', () => { let pr: Pr; beforeEach(() => { - config = partial<BranchConfig>({ - ...defaultConfig, - }); + // TODO #7154 incompatible types + config = { + ...getConfig(), + } as BranchConfig; pr = partial<Pr>({}); }); diff --git a/lib/workers/repository/update/pr/body/updates-table.spec.ts b/lib/workers/repository/update/pr/body/updates-table.spec.ts index f2ee613cfb..82715c4b16 100644 --- a/lib/workers/repository/update/pr/body/updates-table.spec.ts +++ b/lib/workers/repository/update/pr/body/updates-table.spec.ts @@ -85,7 +85,8 @@ describe('workers/repository/update/pr/body/updates-table', () => { displayFrom: '^6.2.3', displayTo: '6.2.3', }; - const upgrade3: BranchUpgradeConfig = undefined; + // TODO #7154 allow or filter undefined + const upgrade3 = undefined as never; const configObj: BranchConfig = { manager: 'some-manager', branchName: 'some-branch', diff --git a/lib/workers/repository/update/pr/changelog/github.spec.ts b/lib/workers/repository/update/pr/changelog/github.spec.ts index 313d4d55d2..cb5ab72dc5 100644 --- a/lib/workers/repository/update/pr/changelog/github.spec.ts +++ b/lib/workers/repository/update/pr/changelog/github.spec.ts @@ -11,7 +11,7 @@ jest.mock('../../../../../modules/datasource/npm'); const upgrade: BranchUpgradeConfig = { manager: 'some-manager', - branchName: undefined, + branchName: '', depName: 'renovate', endpoint: 'https://api.github.com/', versioning: semverVersioning.id, @@ -53,7 +53,7 @@ describe('workers/repository/update/pr/changelog/github', () => { expect( await getChangeLogJSON({ ...upgrade, - currentVersion: null, + currentVersion: undefined, }) ).toBeNull(); }); @@ -313,7 +313,7 @@ describe('workers/repository/update/pr/changelog/github', () => { const upgradeData: BranchUpgradeConfig = { manager: 'some-manager', - branchName: undefined, + branchName: '', depName: 'correctPrefix/target', endpoint: 'https://api.github.com/', versioning: 'npm', diff --git a/lib/workers/repository/update/pr/changelog/gitlab.spec.ts b/lib/workers/repository/update/pr/changelog/gitlab.spec.ts index f8b7e89cde..0e27e9f651 100644 --- a/lib/workers/repository/update/pr/changelog/gitlab.spec.ts +++ b/lib/workers/repository/update/pr/changelog/gitlab.spec.ts @@ -9,7 +9,7 @@ jest.mock('../../../../../modules/datasource/npm'); const upgrade: BranchUpgradeConfig = { manager: 'some-manager', - branchName: undefined, + branchName: '', endpoint: 'https://gitlab.com/api/v4/ ', depName: 'renovate', versioning: semverVersioning.id, @@ -51,7 +51,7 @@ describe('workers/repository/update/pr/changelog/gitlab', () => { expect( await getChangeLogJSON({ ...upgrade, - currentVersion: null, + currentVersion: undefined, }) ).toBeNull(); }); diff --git a/lib/workers/repository/update/pr/changelog/index.spec.ts b/lib/workers/repository/update/pr/changelog/index.spec.ts index 570c613e9c..f9e1cb1b0d 100644 --- a/lib/workers/repository/update/pr/changelog/index.spec.ts +++ b/lib/workers/repository/update/pr/changelog/index.spec.ts @@ -59,7 +59,7 @@ describe('workers/repository/update/pr/changelog/index', () => { expect( await getChangeLogJSON({ ...upgrade, - currentVersion: null, + currentVersion: undefined, }) ).toBeNull(); }); diff --git a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts index 9580a00edb..661f58796f 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -98,7 +98,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { expect( await addReleaseNotes(input as never, {} as BranchUpgradeConfig) ).toEqual(input); - expect(await addReleaseNotes(null, {} as BranchUpgradeConfig)).toBeNull(); + // TODO #7154 + expect( + await addReleaseNotes(null as never, {} as BranchUpgradeConfig) + ).toBeNull(); expect( await addReleaseNotes( { versions: [] } as never, @@ -974,7 +977,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { gitRef: '15.3.0', } as ChangeLogRelease ); - versionOneNotes = res; + versionOneNotes = res!; expect(res).toMatchSnapshot({ notesSourceUrl: @@ -1004,7 +1007,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { gitRef: '15.2.0', } as ChangeLogRelease ); - versionTwoNotes = res; + versionTwoNotes = res!; expect(res).toMatchSnapshot({ notesSourceUrl: @@ -1034,7 +1037,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { gitRef: '4.33.0', } as ChangeLogRelease ); - versionTwoNotes = res; + versionTwoNotes = res!; expect(res).toMatchSnapshot({ notesSourceUrl: @@ -1070,7 +1073,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { gitRef: '4.33.0', } as ChangeLogRelease ); - versionTwoNotes = res; + versionTwoNotes = res!; expect(res).toMatchSnapshot({ notesSourceUrl: diff --git a/lib/workers/repository/update/pr/changelog/release-notes.ts b/lib/workers/repository/update/pr/changelog/release-notes.ts index 8a94dec41c..efc52019bf 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.ts @@ -374,6 +374,7 @@ export function releaseNotesCacheMinutes(releaseDate?: string | Date): number { return 14495; // 5 minutes shy of 10 days } +// TODO #7154 allow `null` and `undefined` export async function addReleaseNotes( input: ChangeLogResult, config: BranchUpgradeConfig diff --git a/lib/workers/repository/update/pr/code-owners.spec.ts b/lib/workers/repository/update/pr/code-owners.spec.ts index fdf8644b7f..f3639b9ed1 100644 --- a/lib/workers/repository/update/pr/code-owners.spec.ts +++ b/lib/workers/repository/update/pr/code-owners.spec.ts @@ -82,7 +82,7 @@ describe('workers/repository/update/pr/code-owners', () => { if (path === codeOwnerFilePath) { return Promise.resolve(['* @mike'].join('\n')); } - return Promise.resolve<string>(null); + return Promise.resolve(null); }); git.getBranchFiles.mockResolvedValueOnce(['README.md']); const codeOwners = await codeOwnersForPr(pr); diff --git a/lib/workers/repository/update/pr/labels.spec.ts b/lib/workers/repository/update/pr/labels.spec.ts index 60f5f8d315..f3f16a8cc9 100644 --- a/lib/workers/repository/update/pr/labels.spec.ts +++ b/lib/workers/repository/update/pr/labels.spec.ts @@ -49,11 +49,12 @@ describe('workers/repository/update/pr/labels', () => { }); it('null labels ignored', () => { + // TODO #7154 const result = prepareLabels({ - labels: ['labelA', null], + labels: ['labelA', null] as never, // an empty space between two commas in an array is categorized as a null value // eslint-disable-next-line no-sparse-arrays - addLabels: ['labelB', '', undefined, , ,], + addLabels: ['labelB', '', undefined, , ,] as never, }); expect(result).toBeArrayOfSize(2); expect(result).toEqual(['labelA', 'labelB']); diff --git a/lib/workers/repository/updates/flatten.spec.ts b/lib/workers/repository/updates/flatten.spec.ts index ce5df4f5a7..c3f987abaf 100644 --- a/lib/workers/repository/updates/flatten.spec.ts +++ b/lib/workers/repository/updates/flatten.spec.ts @@ -15,7 +15,8 @@ beforeEach(() => { describe('workers/repository/updates/flatten', () => { describe('flattenUpdates()', () => { it('flattens', async () => { - config.lockFileMaintenance.enabled = true; + // TODO #7154 + config.lockFileMaintenance!.enabled = true; config.packageRules = [ { matchUpdateTypes: ['minor'], diff --git a/lib/workers/repository/updates/generate.spec.ts b/lib/workers/repository/updates/generate.spec.ts index 25ded12546..a6fa8195bf 100644 --- a/lib/workers/repository/updates/generate.spec.ts +++ b/lib/workers/repository/updates/generate.spec.ts @@ -1,7 +1,6 @@ -import { defaultConfig, partial } from '../../../../test/util'; +import { defaultConfig } from '../../../../test/util'; import type { UpdateType } from '../../../config/types'; import { NpmDatasource } from '../../../modules/datasource/npm'; -import type { LookupUpdate } from '../../../modules/manager/types'; import type { BranchUpgradeConfig } from '../../types'; import { generateBranchConfig } from './generate'; @@ -12,7 +11,7 @@ beforeEach(() => { describe('workers/repository/updates/generate', () => { describe('generateBranchConfig()', () => { it('does not group single upgrade', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', @@ -33,7 +32,7 @@ describe('workers/repository/updates/generate', () => { }); it('handles lockFileMaintenance', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', branchName: 'some-branch', @@ -57,7 +56,7 @@ describe('workers/repository/updates/generate', () => { }); it('handles lockFileUpdate', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', branchName: 'some-branch', @@ -97,7 +96,7 @@ describe('workers/repository/updates/generate', () => { }); it('does not group same upgrades', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', @@ -127,7 +126,7 @@ describe('workers/repository/updates/generate', () => { }); it('groups multiple upgrades same version', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', @@ -199,7 +198,7 @@ describe('workers/repository/updates/generate', () => { }); it('groups major updates with different versions but same newValue, no recreateClosed', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', @@ -235,7 +234,7 @@ describe('workers/repository/updates/generate', () => { }); it('groups multiple upgrades different version', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'depB', @@ -278,7 +277,7 @@ describe('workers/repository/updates/generate', () => { }); it('groups multiple upgrades different version but same value', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'depB', @@ -321,7 +320,7 @@ describe('workers/repository/updates/generate', () => { }); it('groups multiple upgrades different value but same version', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'depB', @@ -364,7 +363,7 @@ describe('workers/repository/updates/generate', () => { }); it('groups multiple digest updates', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'foo/bar', @@ -404,15 +403,16 @@ describe('workers/repository/updates/generate', () => { }); it('pins digest to table', () => { - const branch = [ - partial<LookupUpdate & BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, depName: 'foo-image', newDigest: 'abcdefg987612345', currentDigest: '', updateType: 'pinDigest', isPinDigest: true, - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.upgrades[0].displayFrom).toBe(''); @@ -420,7 +420,7 @@ describe('workers/repository/updates/generate', () => { }); it('fixes different messages', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'depA', @@ -460,8 +460,9 @@ describe('workers/repository/updates/generate', () => { }); it('uses semantic commits', () => { - const branch = [ - partial<BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, manager: 'some-manager', depName: 'some-dep', @@ -475,7 +476,7 @@ describe('workers/repository/updates/generate', () => { group: { foo: 2, }, - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.prTitle).toBe( @@ -484,8 +485,9 @@ describe('workers/repository/updates/generate', () => { }); it('scopes monorepo commits', () => { - const branch = [ - partial<BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, manager: 'some-manager', depName: 'some-dep', @@ -501,15 +503,16 @@ describe('workers/repository/updates/generate', () => { group: { foo: 2, }, - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.prTitle).toBe('chore(): update dependency some-dep to v1.2.0'); }); it('scopes monorepo commits with nested package files using parent directory', () => { - const branch = [ - partial<BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, commitBodyTable: false, manager: 'some-manager', @@ -526,7 +529,7 @@ describe('workers/repository/updates/generate', () => { group: { foo: 2, }, - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.prTitle).toBe( @@ -535,8 +538,9 @@ describe('workers/repository/updates/generate', () => { }); it('scopes monorepo commits with nested package files using base directory', () => { - const branch = [ - partial<BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, manager: 'some-manager', depName: 'some-dep', @@ -552,7 +556,7 @@ describe('workers/repository/updates/generate', () => { group: { foo: 2, }, - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.prTitle).toBe( @@ -561,8 +565,9 @@ describe('workers/repository/updates/generate', () => { }); it('adds commit message body', () => { - const branch = [ - partial<BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, manager: 'some-manager', depName: 'some-dep', @@ -570,7 +575,7 @@ describe('workers/repository/updates/generate', () => { newValue: '1.2.0', isSingleVersion: true, newVersion: '1.2.0', - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.commitMessage).toMatchSnapshot(); @@ -578,14 +583,15 @@ describe('workers/repository/updates/generate', () => { }); it('supports manual prTitle', () => { - const branch = [ - partial<BranchUpgradeConfig>({ + // TODO #7154 incompatible types + const branch: BranchUpgradeConfig[] = [ + { ...defaultConfig, manager: 'some-manager', depName: 'some-dep', prTitle: 'Upgrade {{depName}}', toLowerCase: true, - }), + } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); expect(res.prTitle).toBe('upgrade some-dep'); @@ -598,7 +604,7 @@ describe('workers/repository/updates/generate', () => { commitBodyTable: true, datasource: NpmDatasource.id, depName: '@types/some-dep', - groupName: null, + groupName: null as never, branchName: 'some-branch', prTitle: 'some-title', currentValue: '0.5.7', @@ -612,7 +618,7 @@ describe('workers/repository/updates/generate', () => { datasource: NpmDatasource.id, manager: 'some-manager', depName: 'some-dep', - groupName: null, + groupName: null as never, branchName: 'some-branch', prTitle: 'some-title', newValue: '0.6.0', @@ -623,7 +629,7 @@ describe('workers/repository/updates/generate', () => { datasource: NpmDatasource.id, manager: 'some-manager', depName: 'some-dep', - groupName: null, + groupName: null as never, branchName: 'some-branch', prTitle: 'some-other-title', newValue: '1.0.0', @@ -661,7 +667,7 @@ describe('workers/repository/updates/generate', () => { { manager: 'some-manager', depName: 'some-dep', - groupName: null, + groupName: null as never, branchName: 'some-branch', prTitle: 'some-title', newValue: '0.6.0', @@ -673,7 +679,7 @@ describe('workers/repository/updates/generate', () => { datasource: NpmDatasource.id, manager: 'some-manager', depName: 'some-dep', - groupName: null, + groupName: null as never, branchName: 'some-branch', prTitle: 'some-other-title', newValue: '1.0.0', @@ -683,7 +689,7 @@ describe('workers/repository/updates/generate', () => { { manager: 'some-manager', depName: '@types/some-dep', - groupName: null, + groupName: null as never, branchName: 'some-branch', prTitle: 'some-title', newValue: '0.5.7', @@ -718,6 +724,7 @@ describe('workers/repository/updates/generate', () => { }); it('handles upgrades', () => { + // TODO #7154 incompatible types const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', @@ -765,7 +772,7 @@ describe('workers/repository/updates/generate', () => { updateType: 'patch' as UpdateType, fileReplacePosition: 0, }, - ]; + ] as BranchUpgradeConfig[]; const res = generateBranchConfig(branch); expect(res.prTitle).toMatchSnapshot('some-title (patch)'); }); @@ -829,7 +836,7 @@ describe('workers/repository/updates/generate', () => { }); it('passes through pendingChecks', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', @@ -853,7 +860,7 @@ describe('workers/repository/updates/generate', () => { }); it('filters pendingChecks', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', @@ -876,7 +883,7 @@ describe('workers/repository/updates/generate', () => { }); it('displays pending versions', () => { - const branch = [ + const branch: BranchUpgradeConfig[] = [ { manager: 'some-manager', depName: 'some-dep', diff --git a/tsconfig.strict.json b/tsconfig.strict.json index 31ed5c1aaa..a4aad68848 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -12,9 +12,7 @@ "**/__mocks__/*", "coverage", "config.js", - "tmp", + "tmp" // TODO: fixme - "lib/workers/**/*.spec.ts", - "lib/renovate.spec.ts" ] } -- GitLab