Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace as with partial/satisfies #21982

Merged
merged 10 commits into from May 8, 2023
5 changes: 3 additions & 2 deletions 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';
Expand Down Expand Up @@ -77,11 +78,11 @@ describe('modules/datasource/github-tags/index', () => {
releaseTimestamp: '2021-01-01',
hash: '123',
},
{
partial<GithubTagItem>({
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();
Expand Down
16 changes: 10 additions & 6 deletions lib/modules/manager/gomod/artifacts.spec.ts
Expand Up @@ -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<StatusResult>({
modified: ['go.sum'],
})
);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');
Expand Down Expand Up @@ -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<StatusResult>({
modified: ['go.sum'],
})
);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');
Expand Down

This file was deleted.

7 changes: 3 additions & 4 deletions 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';
Expand All @@ -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', () => {
Expand Down
9 changes: 5 additions & 4 deletions 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';
Expand All @@ -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();
});

Expand Down
27 changes: 22 additions & 5 deletions 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';
Expand All @@ -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',
Expand All @@ -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();
Expand All @@ -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 () => {
Expand Down
9 changes: 5 additions & 4 deletions 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';
Expand Down Expand Up @@ -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');
});
Expand Down
10 changes: 6 additions & 4 deletions 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';
Expand All @@ -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<Pr>();
});

Expand Down
12 changes: 5 additions & 7 deletions lib/workers/repository/update/pr/changelog/release-notes.spec.ts
Expand Up @@ -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<BranchUpgradeConfig>())
).toBeNull();
expect(
await addReleaseNotes(undefined, partial<BranchUpgradeConfig>())
).toBeNull();
});

Expand All @@ -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',
Expand All @@ -118,7 +119,6 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
expect(
await addReleaseNotes(input as never, partial<BranchUpgradeConfig>())
).toEqual({
a: 1,
hasReleaseNotes: false,
project: {
repository: 'https://github.com/nodeca/js-yaml',
Expand All @@ -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<ChangeLogProject>({
type: 'gitlab',
repository: 'https://gitlab.com/gitlab-org/gitter/webapp/',
Expand All @@ -149,11 +148,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
compare: { url: '' },
}),
],
} as ChangeLogResult;
} satisfies ChangeLogResult;
expect(
await addReleaseNotes(input, partial<BranchUpgradeConfig>())
).toEqual({
a: 1,
hasReleaseNotes: false,
project: {
repository: 'https://gitlab.com/gitlab-org/gitter/webapp/',
Expand Down