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(jest): enable clearMocks #18779

Merged
merged 4 commits into from
Nov 15, 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
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function jestGithubRunnerSpecs(): JestConfig {

const config: JestConfig = {
cacheDirectory: '.cache/jest',
clearMocks: true,
coverageDirectory: './coverage',
collectCoverage: true,
collectCoverageFrom: [
Expand Down
1 change: 0 additions & 1 deletion lib/config/presets/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe('config/presets/index', () => {

beforeEach(() => {
config = {};
jest.clearAllMocks();
memCache.init();
});

Expand Down
4 changes: 0 additions & 4 deletions lib/instrumentation/decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ afterAll(disableInstrumentations);
describe('instrumentation/decorator', () => {
const spy = jest.fn(() => Promise.resolve());

beforeEach(() => {
jest.clearAllMocks();
});

it('should instrument async function', async () => {
class MyClass {
@instrument({ name: 'getNumber' })
Expand Down
1 change: 0 additions & 1 deletion lib/instrumentation/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('instrumentation/index', () => {
const oldEnv = process.env;

beforeEach(() => {
jest.clearAllMocks();
api.trace.disable(); // clear global components
process.env = { ...oldEnv };
});
Expand Down
4 changes: 0 additions & 4 deletions lib/modules/datasource/cdnjs/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ const pathFor = (s: string): string =>

describe('modules/datasource/cdnjs/index', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('throws for empty result', async () => {
httpMock.scope(baseUrl).get(pathFor('foo/bar')).reply(200, '}');
await expect(
Expand Down
1 change: 0 additions & 1 deletion lib/modules/datasource/gradle-version/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('modules/datasource/gradle-version/index', () => {
versioning,
depName: 'abc',
};
jest.clearAllMocks();
});

it('processes real data', async () => {
Expand Down
1 change: 0 additions & 1 deletion lib/modules/datasource/npm/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const http = new Http('npm');

describe('modules/datasource/npm/get', () => {
beforeEach(() => {
jest.clearAllMocks();
hostRules.clear();
setNpmrc();
});
Expand Down
4 changes: 0 additions & 4 deletions lib/modules/datasource/orb/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ const datasource = OrbDatasource.id;

describe('modules/datasource/orb/index', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('returns null for empty result', async () => {
httpMock.scope(baseUrl).post('/graphql-unstable').reply(200, {});
expect(
Expand Down
4 changes: 0 additions & 4 deletions lib/modules/datasource/terraform-module/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ const localTerraformEnterprisebaseUrl = 'https://terraform.foo.bar';

describe('modules/datasource/terraform-module/index', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('returns null for empty result', async () => {
httpMock
.scope(baseUrl)
Expand Down
1 change: 0 additions & 1 deletion lib/modules/manager/npm/post-update/yarn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ env.getChildProcessEnv.mockReturnValue(envMock.basic);
describe('modules/manager/npm/post-update/yarn', () => {
beforeEach(() => {
delete process.env.BUILDPACK;
jest.clearAllMocks();
Fixtures.reset();
GlobalConfig.set({ localDir: '.', cacheDir: '/tmp/cache' });
docker.resetPrefetchedImages();
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/platform/bitbucket/comments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ describe('modules/platform/bitbucket/comments', () => {
const config: comments.CommentsConfig = { repository: 'some/repo' };

beforeEach(() => {
jest.clearAllMocks();

setBaseUrl(baseUrl);
});

Expand Down
1 change: 0 additions & 1 deletion lib/modules/platform/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ describe('modules/platform/gitea/index', () => {

beforeEach(async () => {
jest.resetModules();
jest.clearAllMocks();
jest.mock('./gitea-helper');
jest.mock('../../../util/git');
jest.mock('../../../logger');
Expand Down
4 changes: 0 additions & 4 deletions lib/util/cache/package/decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ describe('util/cache/package/decorator', () => {
await packageCache.init({ cacheDir: os.tmpdir() });
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should cache string', async () => {
class MyClass {
@cache({ namespace: 'namespace', key: 'key' })
Expand Down
1 change: 0 additions & 1 deletion lib/util/cache/repository/impl/s3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('util/cache/repository/impl/s3', () => {

beforeEach(() => {
GlobalConfig.set({ platform: 'github' });
jest.clearAllMocks();
s3Mock.reset();
s3Cache = new RepoCacheS3(repository, '0123456789abcdef', url);
getObjectCommandInput = createGetObjectCommandInput(repository, url);
Expand Down
4 changes: 0 additions & 4 deletions lib/util/package-rules/current-version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { CurrentVersionMatcher } from './current-version';
describe('util/package-rules/current-version', () => {
const matcher = new CurrentVersionMatcher();

afterEach(() => {
jest.clearAllMocks();
});

describe('match', () => {
it('return false on version exception', () => {
const spy = jest.spyOn(pep440, 'matches').mockImplementationOnce(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('workers/repository/config-migration/branch/commit-message', () => {
const config = getConfig();
const fileName = 'renovate.json';

beforeEach(() => {
jest.clearAllMocks();
});

afterAll(() => {
jest.resetAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('workers/repository/config-migration/branch/create', () => {
let migratedConfigData: MigratedData;

beforeEach(() => {
jest.clearAllMocks();
config = getConfig();
config.baseBranch = 'dev';
config.defaultBranch = 'master';
Expand Down
48 changes: 23 additions & 25 deletions lib/workers/repository/dependency-dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const getIssueSpy = platform.getIssue;
let config: RenovateConfig;

beforeEach(() => {
jest.clearAllMocks();
massageMdSpy.mockImplementation(massageMarkdown);
config = getConfig();
config.platform = 'github';
Expand Down Expand Up @@ -66,10 +65,9 @@ function genRandPackageFile(
async function dryRun(
branches: BranchConfig[],
platform: jest.MockedObject<Platform>,
ensureIssueClosingCalls = 0,
ensureIssueCalls = 0
ensureIssueClosingCalls: number,
ensureIssueCalls: number
) {
jest.clearAllMocks();
GlobalConfig.set({ dryRun: 'full' });
await dependencyDashboard.ensureDependencyDashboard(config, branches);
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(
Expand Down Expand Up @@ -172,7 +170,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 1, 0);
});

it('do nothing if it has no dependencyDashboardApproval branches', async () => {
Expand All @@ -192,7 +190,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 1, 0);
});

it('closes Dependency Dashboard when there is 0 PR opened and dependencyDashboardAutoclose is true', async () => {
Expand All @@ -207,7 +205,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 1, 0);
});

it('closes Dependency Dashboard when all branches are automerged and dependencyDashboardAutoclose is true', async () => {
Expand All @@ -234,7 +232,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 1, 0);
});

it('open or update Dependency Dashboard when all branches are closed and dependencyDashboardAutoclose is false', async () => {
Expand All @@ -251,7 +249,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('open or update Dependency Dashboard when rules contain approvals', async () => {
Expand Down Expand Up @@ -282,7 +280,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('checks an issue with 2 Pending Approvals, 2 not scheduled, 2 pr-hourly-limit-reached and 2 in error', async () => {
Expand Down Expand Up @@ -364,7 +362,7 @@ describe('workers/repository/dependency-dashboard', () => {
);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('checks an issue with 2 PR pr-edited', async () => {
Expand Down Expand Up @@ -401,7 +399,7 @@ describe('workers/repository/dependency-dashboard', () => {
);

// same with dry run
await dryRun(branches, platform, 0, 0);
await dryRun(branches, platform, 0, 1);
});

it('checks an issue with 3 PR in progress and rebase all option', async () => {
Expand Down Expand Up @@ -446,7 +444,7 @@ describe('workers/repository/dependency-dashboard', () => {
);

// same with dry run
await dryRun(branches, platform, 0, 0);
await dryRun(branches, platform, 0, 1);
});

it('checks an issue with 2 PR closed / ignored', async () => {
Expand Down Expand Up @@ -481,7 +479,7 @@ describe('workers/repository/dependency-dashboard', () => {
);

// same with dry run
await dryRun(branches, platform, 0, 0);
await dryRun(branches, platform, 0, 1);
});

it('checks an issue with 3 PR in approval', async () => {
Expand Down Expand Up @@ -531,7 +529,7 @@ describe('workers/repository/dependency-dashboard', () => {
);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('contains logged problems', async () => {
Expand Down Expand Up @@ -763,7 +761,7 @@ describe('workers/repository/dependency-dashboard', () => {
]);

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

describe('checks detected dependencies section', () => {
Expand Down Expand Up @@ -792,7 +790,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('show default message in issues body when packageFiles is empty', async () => {
Expand All @@ -804,7 +802,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('show default message in issues body when when packageFiles is null', async () => {
Expand All @@ -816,7 +814,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('shows different combinations of version+digest for a given dependency', async () => {
Expand All @@ -827,7 +825,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});
});

Expand All @@ -845,7 +843,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('show default message in issues body when packageFiles is empty', async () => {
Expand All @@ -856,7 +854,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('show default message in issues body when when packageFiles is null', async () => {
Expand All @@ -867,7 +865,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});

it('truncates the body of a really big repo', async () => {
Expand All @@ -883,7 +881,7 @@ describe('workers/repository/dependency-dashboard', () => {
).toBeTrue();

// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});
});

Expand Down Expand Up @@ -918,7 +916,7 @@ describe('workers/repository/dependency-dashboard', () => {
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
// same with dry run
await dryRun(branches, platform);
await dryRun(branches, platform, 0, 1);
});
});

Expand Down
1 change: 0 additions & 1 deletion lib/workers/repository/onboarding/branch/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('workers/repository/onboarding/branch/config', () => {
});

beforeEach(() => {
jest.clearAllMocks();
config = getConfig();
config.platform = 'github';
config.repository = 'some/repo';
Expand Down
1 change: 0 additions & 1 deletion lib/workers/repository/onboarding/branch/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('workers/repository/onboarding/branch/create', () => {
let config: RenovateConfig;

beforeEach(() => {
jest.clearAllMocks();
config = getConfig();
});

Expand Down
Loading