From 0b36f97bd3e5086ac408f9212ecd036bbea171f9 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Mon, 8 May 2023 12:06:40 +0530 Subject: [PATCH] refactor: replace as with partial/satisfies (#21982) --- .../datasource/github-tags/index.spec.ts | 5 ++-- lib/modules/manager/gomod/artifacts.spec.ts | 16 ++++++----- .../branch/__snapshots__/commit.spec.ts.snap | 22 --------------- .../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 ++++--- .../update/pr/changelog/release-notes.spec.ts | 12 ++++----- 9 files changed, 59 insertions(+), 58 deletions(-) delete mode 100644 lib/workers/repository/update/branch/__snapshots__/commit.spec.ts.snap 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'); 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, - }, - ], -] -`; 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(); }); 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/',