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

chore(deps): update jest monorepo #17737

Merged
merged 7 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/modules/datasource/aws-rds/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function mockDescribeVersionsCommand(
}

describe('modules/datasource/aws-rds/index', () => {
beforeEach(() => rdsMock.reset());
beforeEach(() => {
rdsMock.reset();
});

describe('getPkgReleases()', () => {
it('without returned versions', async () => {
Expand Down
89 changes: 41 additions & 48 deletions lib/modules/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as _AWS from '@aws-sdk/client-ecr';
import {
ECRClient,
GetAuthorizationTokenCommand,
GetAuthorizationTokenCommandOutput,
} from '@aws-sdk/client-ecr';
import { mockClient } from 'aws-sdk-client-mock';
import { getDigest, getPkgReleases } from '..';
import * as httpMock from '../../../../test/http-mock';
import { logger, mocked, partial } from '../../../../test/util';
import { logger, mocked } from '../../../../test/util';
import {
EXTERNAL_HOST_ERROR,
PAGE_NOT_FOUND_ERROR,
Expand All @@ -15,13 +20,9 @@ const hostRules = mocked(_hostRules);

const http = new Http(DockerDatasource.id);

jest.mock('@aws-sdk/client-ecr');
jest.mock('../../../util/host-rules');

type ECR = _AWS.ECR;
type GetAuthorizationTokenCommandOutput =
_AWS.GetAuthorizationTokenCommandOutput;
const AWS = mocked(_AWS);
const ecrMock = mockClient(ECRClient);

const baseUrl = 'https://index.docker.io/v2';
const authUrl = 'https://auth.docker.io';
Expand All @@ -30,26 +31,16 @@ const amazonUrl = 'https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2';
function mockEcrAuthResolve(
res: Partial<GetAuthorizationTokenCommandOutput> = {}
) {
AWS.ECR.mockImplementationOnce(() =>
partial<ECR>({
getAuthorizationToken: () =>
Promise.resolve<GetAuthorizationTokenCommandOutput>(
partial<GetAuthorizationTokenCommandOutput>(res)
),
})
);
ecrMock.on(GetAuthorizationTokenCommand).resolvesOnce(res);
}

function mockEcrAuthReject(msg: string) {
AWS.ECR.mockImplementationOnce(() =>
partial<ECR>({
getAuthorizationToken: jest.fn().mockRejectedValue(new Error(msg)),
})
);
ecrMock.on(GetAuthorizationTokenCommand).rejectsOnce(new Error(msg));
}

describe('modules/datasource/docker/index', () => {
beforeEach(() => {
ecrMock.reset();
hostRules.find.mockReturnValue({
username: 'some-username',
password: 'some-password',
Expand Down Expand Up @@ -415,20 +406,21 @@ describe('modules/datasource/docker/index', () => {
authorizationData: [{ authorizationToken: 'test_token' }],
});

await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
);
expect(
await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
)
).toBe('some-digest');

expect(AWS.ECR).toHaveBeenCalledWith({
credentials: {
accessKeyId: 'some-username',
secretAccessKey: 'some-password',
},
region: 'us-east-1',
const ecr = ecrMock.call(0).thisValue as ECRClient;
expect(await ecr.config.region()).toBe('us-east-1');
expect(await ecr.config.credentials()).toEqual({
accessKeyId: 'some-username',
secretAccessKey: 'some-password',
});
});

Expand All @@ -453,21 +445,22 @@ describe('modules/datasource/docker/index', () => {
authorizationData: [{ authorizationToken: 'test_token' }],
});

await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
);

expect(AWS.ECR).toHaveBeenCalledWith({
credentials: {
accessKeyId: 'some-username',
secretAccessKey: 'some-password',
sessionToken: 'some-session-token',
},
region: 'us-east-1',
expect(
await getDigest(
{
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag'
)
).toBe('some-digest');

const ecr = ecrMock.call(0).thisValue as ECRClient;
expect(await ecr.config.region()).toBe('us-east-1');
expect(await ecr.config.credentials()).toEqual({
accessKeyId: 'some-username',
secretAccessKey: 'some-password',
sessionToken: 'some-session-token',
});
});

Expand Down
9 changes: 7 additions & 2 deletions lib/modules/manager/git-submodules/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import is from '@sindresorhus/is';
import { mock } from 'jest-mock-extended';
import _simpleGit, { Response, SimpleGit, TaskOptions } from 'simple-git';
import _simpleGit, {
Response,
SimpleGit,
SimpleGitFactory,
TaskOptions,
} from 'simple-git';
import { GlobalConfig } from '../../../config/global';
import * as hostRules from '../../../util/host-rules';
import type { PackageFile } from '../types';
import { extractPackageFile } from '.';

jest.mock('simple-git');
const simpleGit: jest.Mock<Partial<SimpleGit>> = _simpleGit as never;
const Git: typeof _simpleGit = jest.requireActual('simple-git');
const Git = jest.requireActual('simple-git') as SimpleGitFactory;

describe('modules/manager/git-submodules/extract', () => {
// flaky ci tests
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/gradle/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { extractAllPackageFiles } from '.';
jest.mock('../../../util/fs');

function mockFs(files: Record<string, string>): void {
fs.readLocalFile.mockImplementation((fileName: string): Promise<string> => {
// TODO: fix types, jest is using wrong overload (#7154)
fs.readLocalFile.mockImplementation((fileName: string): Promise<any> => {
const content = files?.[fileName];
return Promise.resolve(content ?? '');
});
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/gradle/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function mockFs(files: Record<string, string>): void {
}
);

fs.readLocalFile.mockImplementation((fileName: string): Promise<string> => {
// TODO: fix types, jest is using wrong overload (#7154)
fs.readLocalFile.mockImplementation((fileName: string): Promise<any> => {
const content = files?.[fileName];
return Promise.resolve(content ?? '');
});
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/npm/post-update/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ describe('modules/manager/npm/post-update/index', () => {

it('works for npm', async () => {
spyNpm.mockResolvedValueOnce({ error: false, lockFile: '{}' });
fs.readLocalFile.mockImplementation((f) => {
// TODO: fix types, jest is using wrong overload (#7154)
fs.readLocalFile.mockImplementation((f): Promise<any> => {
if (f === '.npmrc') {
return Promise.resolve('# dummy');
}
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/nuget/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ jest.mock('./util');
const { getConfiguredRegistries, getDefaultRegistries } = mocked(util);
const hostRules = mocked(_hostRules);

const realFs: typeof import('../../../util/fs') =
jest.requireActual('../../../util/fs');
const realFs = jest.requireActual(
'../../../util/fs'
) as typeof import('../../../util/fs');

const adminConfig: RepoGlobalConfig = {
// `join` fixes Windows CI
Expand Down
3 changes: 2 additions & 1 deletion lib/util/exec/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function getReadable(
return readable;
}

function getSpawnStub(args: StubArgs): ChildProcess {
// TODO: fix types, jest is using wrong overload (#7154)
function getSpawnStub(args: StubArgs): any {
const {
cmd,
error,
Expand Down
2 changes: 1 addition & 1 deletion lib/util/exec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { exec } from '.';
const getHermitEnvsMock = mockedFunction(getHermitEnvs);

jest.mock('./hermit', () => ({
...jest.requireActual('./hermit'),
...(jest.requireActual('./hermit') as any),
getHermitEnvs: jest.fn(),
}));
jest.mock('../../modules/datasource');
Expand Down
12 changes: 7 additions & 5 deletions lib/workers/repository/dependency-dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import { PackageFiles } from './package-files';

type PrUpgrade = BranchUpgradeConfig;

const massageMdSpy = jest.spyOn(platform, 'massageMarkdown');
const massageMdSpy = platform.massageMarkdown;
const getIssueSpy = platform.getIssue;

let config: RenovateConfig;

beforeEach(() => {
Expand Down Expand Up @@ -64,7 +66,7 @@ function genRandPackageFile(

async function dryRun(
branches: BranchConfig[],
platform: jest.Mocked<Platform>,
platform: jest.MockedObject<Platform>,
ensureIssueClosingCalls = 0,
ensureIssueCalls = 0
) {
Expand Down Expand Up @@ -605,7 +607,7 @@ describe('workers/repository/dependency-dashboard', () => {
branchName2: 'approve-branch',
};
config.dependencyDashboardIssue = 1;
jest.spyOn(platform, 'getIssue').mockResolvedValueOnce({
getIssueSpy.mockResolvedValueOnce({
title: 'Dependency Dashboard',
body: `This issue contains a list of Renovate updates and their statuses.

Expand Down Expand Up @@ -667,7 +669,7 @@ describe('workers/repository/dependency-dashboard', () => {
branchName2: 'unlimit-branch',
};
config.dependencyDashboardIssue = 1;
jest.spyOn(platform, 'getIssue').mockResolvedValueOnce({
getIssueSpy.mockResolvedValueOnce({
title: 'Dependency Dashboard',
body: `This issue contains a list of Renovate updates and their statuses.
## Rate-limited
Expand Down Expand Up @@ -726,7 +728,7 @@ describe('workers/repository/dependency-dashboard', () => {
config.dependencyDashboard = true;
config.dependencyDashboardChecks = { branchName2: 'approve-branch' };
config.dependencyDashboardIssue = 1;
mockedFunction(platform.getIssue!).mockResolvedValueOnce({
mockedFunction(platform.getIssue).mockResolvedValueOnce({
title: 'Dependency Dashboard',
body: `This issue contains a list of Renovate updates and their statuses.

Expand Down
3 changes: 2 additions & 1 deletion lib/workers/repository/stats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe('workers/repository/stats', () => {
statusCode: 401,
},
];
memCache.get.mockImplementationOnce(() => stats);
// TODO: fix types, jest is using wrong overload (#7154)
memCache.get.mockImplementationOnce(() => stats as any);
expect(printRequestStats()).toBeUndefined();
expect(log.trace).toHaveBeenCalledOnce();
expect(log.debug).toHaveBeenCalledTimes(2);
Expand Down
13 changes: 2 additions & 11 deletions lib/workers/repository/update/branch/commit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
getConfig,
git,
mockedFunction,
platform,
} from '../../../../../test/util';
import { getConfig, git, platform } from '../../../../../test/util';
import { GlobalConfig } from '../../../../config/global';
import type { BranchConfig } from '../../../types';
import { commitFilesToBranch } from './commit';
Expand All @@ -29,7 +24,6 @@ describe('workers/repository/update/branch/commit', () => {
} as BranchConfig;
jest.resetAllMocks();
git.commitFiles.mockResolvedValueOnce('123test');
platform.commitFiles = jest.fn();
GlobalConfig.reset();
});

Expand Down Expand Up @@ -58,10 +52,7 @@ describe('workers/repository/update/branch/commit', () => {
config.platformCommit = true;
await commitFilesToBranch(config);
expect(platform.commitFiles).toHaveBeenCalledTimes(1);
// TODO #7154
expect(
mockedFunction(platform.commitFiles!).mock.calls
).toMatchSnapshot();
expect(platform.commitFiles.mock.calls).toMatchSnapshot();
});

it('dry runs', async () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/workers/repository/update/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ describe('workers/repository/update/branch/index', () => {
}),
});
GlobalConfig.set(adminConfig);
sanitize.sanitize.mockImplementation((input) => input);
// TODO: fix types, jest is using wrong overload (#7154)
sanitize.sanitize.mockImplementation((input) => input!);
repoCache.getCache.mockReturnValue({});
});

Expand Down
7 changes: 3 additions & 4 deletions lib/workers/repository/update/pr/code-owners.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ describe('workers/repository/update/pr/code-owners', () => {
});

it('returns empty array when error occurs', async () => {
fs.readLocalFile.mockImplementationOnce((_, __) => {
throw new Error();
});
fs.readLocalFile.mockRejectedValueOnce(new Error());
const codeOwners = await codeOwnersForPr(pr);
expect(codeOwners).toBeEmptyArray();
});
Expand All @@ -78,7 +76,8 @@ describe('workers/repository/update/pr/code-owners', () => {
];
codeOwnerFilePaths.forEach((codeOwnerFilePath) => {
it(`detects code owner file at '${codeOwnerFilePath}'`, async () => {
fs.readLocalFile.mockImplementation((path, _) => {
// TODO: fix types, jest is using wrong overload (#7154)
fs.readLocalFile.mockImplementation((path): Promise<any> => {
if (path === codeOwnerFilePath) {
return Promise.resolve(['* @mike'].join('\n'));
}
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@
},
"devDependencies": {
"@actions/core": "1.9.1",
"@jest/globals": "29.0.1",
"@jest/reporters": "29.0.1",
"@jest/test-result": "29.0.1",
"@jest/globals": "29.0.2",
"@jest/reporters": "29.0.2",
"@jest/test-result": "29.0.2",
"@ls-lint/ls-lint": "1.11.2",
"@openpgp/web-stream-tools": "0.0.11",
"@renovate/eslint-plugin": "https://github.com/renovatebot/eslint-plugin#v0.0.4",
Expand All @@ -247,7 +247,6 @@
"@types/github-url-from-git": "1.5.1",
"@types/global-agent": "2.1.1",
"@types/ini": "1.3.31",
"@types/jest": "28.1.7",
"@types/js-yaml": "4.0.5",
"@types/json-dup-key-validator": "1.0.0",
"@types/linkify-markdown": "1.0.1",
Expand Down Expand Up @@ -289,7 +288,7 @@
"glob": "8.0.3",
"graphql": "16.6.0",
"husky": "8.0.1",
"jest": "29.0.1",
"jest": "29.0.2",
"jest-extended": "3.1.0",
"jest-junit": "14.0.1",
"jest-mock-extended": "2.0.6",
Expand Down
Loading