diff --git a/lib/config/migrate-validate.spec.ts b/lib/config/migrate-validate.spec.ts index eb3754620ad580..ff6744efd614b8 100644 --- a/lib/config/migrate-validate.spec.ts +++ b/lib/config/migrate-validate.spec.ts @@ -4,7 +4,6 @@ import { migrateAndValidate } from './migrate-validate'; let config: RenovateConfig; beforeEach(() => { - jest.resetAllMocks(); config = getConfig(); }); diff --git a/lib/config/presets/gitlab/index.spec.ts b/lib/config/presets/gitlab/index.spec.ts index e6bf9f67c4505c..38395133e69c9e 100644 --- a/lib/config/presets/gitlab/index.spec.ts +++ b/lib/config/presets/gitlab/index.spec.ts @@ -8,10 +8,6 @@ const projectPath = '/api/v4/projects/some%2Frepo'; const basePath = `${projectPath}/repository`; describe('config/presets/gitlab/index', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getPreset()', () => { it('throws EXTERNAL_HOST_ERROR', async () => { httpMock.scope(gitlabApiHost).get(projectPath).reply(500); diff --git a/lib/config/presets/local/index.spec.ts b/lib/config/presets/local/index.spec.ts index 54a29f8b8796d5..da874ccc290b23 100644 --- a/lib/config/presets/local/index.spec.ts +++ b/lib/config/presets/local/index.spec.ts @@ -15,7 +15,6 @@ const gitlab = mocked(_gitlab); describe('config/presets/local/index', () => { beforeEach(() => { - jest.resetAllMocks(); const preset = { resolved: 'preset' }; platform.getRawFile.mockResolvedValue('{ resolved: "preset" }'); gitea.getPresetFromEndpoint.mockResolvedValueOnce(preset); diff --git a/lib/config/presets/npm/index.spec.ts b/lib/config/presets/npm/index.spec.ts index e3c1853e0eac9e..1937a93fb82aaf 100644 --- a/lib/config/presets/npm/index.spec.ts +++ b/lib/config/presets/npm/index.spec.ts @@ -6,7 +6,6 @@ jest.mock('delay'); describe('config/presets/npm/index', () => { beforeEach(() => { - jest.resetAllMocks(); GlobalConfig.reset(); }); diff --git a/lib/logger/err-serializer.spec.ts b/lib/logger/err-serializer.spec.ts index 1021746d822289..cf24be5e2ef17f 100644 --- a/lib/logger/err-serializer.spec.ts +++ b/lib/logger/err-serializer.spec.ts @@ -54,8 +54,6 @@ describe('logger/err-serializer', () => { const baseUrl = 'https://github.com'; beforeEach(() => { - // reset module - jest.resetAllMocks(); // clean up hostRules hostRules.clear(); hostRules.add({ diff --git a/lib/modules/datasource/artifactory/index.spec.ts b/lib/modules/datasource/artifactory/index.spec.ts index 014cd1036b32da..e0d6c1b9499e43 100644 --- a/lib/modules/datasource/artifactory/index.spec.ts +++ b/lib/modules/datasource/artifactory/index.spec.ts @@ -22,10 +22,6 @@ function getPath(folder: string): string { } describe('modules/datasource/artifactory/index', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('getReleases', () => { it('parses real data (folders): with slash at the end', async () => { httpMock diff --git a/lib/modules/datasource/clojure/index.spec.ts b/lib/modules/datasource/clojure/index.spec.ts index 24fd6b26df6a4c..87b876cb4ef4d7 100644 --- a/lib/modules/datasource/clojure/index.spec.ts +++ b/lib/modules/datasource/clojure/index.spec.ts @@ -158,7 +158,6 @@ describe('modules/datasource/clojure/index', () => { matchHost: 'custom.registry.renovatebot.com', token: '123test', }); - jest.resetAllMocks(); }); afterEach(() => { diff --git a/lib/modules/datasource/docker/index.spec.ts b/lib/modules/datasource/docker/index.spec.ts index 1c2026fc883401..30b17f3afe7d20 100644 --- a/lib/modules/datasource/docker/index.spec.ts +++ b/lib/modules/datasource/docker/index.spec.ts @@ -47,10 +47,6 @@ describe('modules/datasource/docker/index', () => { hostRules.hosts.mockReturnValue([]); }); - afterEach(() => { - jest.resetAllMocks(); - }); - describe('getRegistryRepository', () => { it('handles local registries', () => { const res = getRegistryRepository( diff --git a/lib/modules/datasource/go/index.spec.ts b/lib/modules/datasource/go/index.spec.ts index 29246de56afc42..170c1774e6a697 100644 --- a/lib/modules/datasource/go/index.spec.ts +++ b/lib/modules/datasource/go/index.spec.ts @@ -45,13 +45,11 @@ const datasource = new GoDatasource(); describe('modules/datasource/go/index', () => { describe('getReleases', () => { beforeEach(() => { - jest.resetAllMocks(); hostRules.find.mockReturnValue({}); hostRules.hosts.mockReturnValue([]); }); afterEach(() => { - jest.resetAllMocks(); delete process.env.GOPROXY; }); diff --git a/lib/modules/datasource/go/releases-direct.spec.ts b/lib/modules/datasource/go/releases-direct.spec.ts index 12eb327a1bf6c5..27debf62018adb 100644 --- a/lib/modules/datasource/go/releases-direct.spec.ts +++ b/lib/modules/datasource/go/releases-direct.spec.ts @@ -21,15 +21,10 @@ describe('modules/datasource/go/releases-direct', () => { ); beforeEach(() => { - jest.resetAllMocks(); hostRules.find.mockReturnValue({}); hostRules.hosts.mockReturnValue([]); }); - afterEach(() => { - jest.resetAllMocks(); - }); - describe('getReleases', () => { it('returns null for null getDatasource result', async () => { getDatasourceSpy.mockResolvedValueOnce(null); diff --git a/lib/modules/datasource/index.spec.ts b/lib/modules/datasource/index.spec.ts index 742fa7e6fd1e0f..3202864da0a583 100644 --- a/lib/modules/datasource/index.spec.ts +++ b/lib/modules/datasource/index.spec.ts @@ -107,10 +107,6 @@ jest.mock('./metadata-manual', () => ({ })); describe('modules/datasource/index', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - afterEach(() => { datasources.delete(datasource); }); diff --git a/lib/util/exec/common.spec.ts b/lib/util/exec/common.spec.ts index 97fc556160d5a9..94812de4d126c6 100644 --- a/lib/util/exec/common.spec.ts +++ b/lib/util/exec/common.spec.ts @@ -152,10 +152,6 @@ describe('util/exec/common', () => { const stdout = 'out message'; const stderr = 'err message'; - beforeEach(() => { - jest.resetAllMocks(); - }); - describe('rawExec', () => { it('command exits with code 0', async () => { const cmd = 'ls -l'; diff --git a/lib/util/github/graphql/cache-strategies/package-cache-strategy.spec.ts b/lib/util/github/graphql/cache-strategies/package-cache-strategy.spec.ts index 4cf6817e8ba6bb..0e2f3f6c8ba6d2 100644 --- a/lib/util/github/graphql/cache-strategies/package-cache-strategy.spec.ts +++ b/lib/util/github/graphql/cache-strategies/package-cache-strategy.spec.ts @@ -17,10 +17,6 @@ describe('util/github/graphql/cache-strategies/package-cache-strategy', () => { const cacheGet = jest.spyOn(packageCache, 'get'); const cacheSet = jest.spyOn(packageCache, 'set'); - beforeEach(() => { - jest.resetAllMocks(); - }); - it('reconciles old cache record with new items', async () => { const oldItems = { '1': { version: '1', releaseTimestamp: isoTs('2020-01-01 10:00') }, diff --git a/lib/workers/global/index.spec.ts b/lib/workers/global/index.spec.ts index f4b25e25ee64ae..daae4d825c3036 100644 --- a/lib/workers/global/index.spec.ts +++ b/lib/workers/global/index.spec.ts @@ -7,9 +7,9 @@ import { CONFIG_PRESETS_INVALID } from '../../constants/error-messages'; import { DockerDatasource } from '../../modules/datasource/docker'; import * as _platform from '../../modules/platform'; import * as secrets from '../../util/sanitize'; -import * as _repositoryWorker from '../repository'; -import * as _configParser from './config/parse'; -import * as _limits from './limits'; +import * as repositoryWorker from '../repository'; +import * as configParser from './config/parse'; +import * as limits from './limits'; import * as globalWorker from '.'; jest.mock('../repository'); @@ -18,28 +18,24 @@ jest.mock('../../config/presets'); jest.mock('fs-extra'); const fs = mocked(_fs); +const platform = mocked(_platform); // imports are readonly -const repositoryWorker = _repositoryWorker; -const configParser: jest.Mocked = _configParser as never; -const platform: jest.Mocked = _platform as never; const presets = mocked(_presets); -const limits = _limits; const addSecretForSanitizing = jest.spyOn(secrets, 'addSecretForSanitizing'); +const parseConfigs = jest.spyOn(configParser, 'parseConfigs'); describe('workers/global/index', () => { beforeEach(() => { - jest.resetAllMocks(); logger.getProblems.mockImplementationOnce(() => []); - configParser.parseConfigs = jest.fn(); platform.initPlatform.mockImplementation((input) => Promise.resolve(input)); delete process.env.AWS_SECRET_ACCESS_KEY; delete process.env.AWS_SESSION_TOKEN; }); it('handles config warnings and errors', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ repositories: [], maintainYarnLock: true, foo: 1, @@ -51,7 +47,7 @@ describe('workers/global/index', () => { }); it('resolves global presets immediately', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ repositories: [], globalExtends: [':pinVersions'], hostRules: [{ matchHost: 'github.com', token: 'abc123' }], @@ -61,33 +57,33 @@ describe('workers/global/index', () => { expect(presets.resolveConfigPresets).toHaveBeenCalledWith({ extends: [':pinVersions'], }); + expect(parseConfigs).toHaveBeenCalledTimes(1); }); it('throws if global presets could not be resolved', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ - repositories: [], - globalExtends: [':pinVersions'], - }); - presets.resolveConfigPresets.mockImplementation(() => { + presets.resolveConfigPresets.mockImplementationOnce(() => { throw new Error('some-error'); }); await expect( globalWorker.resolveGlobalExtends(['some-preset']) ).rejects.toThrow(CONFIG_PRESETS_INVALID); expect(presets.resolveConfigPresets).toHaveBeenCalled(); + expect(parseConfigs).not.toHaveBeenCalled(); }); it('handles zero repos', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ baseDir: '/tmp/base', cacheDir: '/tmp/cache', repositories: [], }); await expect(globalWorker.start()).resolves.toBe(0); + expect(parseConfigs).toHaveBeenCalledTimes(1); + expect(repositoryWorker.renovateRepository).not.toHaveBeenCalled(); }); it('processes repositories', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ gitAuthor: 'a@b.com', enabled: true, repositories: ['a', 'b'], @@ -99,14 +95,15 @@ describe('workers/global/index', () => { }, ], }); - await globalWorker.start(); - expect(configParser.parseConfigs).toHaveBeenCalledTimes(1); + await expect(globalWorker.start()).resolves.toBe(0); + expect(parseConfigs).toHaveBeenCalledTimes(1); expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(2); }); it('processes repositories break', async () => { - limits.isLimitReached = jest.fn(() => true); - configParser.parseConfigs.mockResolvedValueOnce({ + const isLimitReached = jest.spyOn(limits, 'isLimitReached'); + isLimitReached.mockReturnValue(true); + parseConfigs.mockResolvedValueOnce({ gitAuthor: 'a@b.com', enabled: true, repositories: ['a', 'b'], @@ -119,12 +116,13 @@ describe('workers/global/index', () => { ], }); await globalWorker.start(); - expect(configParser.parseConfigs).toHaveBeenCalledTimes(1); + expect(parseConfigs).toHaveBeenCalledTimes(1); expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(0); + isLimitReached.mockReset(); }); it('exits with non-zero when errors are logged', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ baseDir: '/tmp/base', cacheDir: '/tmp/cache', repositories: [], @@ -140,7 +138,7 @@ describe('workers/global/index', () => { }); it('exits with zero when warnings are logged', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ baseDir: '/tmp/base', cacheDir: '/tmp/cache', repositories: [], @@ -157,31 +155,31 @@ describe('workers/global/index', () => { describe('processes platforms', () => { it('github', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ repositories: ['a'], platform: 'github', endpoint: 'https://github.com/', }); await globalWorker.start(); - expect(configParser.parseConfigs).toHaveBeenCalledTimes(1); + expect(parseConfigs).toHaveBeenCalledTimes(1); expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(1); }); it('gitlab', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ repositories: [{ repository: 'a' }], platform: 'gitlab', endpoint: 'https://my.gitlab.com/', }); await globalWorker.start(); - expect(configParser.parseConfigs).toHaveBeenCalledTimes(1); + expect(parseConfigs).toHaveBeenCalledTimes(1); expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(1); }); }); describe('write repositories to file', () => { it('successfully write file', async () => { - configParser.parseConfigs.mockResolvedValueOnce({ + parseConfigs.mockResolvedValueOnce({ repositories: ['myOrg/myRepo'], platform: 'github', endpoint: 'https://github.com/', @@ -194,7 +192,7 @@ describe('workers/global/index', () => { '/tmp/renovate-output.json', '["myOrg/myRepo"]' ); - expect(configParser.parseConfigs).toHaveBeenCalledTimes(1); + expect(parseConfigs).toHaveBeenCalledTimes(1); expect(repositoryWorker.renovateRepository).toHaveBeenCalledTimes(0); }); }); diff --git a/lib/workers/repository/config-migration/branch/rebase.spec.ts b/lib/workers/repository/config-migration/branch/rebase.spec.ts index c7e8b12a2d80ee..73bed25e762d65 100644 --- a/lib/workers/repository/config-migration/branch/rebase.spec.ts +++ b/lib/workers/repository/config-migration/branch/rebase.spec.ts @@ -26,7 +26,7 @@ describe('workers/repository/config-migration/branch/rebase', () => { 'applyPrettierFormatting' ); - beforeAll(() => { + beforeEach(() => { GlobalConfig.set({ localDir: '', }); @@ -47,8 +47,6 @@ describe('workers/repository/config-migration/branch/rebase', () => { }; beforeEach(() => { - jest.resetAllMocks(); - GlobalConfig.reset(); config = { ...getConfig(), repository: 'some/repo', @@ -72,9 +70,7 @@ describe('workers/repository/config-migration/branch/rebase', () => { ])( 'does nothing if branch is up to date (%s)', async (filename, rawConfig) => { - git.getFile - .mockResolvedValueOnce(rawConfig) - .mockResolvedValueOnce(rawConfig); + git.getFile.mockResolvedValueOnce(rawConfig); migratedConfigData.filename = filename; migratedConfigData.content = rawConfig; @@ -82,6 +78,7 @@ describe('workers/repository/config-migration/branch/rebase', () => { expect(checkoutBranch).toHaveBeenCalledTimes(0); expect(git.commitFiles).toHaveBeenCalledTimes(0); + expect(git.getFile).toHaveBeenCalledTimes(1); } ); @@ -90,6 +87,7 @@ describe('workers/repository/config-migration/branch/rebase', () => { ['renovate.json5', renovateConfigJson5], ])('rebases migration branch (%s)', async (filename, rawConfig) => { git.isBranchBehindBase.mockResolvedValueOnce(true); + prettierSpy.mockResolvedValueOnce(''); migratedConfigData.filename = filename; migratedConfigData.content = rawConfig; @@ -157,6 +155,7 @@ describe('workers/repository/config-migration/branch/rebase', () => { ])('rebases via platform (%s)', async (filename, rawConfig) => { config.platformCommit = true; git.isBranchBehindBase.mockResolvedValueOnce(true); + prettierSpy.mockResolvedValueOnce(''); migratedConfigData.filename = filename; migratedConfigData.content = rawConfig; diff --git a/lib/workers/repository/process/lookup/index.spec.ts b/lib/workers/repository/process/lookup/index.spec.ts index 58baa2986886ce..a9ed162fc30eee 100644 --- a/lib/workers/repository/process/lookup/index.spec.ts +++ b/lib/workers/repository/process/lookup/index.spec.ts @@ -49,7 +49,6 @@ describe('workers/repository/process/lookup/index', () => { config.manager = 'npm'; config.versioning = npmVersioningId; config.rangeStrategy = 'replace'; - jest.resetAllMocks(); jest .spyOn(GitRefsDatasource.prototype, 'getReleases') .mockResolvedValueOnce({ @@ -61,7 +60,9 @@ describe('workers/repository/process/lookup/index', () => { }); // TODO: fix mocks - afterEach(() => httpMock.clear(false)); + afterEach(() => { + httpMock.clear(false); + }); describe('.lookupUpdates()', () => { it('returns null if unknown datasource', async () => { diff --git a/lib/workers/repository/update/pr/changelog/index.spec.ts b/lib/workers/repository/update/pr/changelog/index.spec.ts index c3a3439f4cc773..c99c2f0e877a06 100644 --- a/lib/workers/repository/update/pr/changelog/index.spec.ts +++ b/lib/workers/repository/update/pr/changelog/index.spec.ts @@ -38,7 +38,6 @@ const upgrade: BranchConfig = partial({ describe('workers/repository/update/pr/changelog/index', () => { describe('getChangeLogJSON', () => { beforeEach(() => { - jest.resetAllMocks(); hostRules.clear(); hostRules.add({ hostType: 'github', @@ -86,7 +85,12 @@ describe('workers/repository/update/pr/changelog/index', () => { it('works without Github', async () => { githubTagsMock.mockRejectedValueOnce(new Error('Unknown')); - githubReleasesMock.mockRejectedValueOnce(new Error('Unknown')); + // 4 versions, so 4 calls without cache + githubReleasesMock + .mockRejectedValueOnce(new Error('Unknown')) + .mockRejectedValueOnce(new Error('Unknown')) + .mockRejectedValueOnce(new Error('Unknown')) + .mockRejectedValueOnce(new Error('Unknown')); httpMock .scope(githubApiHost) .get('/repos/chalk/chalk') @@ -182,8 +186,9 @@ describe('workers/repository/update/pr/changelog/index', () => { }); it('supports node engines', async () => { - githubTagsMock.mockRejectedValueOnce([]); - githubReleasesMock.mockRejectedValueOnce([]); + githubTagsMock.mockResolvedValueOnce([]); + githubReleasesMock.mockResolvedValueOnce([]); + httpMock.scope(githubApiHost).get(/.*/).reply(200, []).persist(); expect( await getChangeLogJSON({ ...upgrade, @@ -207,8 +212,6 @@ describe('workers/repository/update/pr/changelog/index', () => { { version: '2.2.2' }, ], }); - // FIXME: missing mocks - httpMock.clear(false); }); it('handles no sourceUrl', async () => { 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 c44ff547ecc0da..071f42ffe7d89f 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -66,10 +66,6 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { hostRules.hosts.mockReturnValue([]); }); - afterEach(() => { - jest.resetAllMocks(); - }); - describe('releaseNotesCacheMinutes', () => { const now = DateTime.local();