From 6d5de8a8c3760633793cec7c579a62ac62790342 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Mon, 20 Feb 2023 02:01:45 +0530 Subject: [PATCH 1/7] replace as with partial --- lib/config/types.ts | 4 +- lib/modules/manager/gomod/artifacts.spec.ts | 16 +- lib/modules/manager/types.ts | 2 +- .../repository/update/branch/index.spec.ts | 54 +++--- .../update/pr/changelog/release-notes.spec.ts | 163 +++++++++--------- 5 files changed, 128 insertions(+), 111 deletions(-) diff --git a/lib/config/types.ts b/lib/config/types.ts index 817fcdca976dcb..74110ea2c3282a 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -31,7 +31,7 @@ export interface RenovateSharedConfig { branchPrefixOld?: string; branchName?: string; branchNameStrict?: boolean; - manager?: string | null; + manager?: string; commitMessage?: string; commitMessagePrefix?: string; confidential?: boolean; @@ -454,7 +454,7 @@ export interface PackageRuleInputConfig extends Record { sourceUrl?: string | null; language?: string; baseBranch?: string; - manager?: string | null; + manager?: string; datasource?: string; packageRules?: (PackageRule & PackageRuleInputConfig)[]; } diff --git a/lib/modules/manager/gomod/artifacts.spec.ts b/lib/modules/manager/gomod/artifacts.spec.ts index 71a441107d0861..16c65b5fdfafbd 100644 --- a/lib/modules/manager/gomod/artifacts.spec.ts +++ b/lib/modules/manager/gomod/artifacts.spec.ts @@ -1083,9 +1083,11 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename const execSnapshots = mockExecAll(); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['go.sum'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: ['go.sum'], + }) + ); fs.readLocalFile.mockResolvedValueOnce('New go.sum 1'); fs.readLocalFile.mockResolvedValueOnce('New go.sum 2'); fs.readLocalFile.mockResolvedValueOnce('New go.sum 3'); @@ -1146,9 +1148,11 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename const execSnapshots = mockExecAll(); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['go.sum'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: ['go.sum'], + }) + ); fs.readLocalFile.mockResolvedValueOnce('New go.sum 1'); fs.readLocalFile.mockResolvedValueOnce('New go.sum 2'); fs.readLocalFile.mockResolvedValueOnce('New go.sum 3'); diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index d3d897ff7e22bd..969e7875cf0c85 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -47,7 +47,7 @@ export interface RangeConfig> extends ManagerData { currentValue?: string; depName?: string; depType?: string; - manager?: string | null; + manager?: string; rangeStrategy: RangeStrategy; } diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 08d037066d3cbe..f910665802edbb 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -1627,11 +1627,13 @@ describe('workers/repository/update/branch/index', () => { path: 'pom.xml', contents: 'pom.xml file contents', }; - getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ - updatedPackageFiles: [updatedPackageFile], - artifactErrors: [], - updatedArtifacts: [], - } as PackageFilesResult); + getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce( + partial({ + updatedPackageFiles: [updatedPackageFile], + artifactErrors: [], + updatedArtifacts: [], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [ @@ -1784,11 +1786,13 @@ describe('workers/repository/update/branch/index', () => { path: 'pom.xml', contents: 'pom.xml file contents', }; - getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ - updatedPackageFiles: [updatedPackageFile], - artifactErrors: [], - updatedArtifacts: [], - } as PackageFilesResult); + getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce( + partial({ + updatedPackageFiles: [updatedPackageFile], + artifactErrors: [], + updatedArtifacts: [], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [ @@ -2014,10 +2018,12 @@ describe('workers/repository/update/branch/index', () => { }); it('Dependency Dashboard All Pending approval', async () => { - jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce({ - updatedPackageFiles: [partial({})], - artifactErrors: [{}], - } as PackageFilesResult); + jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce( + partial({ + updatedPackageFiles: [partial({})], + artifactErrors: [{}], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [partial({})], @@ -2049,10 +2055,12 @@ describe('workers/repository/update/branch/index', () => { }); it('Dependency Dashboard open all rate-limited', async () => { - jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce({ - updatedPackageFiles: [partial({})], - artifactErrors: [{}], - } as PackageFilesResult); + jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce( + partial({ + updatedPackageFiles: [partial({})], + artifactErrors: [{}], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [partial({})], @@ -2084,10 +2092,12 @@ describe('workers/repository/update/branch/index', () => { }); it('continues branch, skips automerge if there are artifact errors', async () => { - jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce({ - updatedPackageFiles: [partial({})], - artifactErrors: [{}], - } as PackageFilesResult); + jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce( + partial({ + updatedPackageFiles: [partial({})], + artifactErrors: [{}], + }) + ); npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [], 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 071f42ffe7d89f..522700de0e3589 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -1,7 +1,7 @@ import { DateTime } from 'luxon'; import { Fixtures } from '../../../../../../test/fixtures'; import * as httpMock from '../../../../../../test/http-mock'; -import { mocked } from '../../../../../../test/util'; +import { mocked, partial } from '../../../../../../test/util'; import { clone } from '../../../../../util/clone'; import * as githubGraphql from '../../../../../util/github/graphql'; import * as _hostRules from '../../../../../util/host-rules'; @@ -46,17 +46,17 @@ const gitlabTreeResponse = [ { path: 'README.md', name: 'README.md', type: 'blob' }, ]; -const githubProject = { +const githubProject = partial({ type: 'github', apiBaseUrl: 'https://api.github.com/', baseUrl: 'https://github.com/', -} as ChangeLogProject; +}); -const gitlabProject = { +const gitlabProject = partial({ type: 'gitlab', apiBaseUrl: 'https://gitlab.com/api/v4/', baseUrl: 'https://gitlab.com/', -} as ChangeLogProject; +}); describe('workers/repository/update/pr/changelog/release-notes', () => { const githubReleasesMock = jest.spyOn(githubGraphql, 'queryReleases'); @@ -139,12 +139,15 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { it('returns ChangeLogResult without release notes', async () => { const input = { a: 1, - project: { + project: partial({ type: 'gitlab', repository: 'https://gitlab.com/gitlab-org/gitter/webapp/', - } as ChangeLogProject, + }), versions: [ - { version: '20.26.0', compare: { url: '' } } as ChangeLogRelease, + partial({ + version: '20.26.0', + compare: { url: '' }, + }), ], } as ChangeLogResult; expect(await addReleaseNotes(input, {} as BranchUpgradeConfig)).toEqual({ @@ -170,8 +173,8 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { describe('getReleaseList()', () => { it('should return empty array if no apiBaseUrl', async () => { const res = await getReleaseList( - {} as ChangeLogProject, - {} as ChangeLogRelease + partial({}), + partial({}) ); expect(res).toBeEmptyArray(); }); @@ -201,7 +204,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'some/yet-other-repository', }, - {} as ChangeLogRelease + partial({}) ); expect(res).toMatchObject([ { @@ -236,7 +239,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...gitlabProject, repository: 'some/yet-other-repository', }, - {} as ChangeLogRelease + partial({}) ); expect(res).toMatchObject([ { @@ -275,7 +278,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { apiBaseUrl: 'https://my.custom.domain/api/v4/', baseUrl: 'https://my.custom.domain/', }, - {} as ChangeLogRelease + partial({}) ); expect(res).toMatchObject([ { @@ -320,10 +323,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/repository', depName: 'some', }, - { + partial({ version: '1.0.0', gitRef: '1.0.0', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toBeNull(); @@ -355,10 +358,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -397,10 +400,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -439,10 +442,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -481,10 +484,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -523,10 +526,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toBeNull(); @@ -558,10 +561,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -602,10 +605,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -646,10 +649,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -689,10 +692,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -727,10 +730,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { depName: 'other', apiBaseUrl: 'https://api.gitlab.com/', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -764,10 +767,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { depName: 'other', apiBaseUrl: 'https://api.gitlab.com/', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -801,10 +804,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { depName: 'other', apiBaseUrl: 'https://api.gitlab.com/', }, - { + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -819,17 +822,17 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { it('gets null from repository without gitlab/github in domain', async () => { const res = await getReleaseNotes( - { + partial({ repository: 'some/repository', depName: 'other', apiBaseUrl: 'https://api.lol.lol/', baseUrl: 'https://lol.lol/', - } as ChangeLogProject, - { + }), + partial({ version: '1.0.1', gitRef: '1.0.1', - } as ChangeLogRelease, - {} as BranchUpgradeConfig + }), + partial({}) ); expect(res).toBeNull(); }); @@ -868,10 +871,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'exampleDep', }, - { + partial({ version: '1.0.0', gitRef: '1.0.0', - } as ChangeLogRelease, + }), {} as BranchUpgradeConfig ); expect(res).toEqual({ @@ -902,10 +905,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'exampleDep', }, - { + partial({ version: '1.0.0', gitRef: '1.0.0', - } as ChangeLogRelease, + }), { extractVersion: 'app-(?[0-9.]*)' } as BranchUpgradeConfig ); expect(res).toEqual({ @@ -928,10 +931,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'chalk', }, - { + partial({ version: '2.0.0', gitRef: '2.0.0', - } as ChangeLogRelease + }) ); expect(res).toBeNull(); }); @@ -953,10 +956,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'chalk', }, - { + partial({ version: '2.0.0', gitRef: '2.0.0', - } as ChangeLogRelease + }) ); expect(res).toBeNull(); }); @@ -977,10 +980,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'some/repository1', }, - { + partial({ version: '1.0.0', gitRef: '1.0.0', - } as ChangeLogRelease + }) ); expect(res).toBeNull(); }); @@ -1001,10 +1004,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'some/repository2', }, - { + partial({ version: '1.0.0', gitRef: '1.0.0', - } as ChangeLogRelease + }) ); expect(res).toBeNull(); }); @@ -1025,10 +1028,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'angular/angular.js', }, - { + partial({ version: '1.6.9', gitRef: '1.6.9', - } as ChangeLogRelease + }) ); expect(res).toMatchSnapshot({ notesSourceUrl: @@ -1053,10 +1056,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'gitlab-org/gitter/webapp', apiBaseUrl: 'https://api.gitlab.com/', }, - { + partial({ version: '20.26.0', gitRef: '20.26.0', - } as ChangeLogRelease + }) ); expect(res).toMatchSnapshot({ @@ -1084,10 +1087,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { apiBaseUrl: 'https://my.custom.domain/', baseUrl: 'https://my.custom.domain/', }, - { + partial({ version: '20.26.0', gitRef: '20.26.0', - } as ChangeLogRelease + }) ); expect(res).toMatchSnapshot({ @@ -1113,10 +1116,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'facebook/jest', }, - { + partial({ version: '22.0.0', gitRef: '22.0.0', - } as ChangeLogRelease + }) ); expect(res).toMatchSnapshot({ @@ -1148,10 +1151,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'nodeca/js-yaml', sourceDirectory, }, - { + partial({ version: '3.10.0', gitRef: '3.10.0', - } as ChangeLogRelease + }) ); expect(res).toMatchSnapshot({ @@ -1177,10 +1180,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'nodeca/js-yaml', }, - { + partial({ version: '3.10.0', gitRef: '3.10.0', - } as ChangeLogRelease + }) ); expect(res).toMatchSnapshot({ @@ -1192,13 +1195,13 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { it('ignores invalid', async () => { const res = await getReleaseNotesMd( - { + partial({ repository: 'nodeca/js-yaml', - } as ChangeLogProject, - { + }), + partial({ version: '3.10.0', gitRef: '3.10.0', - } as ChangeLogRelease + }) ); expect(res).toBeNull(); }); @@ -1223,10 +1226,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'yargs/yargs', }, - { + partial({ version: '15.3.0', gitRef: '15.3.0', - } as ChangeLogRelease + }) ); versionOneNotes = res!; @@ -1253,10 +1256,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'yargs/yargs', }, - { + partial({ version: '15.2.0', gitRef: '15.2.0', - } as ChangeLogRelease + }) ); versionTwoNotes = res!; @@ -1283,10 +1286,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...gitlabProject, repository: 'itentialopensource/adapter-utils', }, - { + partial({ version: '4.33.0', gitRef: '4.33.0', - } as ChangeLogRelease + }) ); versionTwoNotes = res!; @@ -1319,10 +1322,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'itentialopensource/adapter-utils', sourceDirectory, }, - { + partial({ version: '4.33.0', gitRef: '4.33.0', - } as ChangeLogRelease + }) ); versionTwoNotes = res!; From f108a9b1aac0db1b8cfb79ad8dbb09fedec44246 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 5 May 2023 08:33:18 +0530 Subject: [PATCH 2/7] replace as with partial --- lib/modules/datasource/github-tags/index.spec.ts | 5 +++-- lib/modules/manager/gomod/artifacts.spec.ts | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/modules/datasource/github-tags/index.spec.ts b/lib/modules/datasource/github-tags/index.spec.ts index 72ae3f11f2421b..cf276d32b32c12 100644 --- a/lib/modules/datasource/github-tags/index.spec.ts +++ b/lib/modules/datasource/github-tags/index.spec.ts @@ -1,5 +1,6 @@ import { getPkgReleases } from '..'; import * as httpMock from '../../../../test/http-mock'; +import { partial } from '../../../../test/util'; import * as githubGraphql from '../../../util/github/graphql'; import type { GithubTagItem } from '../../../util/github/graphql/types'; import * as hostRules from '../../../util/host-rules'; @@ -77,11 +78,11 @@ describe('modules/datasource/github-tags/index', () => { releaseTimestamp: '2021-01-01', hash: '123', }, - { + partial({ version: 'v2.0.0', gitRef: 'v2.0.0', releaseTimestamp: '2022-01-01', - } as GithubTagItem, + }), ]); const res = await github.getDigest({ packageName }, 'v2.0.0'); expect(res).toBeNull(); diff --git a/lib/modules/manager/gomod/artifacts.spec.ts b/lib/modules/manager/gomod/artifacts.spec.ts index b7370430da197d..aee0645b62011a 100644 --- a/lib/modules/manager/gomod/artifacts.spec.ts +++ b/lib/modules/manager/gomod/artifacts.spec.ts @@ -1362,9 +1362,11 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename const execSnapshots = mockExecAll(); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['go.sum'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: ['go.sum'], + }) + ); fs.readLocalFile .mockResolvedValueOnce('New go.sum') .mockResolvedValueOnce('New go.mod'); @@ -1405,9 +1407,11 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename const execSnapshots = mockExecAll(); - git.getRepoStatus.mockResolvedValueOnce({ - modified: ['go.sum'], - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial({ + modified: ['go.sum'], + }) + ); fs.readLocalFile .mockResolvedValueOnce('New go.sum') .mockResolvedValueOnce('New go.mod'); From dcb6cdfa7b754e46ac3d9320ac9fd2e589a84fee Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 5 May 2023 08:39:58 +0530 Subject: [PATCH 3/7] use minimal config --- .../update/branch/artifacts.spec.ts | 7 +++-- .../update/branch/check-existing.spec.ts | 9 ++++--- .../repository/update/branch/commit.spec.ts | 27 +++++++++++++++---- .../update/branch/get-updated.spec.ts | 9 ++++--- .../repository/update/pr/automerge.spec.ts | 10 ++++--- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/workers/repository/update/branch/artifacts.spec.ts b/lib/workers/repository/update/branch/artifacts.spec.ts index ca63fa5ec3db7b..1744205fbcfbf5 100644 --- a/lib/workers/repository/update/branch/artifacts.spec.ts +++ b/lib/workers/repository/update/branch/artifacts.spec.ts @@ -1,4 +1,4 @@ -import { getConfig, platform } from '../../../../../test/util'; +import { platform } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { BranchConfig } from '../../../types'; import { setArtifactErrorStatus } from './artifacts'; @@ -9,14 +9,13 @@ describe('workers/repository/update/branch/artifacts', () => { beforeEach(() => { GlobalConfig.set({}); jest.resetAllMocks(); - // TODO #7154 incompatible types config = { - ...getConfig(), + baseBranch: 'base-branch', manager: 'some-manager', branchName: 'renovate/pin', upgrades: [], artifactErrors: [{ lockFile: 'some' }], - } as BranchConfig; + } satisfies BranchConfig; }); describe('setArtifactsErrorStatus', () => { diff --git a/lib/workers/repository/update/branch/check-existing.spec.ts b/lib/workers/repository/update/branch/check-existing.spec.ts index c8cee3ed04366e..2e1af5eef1a7cd 100644 --- a/lib/workers/repository/update/branch/check-existing.spec.ts +++ b/lib/workers/repository/update/branch/check-existing.spec.ts @@ -1,4 +1,4 @@ -import { getConfig, partial, platform } from '../../../../../test/util'; +import { partial, platform } from '../../../../../test/util'; import { logger } from '../../../../logger'; import type { Pr } from '../../../../modules/platform'; import type { BranchConfig } from '../../../types'; @@ -9,12 +9,13 @@ describe('workers/repository/update/branch/check-existing', () => { let config: BranchConfig; beforeEach(() => { - // TODO: incompatible types (#7154) config = { - ...getConfig(), + baseBranch: 'base-branch', + manager: 'some-manager', + upgrades: [], branchName: 'some-branch', prTitle: 'some-title', - } as BranchConfig; + } satisfies BranchConfig; jest.resetAllMocks(); }); diff --git a/lib/workers/repository/update/branch/commit.spec.ts b/lib/workers/repository/update/branch/commit.spec.ts index 9147cf48e428f8..f98f3b57f7d842 100644 --- a/lib/workers/repository/update/branch/commit.spec.ts +++ b/lib/workers/repository/update/branch/commit.spec.ts @@ -1,4 +1,4 @@ -import { getConfig, scm } from '../../../../../test/util'; +import { scm } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { BranchConfig } from '../../../types'; import { commitFilesToBranch } from './commit'; @@ -8,9 +8,9 @@ describe('workers/repository/update/branch/commit', () => { let config: BranchConfig; beforeEach(() => { - // TODO: incompatible types (#7154) config = { - ...getConfig(), + baseBranch: 'base-branch', + manager: 'some-manager', branchName: 'renovate/some-branch', commitMessage: 'some commit message', semanticCommits: 'disabled', @@ -19,7 +19,7 @@ describe('workers/repository/update/branch/commit', () => { updatedPackageFiles: [], updatedArtifacts: [], upgrades: [], - } as BranchConfig; + } satisfies BranchConfig; jest.resetAllMocks(); scm.commitAndPush.mockResolvedValueOnce('123test'); GlobalConfig.reset(); @@ -38,7 +38,24 @@ describe('workers/repository/update/branch/commit', () => { }); await commitFilesToBranch(config); expect(scm.commitAndPush).toHaveBeenCalledTimes(1); - expect(scm.commitAndPush.mock.calls).toMatchSnapshot(); + expect(scm.commitAndPush.mock.calls).toEqual([ + [ + { + baseBranch: 'base-branch', + branchName: 'renovate/some-branch', + files: [ + { + contents: 'some contents', + path: 'package.json', + type: 'addition', + }, + ], + force: false, + message: 'some commit message', + platformCommit: false, + }, + ], + ]); }); it('dry runs', async () => { diff --git a/lib/workers/repository/update/branch/get-updated.spec.ts b/lib/workers/repository/update/branch/get-updated.spec.ts index 9dc3d2702d20c1..f6ec285d2f4a0e 100644 --- a/lib/workers/repository/update/branch/get-updated.spec.ts +++ b/lib/workers/repository/update/branch/get-updated.spec.ts @@ -1,4 +1,4 @@ -import { getConfig, git, mocked } from '../../../../../test/util'; +import { git, mocked } from '../../../../../test/util'; import { GitRefsDatasource } from '../../../../modules/datasource/git-refs'; import * as _batectWrapper from '../../../../modules/manager/batect-wrapper'; import * as _bundler from '../../../../modules/manager/bundler'; @@ -32,11 +32,12 @@ describe('workers/repository/update/branch/get-updated', () => { let config: BranchConfig; beforeEach(() => { - // TODO: incompatible types (#7154) config = { - ...getConfig(), + baseBranch: 'base-branch', + manager: 'some-manager', + branchName: 'renovate/pin', upgrades: [], - } as BranchConfig; + } satisfies BranchConfig; npm.updateDependency = jest.fn(); git.getFile.mockResolvedValueOnce('existing content'); }); diff --git a/lib/workers/repository/update/pr/automerge.spec.ts b/lib/workers/repository/update/pr/automerge.spec.ts index dfe4913afb4770..b602de45160ef3 100644 --- a/lib/workers/repository/update/pr/automerge.spec.ts +++ b/lib/workers/repository/update/pr/automerge.spec.ts @@ -1,4 +1,4 @@ -import { getConfig, partial, platform, scm } from '../../../../../test/util'; +import { partial, platform, scm } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { Pr } from '../../../../modules/platform'; import type { BranchConfig } from '../../../types'; @@ -12,10 +12,12 @@ describe('workers/repository/update/pr/automerge', () => { let pr: Pr; beforeEach(() => { - // TODO #7154 incompatible types config = { - ...getConfig(), - } as BranchConfig; + baseBranch: 'base-branch', + manager: 'some-manager', + branchName: 'renovate/pin', + upgrades: [], + } satisfies BranchConfig; pr = partial(); }); From 36f45d81fdf0cbf3e17070e9e8ef5526b945e1c1 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 5 May 2023 08:41:58 +0530 Subject: [PATCH 4/7] replace small snap with toEqual --- .../branch/__snapshots__/commit.spec.ts.snap | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 lib/workers/repository/update/branch/__snapshots__/commit.spec.ts.snap diff --git a/lib/workers/repository/update/branch/__snapshots__/commit.spec.ts.snap b/lib/workers/repository/update/branch/__snapshots__/commit.spec.ts.snap deleted file mode 100644 index 9de011dc077203..00000000000000 --- a/lib/workers/repository/update/branch/__snapshots__/commit.spec.ts.snap +++ /dev/null @@ -1,22 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`workers/repository/update/branch/commit commitFilesToBranch commits files 1`] = ` -[ - [ - { - "baseBranch": undefined, - "branchName": "renovate/some-branch", - "files": [ - { - "contents": "some contents", - "path": "package.json", - "type": "addition", - }, - ], - "force": false, - "message": "some commit message", - "platformCommit": false, - }, - ], -] -`; From 6a37316634269c8fdde3e05c6fbc3cf04c35c5d9 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 5 May 2023 08:43:50 +0530 Subject: [PATCH 5/7] replace as partial remove extra property from test config object --- .../update/pr/changelog/release-notes.spec.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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 978bef659f4a44..500c1ed58936bc 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -87,9 +87,11 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { describe('addReleaseNotes()', () => { it('returns null if input is null/undefined', async () => { - expect(await addReleaseNotes(null, {} as BranchUpgradeConfig)).toBeNull(); expect( - await addReleaseNotes(undefined, {} as BranchUpgradeConfig) + await addReleaseNotes(null, partial()) + ).toBeNull(); + expect( + await addReleaseNotes(undefined, partial()) ).toBeNull(); }); @@ -108,7 +110,6 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { it('returns ChangeLogResult', async () => { const input = { - a: 1, project: { type: 'github', repository: 'https://github.com/nodeca/js-yaml', @@ -118,7 +119,6 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { expect( await addReleaseNotes(input as never, partial()) ).toEqual({ - a: 1, hasReleaseNotes: false, project: { repository: 'https://github.com/nodeca/js-yaml', @@ -138,7 +138,6 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { it('returns ChangeLogResult without release notes', async () => { const input = { - a: 1, project: partial({ type: 'gitlab', repository: 'https://gitlab.com/gitlab-org/gitter/webapp/', @@ -149,11 +148,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { compare: { url: '' }, }), ], - } as ChangeLogResult; + } satisfies ChangeLogResult; expect( await addReleaseNotes(input, partial()) ).toEqual({ - a: 1, hasReleaseNotes: false, project: { repository: 'https://gitlab.com/gitlab-org/gitter/webapp/', From 8277aeabbe2a0fa5f5f84e07c3287cef91a12838 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 5 May 2023 09:06:54 +0530 Subject: [PATCH 6/7] revert outdated change --- .../repository/update/branch/index.spec.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index f34567457044bc..78f075b1427c58 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -1709,13 +1709,7 @@ describe('workers/repository/update/branch/index', () => { updatedArtifacts: [], }) ); - getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce( - partial({ - updatedPackageFiles: [updatedPackageFile], - artifactErrors: [], - updatedArtifacts: [], - }) - ); + npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [ @@ -2191,10 +2185,13 @@ describe('workers/repository/update/branch/index', () => { }); it('continues branch, skips automerge if there are artifact errors', async () => { - jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce({ - updatedPackageFiles: [partial({})], - artifactErrors: [{}], - } as PackageFilesResult); + jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce( + partial({ + updatedPackageFiles: [partial()], + artifactErrors: [{}], + }) + ); + npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [], From 8b6b024b44026a8cea1a2d5edbb2d644def80e3d Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 5 May 2023 09:16:53 +0530 Subject: [PATCH 7/7] refactor --- lib/workers/repository/update/branch/index.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 78f075b1427c58..636803ec391f9d 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -1709,7 +1709,6 @@ describe('workers/repository/update/branch/index', () => { updatedArtifacts: [], }) ); - npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [ @@ -2191,7 +2190,6 @@ describe('workers/repository/update/branch/index', () => { artifactErrors: [{}], }) ); - npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ artifactErrors: [], updatedArtifacts: [],