From ec6893de2125fd93d6d88d095a9e651bd5d86e1d Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Fri, 22 Jul 2022 09:04:21 +0200 Subject: [PATCH] test: simplify exec mock --- lib/modules/manager/bundler/artifacts.spec.ts | 29 ++++++----- lib/modules/manager/cargo/artifacts.spec.ts | 15 +++--- .../manager/cocoapods/artifacts.spec.ts | 25 +++++----- .../manager/composer/artifacts.spec.ts | 29 ++++++----- lib/modules/manager/flux/artifacts.spec.ts | 11 ++--- lib/modules/manager/gomod/artifacts.spec.ts | 49 +++++++++---------- .../manager/gradle-wrapper/artifacts.spec.ts | 9 ++-- lib/modules/manager/helmv3/artifacts.spec.ts | 23 +++++---- .../manager/jsonnet-bundler/artifacts.spec.ts | 11 ++--- lib/modules/manager/mix/artifacts.spec.ts | 15 +++--- .../manager/npm/post-update/lerna.spec.ts | 13 +++-- .../manager/npm/post-update/npm.spec.ts | 25 +++++----- .../manager/npm/post-update/pnpm.spec.ts | 19 ++++--- .../manager/npm/post-update/yarn.spec.ts | 30 ++++++------ lib/modules/manager/nuget/artifacts.spec.ts | 23 +++++---- .../manager/pip-compile/artifacts.spec.ts | 13 +++-- lib/modules/manager/pipenv/artifacts.spec.ts | 19 ++++--- lib/modules/manager/poetry/artifacts.spec.ts | 19 ++++--- lib/util/exec/docker/index.spec.ts | 43 +++++++--------- lib/util/exec/index.spec.ts | 22 +++------ test/exec-util.ts | 25 ++++------ 21 files changed, 212 insertions(+), 255 deletions(-) diff --git a/lib/modules/manager/bundler/artifacts.spec.ts b/lib/modules/manager/bundler/artifacts.spec.ts index 3d287d719ab602..c86b6f2e65f007 100644 --- a/lib/modules/manager/bundler/artifacts.spec.ts +++ b/lib/modules/manager/bundler/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -14,7 +14,6 @@ const datasource = mocked(_datasource); const bundlerHostRules = mocked(_bundlerHostRules); jest.mock('fs-extra'); -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../datasource'); jest.mock('../../../util/fs'); @@ -71,7 +70,7 @@ describe('modules/manager/bundler/artifacts', () => { it('returns null if Gemfile.lock was not changed', async () => { fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: [] as string[], } as StatusResult); @@ -91,7 +90,7 @@ describe('modules/manager/bundler/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(); fs.readLocalFile.mockResolvedValueOnce(null); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -112,7 +111,7 @@ describe('modules/manager/bundler/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(); fs.readLocalFile.mockResolvedValueOnce(null); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -132,7 +131,7 @@ describe('modules/manager/bundler/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(); fs.readLocalFile.mockResolvedValueOnce(null); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -180,7 +179,7 @@ describe('modules/manager/bundler/artifacts', () => { { version: '1.3.0' }, ], }); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -210,7 +209,7 @@ describe('modules/manager/bundler/artifacts', () => { { version: '1.3.0' }, ], }); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -246,7 +245,7 @@ describe('modules/manager/bundler/artifacts', () => { { version: '1.3.0' }, ], }); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -295,7 +294,7 @@ describe('modules/manager/bundler/artifacts', () => { bundlerHostRules.getAuthenticationHeaderValue.mockReturnValue( 'some-user:some-password' ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -335,7 +334,7 @@ describe('modules/manager/bundler/artifacts', () => { bundlerHostRules.getAuthenticationHeaderValue.mockReturnValue( 'some-user:some-password' ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -380,7 +379,7 @@ describe('modules/manager/bundler/artifacts', () => { bundlerHostRules.getAuthenticationHeaderValue.mockReturnValue( 'some-user:some-password' ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -428,7 +427,7 @@ describe('modules/manager/bundler/artifacts', () => { bundlerHostRules.getAuthenticationHeaderValue.mockReturnValue( 'some-user:some-password' ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -451,7 +450,7 @@ describe('modules/manager/bundler/artifacts', () => { (execError as any).stderr = ''; fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); - const execSnapshots = mockExecAll(exec, execError); + const execSnapshots = mockExecAll(execError); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); @@ -478,7 +477,7 @@ describe('modules/manager/bundler/artifacts', () => { it('performs lockFileMaintenance', async () => { fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as StatusResult); diff --git a/lib/modules/manager/cargo/artifacts.spec.ts b/lib/modules/manager/cargo/artifacts.spec.ts index df04fea219a865..a3cfcc774624cf 100644 --- a/lib/modules/manager/cargo/artifacts.spec.ts +++ b/lib/modules/manager/cargo/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -7,7 +7,6 @@ import * as docker from '../../../util/exec/docker'; import type { UpdateArtifactsConfig } from '../types'; import * as cargo from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/git'); jest.mock('../../../util/http'); @@ -67,7 +66,7 @@ describe('modules/manager/cargo/artifacts', () => { fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('Current Cargo.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('Current Cargo.lock'); @@ -91,7 +90,7 @@ describe('modules/manager/cargo/artifacts', () => { fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); git.getFile.mockResolvedValueOnce('Old Cargo.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock'); const updatedDeps = [ @@ -113,7 +112,7 @@ describe('modules/manager/cargo/artifacts', () => { it('updates Cargo.lock based on the packageName, when given', async () => { fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); git.getFile.mockResolvedValueOnce('Old Cargo.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock'); const updatedDeps = [ @@ -143,7 +142,7 @@ describe('modules/manager/cargo/artifacts', () => { fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); git.getFile.mockResolvedValueOnce('Old Cargo.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock'); const updatedDeps = [ @@ -165,7 +164,7 @@ describe('modules/manager/cargo/artifacts', () => { it('returns updated Cargo.lock for lockfile maintenance', async () => { fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); git.getFile.mockResolvedValueOnce('Old Cargo.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock'); expect( @@ -183,7 +182,7 @@ describe('modules/manager/cargo/artifacts', () => { fs.statLocalFile.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); git.getFile.mockResolvedValueOnce('Old Cargo.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Cargo.lock'); fs.readLocalFile.mockResolvedValueOnce('New Cargo.lock'); const updatedDeps = [ diff --git a/lib/modules/manager/cocoapods/artifacts.spec.ts b/lib/modules/manager/cocoapods/artifacts.spec.ts index 5619b7760150f4..1f0fc0f87f7698 100644 --- a/lib/modules/manager/cocoapods/artifacts.spec.ts +++ b/lib/modules/manager/cocoapods/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -9,7 +9,6 @@ import * as _datasource from '../../datasource'; import type { UpdateArtifactsConfig } from '../types'; import { updateArtifacts } from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/git'); jest.mock('../../../util/fs'); @@ -51,7 +50,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns null if no Podfile.lock found', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); expect( await updateArtifacts({ packageFileName: 'Podfile', @@ -64,7 +63,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns null if no updatedDeps were provided', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); expect( await updateArtifacts({ packageFileName: 'Podfile', @@ -77,7 +76,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns null for invalid local directory', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ localDir: '', }); @@ -94,7 +93,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns null if updatedDeps is empty', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); expect( await updateArtifacts({ packageFileName: 'Podfile', @@ -107,7 +106,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns null if unchanged', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Podfile.lock'); fs.readLocalFile.mockResolvedValueOnce('Current Podfile'); git.getRepoStatus.mockResolvedValueOnce({ @@ -127,7 +126,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns updated Podfile', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.getSiblingFileName.mockReturnValueOnce('Podfile.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Podfile'); @@ -149,7 +148,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns updated Podfile and Pods files', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.getSiblingFileName.mockReturnValueOnce('Podfile.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Podfile.lock'); @@ -180,7 +179,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('catches write error', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('Podfile.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Podfile.lock'); fs.readLocalFile.mockResolvedValueOnce('Current Podfile'); @@ -201,7 +200,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('returns pod exec error', async () => { - const execSnapshots = mockExecAll(exec, new Error('exec exception')); + const execSnapshots = mockExecAll(new Error('exec exception')); fs.getSiblingFileName.mockReturnValueOnce('Podfile.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('Podfile.lock'); fs.readLocalFile.mockResolvedValueOnce('Old Podfile.lock'); @@ -222,7 +221,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('dynamically selects Docker image tag', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); @@ -261,7 +260,7 @@ describe('modules/manager/cocoapods/artifacts', () => { }); it('falls back to the `latest` Docker image tag', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); diff --git a/lib/modules/manager/composer/artifacts.spec.ts b/lib/modules/manager/composer/artifacts.spec.ts index aedf652d8404d9..283d9e6dc2e206 100644 --- a/lib/modules/manager/composer/artifacts.spec.ts +++ b/lib/modules/manager/composer/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git, mocked, partial } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -12,7 +12,6 @@ import { PackagistDatasource } from '../../datasource/packagist'; import type { UpdateArtifactsConfig } from '../types'; import * as composer from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../datasource'); jest.mock('../../../util/fs'); @@ -78,7 +77,7 @@ describe('modules/manager/composer/artifacts', () => { it('returns null if unchanged', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{}'); git.getRepoStatus.mockResolvedValueOnce(repoStatus); GlobalConfig.set({ @@ -131,7 +130,7 @@ describe('modules/manager/composer/artifacts', () => { token: 'abcdef0123456789', }); fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{}'); const authConfig = { ...config, @@ -151,7 +150,7 @@ describe('modules/manager/composer/artifacts', () => { it('returns updated composer.lock', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{}'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -174,7 +173,7 @@ describe('modules/manager/composer/artifacts', () => { const baz = join('vendor/baz/Baz.php'); fs.localPathExists.mockResolvedValueOnce(true); fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, modified: ['composer.lock', foo], @@ -203,7 +202,7 @@ describe('modules/manager/composer/artifacts', () => { it('performs lockFileMaintenance', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -227,7 +226,7 @@ describe('modules/manager/composer/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); @@ -261,7 +260,7 @@ describe('modules/manager/composer/artifacts', () => { it('supports global mode', async () => { GlobalConfig.set({ ...adminConfig, binarySource: 'global' }); fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -331,7 +330,7 @@ describe('modules/manager/composer/artifacts', () => { it('disables ignorePlatformReqs', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -353,7 +352,7 @@ describe('modules/manager/composer/artifacts', () => { it('adds all ignorePlatformReq items', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -377,7 +376,7 @@ describe('modules/manager/composer/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce( '{"packages":[{"name":"symfony/flex","version":"1.17.1"}]}' ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -401,7 +400,7 @@ describe('modules/manager/composer/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce( '{"packages-dev":[{"name":"symfony/flex","version":"1.17.1"}]}' ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{ }'); git.getRepoStatus.mockResolvedValueOnce({ ...repoStatus, @@ -423,7 +422,7 @@ describe('modules/manager/composer/artifacts', () => { it('does not disable plugins when configured globally', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{}'); git.getRepoStatus.mockResolvedValueOnce(repoStatus); GlobalConfig.set({ ...adminConfig, allowPlugins: true }); @@ -440,7 +439,7 @@ describe('modules/manager/composer/artifacts', () => { it('disable plugins when configured locally', async () => { fs.readLocalFile.mockResolvedValueOnce('{}'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('{}'); git.getRepoStatus.mockResolvedValueOnce(repoStatus); GlobalConfig.set({ ...adminConfig, allowPlugins: true }); diff --git a/lib/modules/manager/flux/artifacts.spec.ts b/lib/modules/manager/flux/artifacts.spec.ts index f8a02e7e5f6ffe..35e76714767406 100644 --- a/lib/modules/manager/flux/artifacts.spec.ts +++ b/lib/modules/manager/flux/artifacts.spec.ts @@ -1,9 +1,8 @@ -import { exec, mockExecAll } from '../../../../test/exec-util'; +import { mockExecAll } from '../../../../test/exec-util'; import { fs } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import { updateArtifacts } from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/fs'); describe('modules/manager/flux/artifacts', () => { @@ -14,7 +13,7 @@ describe('modules/manager/flux/artifacts', () => { }); it('replaces existing value', async () => { - const snapshots = mockExecAll(exec, { stdout: '', stderr: '' }); + const snapshots = mockExecAll({ stdout: '', stderr: '' }); fs.readLocalFile.mockResolvedValueOnce('old'); fs.readLocalFile.mockResolvedValueOnce('test'); @@ -61,7 +60,7 @@ describe('modules/manager/flux/artifacts', () => { }); it('ignores unchanged system manifests', async () => { - const execSnapshots = mockExecAll(exec, { stdout: '', stderr: '' }); + const execSnapshots = mockExecAll({ stdout: '', stderr: '' }); fs.readLocalFile.mockResolvedValueOnce('old'); fs.readLocalFile.mockResolvedValueOnce('old'); const res = await updateArtifacts({ @@ -91,7 +90,7 @@ describe('modules/manager/flux/artifacts', () => { }); it('failed to generate system manifest', async () => { - mockExecAll(exec, new Error('failed')); + mockExecAll(new Error('failed')); const res = await updateArtifacts({ packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml', updatedDeps: [{ newVersion: '1.0.1' }], @@ -110,7 +109,7 @@ describe('modules/manager/flux/artifacts', () => { }); it('failed to read system manifest', async () => { - mockExecAll(exec, { stdout: '', stderr: 'Error' }); + mockExecAll({ stdout: '', stderr: 'Error' }); fs.readLocalFile.mockResolvedValueOnce('old'); fs.readLocalFile.mockResolvedValueOnce(''); const res = await updateArtifacts({ diff --git a/lib/modules/manager/gomod/artifacts.spec.ts b/lib/modules/manager/gomod/artifacts.spec.ts index 092bf6af0e6ffb..e82a24a31b2b24 100644 --- a/lib/modules/manager/gomod/artifacts.spec.ts +++ b/lib/modules/manager/gomod/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -10,7 +10,6 @@ import * as _hostRules from '../../../util/host-rules'; import type { UpdateArtifactsConfig } from '../types'; import * as gomod from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/git'); jest.mock('../../../util/host-rules'); @@ -76,7 +75,7 @@ describe('modules/manager/gomod/artifacts', () => { }); it('returns if no go.sum found', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); expect( await gomod.updateArtifacts({ packageFileName: 'go.mod', @@ -92,7 +91,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: [] as string[], } as StatusResult); @@ -112,7 +111,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -135,7 +134,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); fs.readLocalFile.mockResolvedValueOnce('modules.txt content'); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', foo], not_added: [bar], @@ -170,7 +169,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -191,7 +190,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -215,7 +214,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -246,7 +245,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -301,7 +300,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -353,7 +352,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -414,7 +413,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -474,7 +473,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -550,7 +549,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -590,7 +589,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -618,7 +617,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); @@ -641,7 +640,7 @@ describe('modules/manager/gomod/artifacts', () => { }); it('catches errors', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename @@ -670,7 +669,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], } as StatusResult); @@ -702,7 +701,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], } as StatusResult); @@ -732,7 +731,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], } as StatusResult); @@ -760,7 +759,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], } as StatusResult); @@ -787,7 +786,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], } as StatusResult); @@ -822,7 +821,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], } as StatusResult); @@ -857,7 +856,7 @@ describe('modules/manager/gomod/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); // TODO: #7154 can be null fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], } as StatusResult); diff --git a/lib/modules/manager/gradle-wrapper/artifacts.spec.ts b/lib/modules/manager/gradle-wrapper/artifacts.spec.ts index 8132ff32558a9f..1e6a84f64cd947 100644 --- a/lib/modules/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/modules/manager/gradle-wrapper/artifacts.spec.ts @@ -1,7 +1,7 @@ import type { Stats } from 'fs'; import { readFile } from 'fs-extra'; import { resolve } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import * as httpMock from '../../../../test/http-mock'; import { addReplacingSerializer, @@ -17,7 +17,6 @@ import type { StatusResult } from '../../../util/git/types'; import type { UpdateArtifactsConfig } from '../types'; import * as gradleWrapper from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/fs'); jest.mock('../../../util/git'); jest.mock('../../../util/exec/env'); @@ -76,7 +75,7 @@ describe('modules/manager/gradle-wrapper/artifacts', () => { ], } as StatusResult); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const res = await gradleWrapper.updateArtifacts({ packageFileName: 'gradle/wrapper/gradle-wrapper.properties', @@ -122,7 +121,7 @@ describe('modules/manager/gradle-wrapper/artifacts', () => { }); it('gradlew failed', async () => { - const execSnapshots = mockExecAll(exec, new Error('failed')); + const execSnapshots = mockExecAll(new Error('failed')); git.getRepoStatus.mockResolvedValueOnce( partial({ modified: [], @@ -154,7 +153,7 @@ describe('modules/manager/gradle-wrapper/artifacts', () => { }) ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const result = await gradleWrapper.updateArtifacts({ packageFileName: 'gradle-wrapper.properties', diff --git a/lib/modules/manager/helmv3/artifacts.spec.ts b/lib/modules/manager/helmv3/artifacts.spec.ts index 62ab0af27ee7f7..2e2d9558a430ff 100644 --- a/lib/modules/manager/helmv3/artifacts.spec.ts +++ b/lib/modules/manager/helmv3/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { Fixtures } from '../../../../test/fixtures'; import { env, fs, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; @@ -10,7 +10,6 @@ import * as _datasource from '../../datasource'; import type { UpdateArtifactsConfig } from '../types'; import * as helmv3 from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../datasource'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/http'); @@ -73,7 +72,7 @@ describe('modules/manager/helmv3/artifacts', () => { it('returns null if unchanged', async () => { fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as any); fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as any); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -94,7 +93,7 @@ describe('modules/manager/helmv3/artifacts', () => { it('returns updated Chart.lock', async () => { fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -124,7 +123,7 @@ describe('modules/manager/helmv3/artifacts', () => { it('returns updated Chart.lock for lockfile maintenance', async () => { fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -154,7 +153,7 @@ describe('modules/manager/helmv3/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -217,7 +216,7 @@ describe('modules/manager/helmv3/artifacts', () => { ); fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.getParentDir.mockReturnValue(''); expect( @@ -248,7 +247,7 @@ describe('modules/manager/helmv3/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -296,7 +295,7 @@ describe('modules/manager/helmv3/artifacts', () => { fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -346,7 +345,7 @@ describe('modules/manager/helmv3/artifacts', () => { fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -386,7 +385,7 @@ describe('modules/manager/helmv3/artifacts', () => { fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1 as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2 as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' @@ -434,7 +433,7 @@ describe('modules/manager/helmv3/artifacts', () => { it('do not add registryAliases to repository list', async () => { fs.getSiblingFileName.mockReturnValueOnce('Chart.lock'); fs.readLocalFile.mockResolvedValueOnce(ociLockFile1Alias as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(ociLockFile2Alias as never); fs.privateCacheDir.mockReturnValue( '/tmp/renovate/cache/__renovate-private-cache' diff --git a/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts b/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts index 9e7e6cb1d52d3b..29d3fec712b0cf 100644 --- a/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts +++ b/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git, partial } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -7,7 +7,6 @@ import type { StatusResult } from '../../../util/git/types'; import type { UpdateArtifactsConfig } from '../types'; import { updateArtifacts } from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/fs'); jest.mock('../../../util/git'); @@ -40,7 +39,7 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => { it('returns null if there are no changes', async () => { fs.readLocalFile.mockResolvedValueOnce('Current jsonnetfile.lock.json'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce( partial({ modified: [], @@ -64,7 +63,7 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => { it('updates the vendor dir when dependencies change', async () => { fs.readLocalFile.mockResolvedValueOnce('Current jsonnetfile.lock.json'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ not_added: ['vendor/foo/main.jsonnet', 'vendor/bar/main.jsonnet'], modified: ['jsonnetfile.json', 'jsonnetfile.lock.json'], @@ -137,7 +136,7 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => { it('performs lock file maintenance', async () => { fs.readLocalFile.mockResolvedValueOnce('Current jsonnetfile.lock.json'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValueOnce({ modified: ['jsonnetfile.lock.json'], isClean(): boolean { @@ -172,7 +171,7 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => { (execError as any).stderr = 'jb released the magic smoke'; fs.readLocalFile.mockResolvedValueOnce('Current jsonnetfile.lock.json'); - const execSnapshots = mockExecAll(exec, execError); + const execSnapshots = mockExecAll(execError); git.getRepoStatus.mockResolvedValueOnce({ modified: ['jsonnetfile.lock.json'], isClean(): boolean { diff --git a/lib/modules/manager/mix/artifacts.spec.ts b/lib/modules/manager/mix/artifacts.spec.ts index 215320c8c77bbd..781eaed6094721 100644 --- a/lib/modules/manager/mix/artifacts.spec.ts +++ b/lib/modules/manager/mix/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, hostRules } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -7,7 +7,6 @@ import * as docker from '../../../util/exec/docker'; import type { UpdateArtifactsConfig } from '../types'; import { updateArtifacts } from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/fs'); jest.mock('../../../util/host-rules'); @@ -68,7 +67,7 @@ describe('modules/manager/mix/artifacts', () => { it('returns null if unchanged', async () => { fs.readLocalFile.mockResolvedValueOnce('Current mix.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('Current mix.lock'); expect( await updateArtifacts({ @@ -86,7 +85,7 @@ describe('modules/manager/mix/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Old mix.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('New mix.lock'); expect( await updateArtifacts({ @@ -108,7 +107,7 @@ describe('modules/manager/mix/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Old mix.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('New mix.lock'); hostRules.find.mockReturnValueOnce({ token: 'valid_test_token' }); hostRules.find.mockReturnValueOnce({}); @@ -148,7 +147,7 @@ describe('modules/manager/mix/artifacts', () => { it('returns updated mix.lock in subdir', async () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.findLocalSiblingOrParent.mockResolvedValueOnce('subdir/mix.lock'); - mockExecAll(exec); + mockExecAll(); expect( await updateArtifacts({ packageFileName: 'subdir/mix.exs', @@ -181,9 +180,7 @@ describe('modules/manager/mix/artifacts', () => { it('catches exec errors', async () => { fs.readLocalFile.mockResolvedValueOnce('Current mix.lock'); fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock'); - exec.mockImplementationOnce(() => { - throw new Error('exec-error'); - }); + mockExecAll(new Error('exec-error')); expect( await updateArtifacts({ packageFileName: 'mix.exs', diff --git a/lib/modules/manager/npm/post-update/lerna.spec.ts b/lib/modules/manager/npm/post-update/lerna.spec.ts index f7856a6eb2b3c4..8b2277a3226580 100644 --- a/lib/modules/manager/npm/post-update/lerna.spec.ts +++ b/lib/modules/manager/npm/post-update/lerna.spec.ts @@ -1,11 +1,10 @@ -import { envMock, exec, mockExecAll } from '../../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../../test/exec-util'; import { env, partial } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { RepoGlobalConfig } from '../../../../config/types'; import type { PackageFile, PostUpdateConfig } from '../../types'; import * as lernaHelper from './lerna'; -jest.mock('../../../../util/exec/common'); jest.mock('../../../../util/exec/env'); jest.mock('../../npm/post-update/node-version'); @@ -58,7 +57,7 @@ describe('modules/manager/npm/post-update/lerna', () => { }); it('generates package-lock.json files', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const skipInstalls = true; const res = await lernaHelper.generateLockFiles( lernaPkgFile('npm'), @@ -72,7 +71,7 @@ describe('modules/manager/npm/post-update/lerna', () => { }); it('performs full npm install', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const skipInstalls = false; const res = await lernaHelper.generateLockFiles( lernaPkgFile('npm'), @@ -86,7 +85,7 @@ describe('modules/manager/npm/post-update/lerna', () => { }); it('generates yarn.lock files', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const res = await lernaHelper.generateLockFiles( lernaPkgFile('yarn'), 'some-dir', @@ -98,7 +97,7 @@ describe('modules/manager/npm/post-update/lerna', () => { }); it('defaults to latest if lerna version unspecified', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const res = await lernaHelper.generateLockFiles( lernaPkgFileWithoutLernaDep('npm'), 'some-dir', @@ -110,7 +109,7 @@ describe('modules/manager/npm/post-update/lerna', () => { }); it('allows scripts for trust level high', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ ...globalConfig, allowScripts: true }); const res = await lernaHelper.generateLockFiles( lernaPkgFile('npm'), diff --git a/lib/modules/manager/npm/post-update/npm.spec.ts b/lib/modules/manager/npm/post-update/npm.spec.ts index d58cb419f1dbea..9c1d91e04a4821 100644 --- a/lib/modules/manager/npm/post-update/npm.spec.ts +++ b/lib/modules/manager/npm/post-update/npm.spec.ts @@ -1,11 +1,10 @@ import upath from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../../test/exec-util'; import { Fixtures } from '../../../../../test/fixtures'; import { env, fs } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import * as npmHelper from './npm'; -jest.mock('../../../../util/exec/common'); jest.mock('../../../../util/exec/env'); jest.mock('../../../../util/fs'); jest.mock('./node-version'); @@ -19,7 +18,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('generates lock files', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('package-lock-contents'); const skipInstalls = true; const postUpdateOptions = ['npmDedupe']; @@ -40,7 +39,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('performs lock file updates', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('package-lock-contents'); const skipInstalls = true; const updates = [ @@ -60,7 +59,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('performs lock file updates retaining the package.json counterparts', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce( Fixtures.get('update-lockfile-massage-1/package-lock.json') ); @@ -88,7 +87,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('performs npm-shrinkwrap.json updates', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.localPathExists.mockResolvedValueOnce(true); fs.readLocalFile.mockResolvedValueOnce('package-lock-contents'); const skipInstalls = true; @@ -114,7 +113,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('performs npm-shrinkwrap.json updates (no package-lock.json)', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.findLocalSiblingOrParent.mockResolvedValueOnce(null); fs.readLocalFile.mockResolvedValueOnce('package-lock-contents'); const skipInstalls = true; @@ -136,7 +135,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('performs full install', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('package-lock-contents'); const skipInstalls = false; const binarySource = 'global'; @@ -153,7 +152,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('runs twice if remediating', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('package-lock-contents'); const binarySource = 'global'; const res = await npmHelper.generateLockFile( @@ -170,7 +169,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('catches errors', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockImplementation(() => { throw new Error('not found'); }); @@ -186,7 +185,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('finds npm globally', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await npmHelper.generateLockFile( 'some-dir', @@ -199,7 +198,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('uses docker npm', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await npmHelper.generateLockFile( 'some-dir', @@ -213,7 +212,7 @@ describe('modules/manager/npm/post-update/npm', () => { }); it('performs lock file maintenance', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await npmHelper.generateLockFile( 'some-dir', diff --git a/lib/modules/manager/npm/post-update/pnpm.spec.ts b/lib/modules/manager/npm/post-update/pnpm.spec.ts index 233bb5764e825c..2924256993d8b7 100644 --- a/lib/modules/manager/npm/post-update/pnpm.spec.ts +++ b/lib/modules/manager/npm/post-update/pnpm.spec.ts @@ -1,11 +1,10 @@ -import { envMock, exec, mockExecAll } from '../../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../../test/exec-util'; import { Fixtures } from '../../../../../test/fixtures'; import { env, fs, partial } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { PostUpdateConfig } from '../../types'; import * as pnpmHelper from './pnpm'; -jest.mock('../../../../util/exec/common'); jest.mock('../../../../util/exec/env'); jest.mock('../../../../util/fs'); jest.mock('./node-version'); @@ -23,7 +22,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('generates lock files', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await pnpmHelper.generateLockFile('some-dir', {}, config); expect(fs.readLocalFile).toHaveBeenCalledTimes(1); @@ -32,7 +31,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('catches errors', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockImplementation(() => { throw new Error('not found'); }); @@ -44,7 +43,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('finds pnpm globally', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await pnpmHelper.generateLockFile('some-dir', {}, config); expect(fs.readLocalFile).toHaveBeenCalledTimes(1); @@ -53,7 +52,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('performs lock file maintenance', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await pnpmHelper.generateLockFile('some-dir', {}, config, [ { isLockFileMaintenance: true }, @@ -65,7 +64,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('uses the new version if packageManager is updated', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValue('package-lock-contents'); const res = await pnpmHelper.generateLockFile('some-dir', {}, config, [ { @@ -81,7 +80,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('uses constraint version if parent json has constraints', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const configTemp = partial({}); const fileContent = Fixtures.get('parent/package.json'); fs.readLocalFile @@ -123,7 +122,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('uses packageManager version and puts it into constraint', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); const configTemp = partial({}); const fileContent = Fixtures.get('manager-field/package.json'); fs.readLocalFile @@ -165,7 +164,7 @@ describe('modules/manager/npm/post-update/pnpm', () => { }); it('uses skips pnpm v7 if lockfileVersion indicates <7', async () => { - mockExecAll(exec); + mockExecAll(); const configTemp = partial({}); fs.readLocalFile .mockResolvedValueOnce('{}') // package.json diff --git a/lib/modules/manager/npm/post-update/yarn.spec.ts b/lib/modules/manager/npm/post-update/yarn.spec.ts index 8ffd7c3b728906..3798b4e2531a9c 100644 --- a/lib/modules/manager/npm/post-update/yarn.spec.ts +++ b/lib/modules/manager/npm/post-update/yarn.spec.ts @@ -2,7 +2,6 @@ import fs from 'fs-extra'; import { ExecSnapshots, envMock, - exec, mockExecAll, mockExecSequence, } from '../../../../../test/exec-util'; @@ -18,7 +17,6 @@ import * as yarnHelper from './yarn'; jest.mock('fs-extra', () => require('../../../../../test/fixtures').Fixtures.fsExtra() ); -jest.mock('../../../../util/exec/common'); jest.mock('../../../../util/exec/env'); jest.mock('./node-version'); jest.mock('../../../datasource'); @@ -63,7 +61,7 @@ describe('modules/manager/npm/post-update/yarn', () => { '/some-dir' ); GlobalConfig.set({ localDir: '/', cacheDir: '/tmp/cache' }); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: yarnVersion, stderr: '', }); @@ -95,7 +93,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: '3.0.0', stderr: '', }); @@ -123,7 +121,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: '3.0.0', stderr: '', }); @@ -145,7 +143,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: '2.1.0', stderr: '', }); @@ -174,7 +172,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: yarnVersion, stderr: '', }); @@ -209,7 +207,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: yarnVersion, stderr: '', }); @@ -238,7 +236,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: yarnVersion, stderr: '', }); @@ -280,7 +278,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: yarnVersion, stderr: '', }); @@ -323,7 +321,7 @@ describe('modules/manager/npm/post-update/yarn', () => { }, 'some-dir' ); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: yarnVersion, stderr: '', }); @@ -346,7 +344,7 @@ describe('modules/manager/npm/post-update/yarn', () => { it('catches errors', async () => { Fixtures.mock({}); - const execSnapshots = mockExecAll(exec, new Error('some-error')); + const execSnapshots = mockExecAll(new Error('some-error')); const res = await yarnHelper.generateLockFile('some-dir', {}); expect(fs.readFile).toHaveBeenCalledTimes(1); expect(res.error).toBeTrue(); @@ -371,7 +369,7 @@ describe('modules/manager/npm/post-update/yarn', () => { mockedFunction(getPkgReleases).mockResolvedValueOnce({ releases: [{ version: '0.10.0' }], }); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: '2.1.0', stderr: '', }); @@ -419,7 +417,7 @@ describe('modules/manager/npm/post-update/yarn', () => { mockedFunction(getPkgReleases).mockResolvedValueOnce({ releases: [{ version: '1.22.18' }, { version: '2.4.3' }], }); - const execSnapshots = mockExecAll(exec, { + const execSnapshots = mockExecAll({ stdout: '2.1.0', stderr: '', }); @@ -454,7 +452,7 @@ describe('modules/manager/npm/post-update/yarn', () => { mockedFunction(getPkgReleases).mockResolvedValueOnce({ releases: [{ version: '1.22.18' }], }); - const execSnapshots = mockExecSequence(exec, [ + const execSnapshots = mockExecSequence([ { stdout: '', stderr: '' }, { stdout: '', stderr: '' }, { stdout: '', stderr: '' }, @@ -496,7 +494,7 @@ describe('modules/manager/npm/post-update/yarn', () => { mockedFunction(getPkgReleases).mockResolvedValueOnce({ releases: [{ version: '1.22.18' }], }); - const execSnapshots = mockExecAll(exec, { stdout: '', stderr: '' }); + const execSnapshots = mockExecAll({ stdout: '', stderr: '' }); const config = partial>({}); const res = await yarnHelper.generateLockFile('some-dir', {}, config); expect(res.lockFile).toBe(plocktest1YarnLockV1); diff --git a/lib/modules/manager/nuget/artifacts.spec.ts b/lib/modules/manager/nuget/artifacts.spec.ts index 8a51c5752b4c9b..e164e4a2a5418e 100644 --- a/lib/modules/manager/nuget/artifacts.spec.ts +++ b/lib/modules/manager/nuget/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -9,7 +9,6 @@ import type { UpdateArtifactsConfig } from '../types'; import * as util from './util'; import * as nuget from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/fs'); jest.mock('../../../util/host-rules'); @@ -47,7 +46,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('aborts if no lock file found', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); expect( await nuget.updateArtifacts({ @@ -61,7 +60,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('aborts if lock file is unchanged', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce( 'path/with space/packages.lock.json' ); @@ -79,7 +78,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('updates lock file', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -95,7 +94,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('does not update lock file when non-proj file is changed', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -111,7 +110,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('does not update lock file when no deps changed', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -127,7 +126,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('performs lock file maintenance', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -147,7 +146,7 @@ describe('modules/manager/nuget/artifacts', () => { it('supports docker mode', async () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -164,7 +163,7 @@ describe('modules/manager/nuget/artifacts', () => { it('supports global mode', async () => { GlobalConfig.set({ ...adminConfig, binarySource: 'global' }); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -203,7 +202,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('authenticates at registries', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); @@ -237,7 +236,7 @@ describe('modules/manager/nuget/artifacts', () => { }); it('strips protocol version from feed url', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); git.getFile.mockResolvedValueOnce('Current packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json'); diff --git a/lib/modules/manager/pip-compile/artifacts.spec.ts b/lib/modules/manager/pip-compile/artifacts.spec.ts index 8f54c61b1048a4..21a6992dde224d 100644 --- a/lib/modules/manager/pip-compile/artifacts.spec.ts +++ b/lib/modules/manager/pip-compile/artifacts.spec.ts @@ -1,6 +1,6 @@ import _fs from 'fs-extra'; import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { Fixtures } from '../../../../test/fixtures'; import { env, git } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; @@ -13,7 +13,6 @@ import { constructPipCompileCmd } from './artifacts'; import { updateArtifacts } from '.'; jest.mock('fs-extra'); -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/git'); jest.mock('../../../util/host-rules'); @@ -56,7 +55,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('returns null if unchanged', async () => { fs.readFile.mockResolvedValueOnce('content' as any); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('content' as any); expect( await updateArtifacts({ @@ -71,7 +70,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('returns updated requirements.txt', async () => { fs.readFile.mockResolvedValueOnce('current requirements.txt' as any); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); @@ -89,7 +88,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('supports docker mode', async () => { GlobalConfig.set(dockerAdminConfig); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); @@ -126,7 +125,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('returns updated requirements.txt when doing lockfile maintenance', async () => { fs.readFile.mockResolvedValueOnce('Current requirements.txt' as any); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); @@ -144,7 +143,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('uses pipenv version from config', async () => { GlobalConfig.set(dockerAdminConfig); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); diff --git a/lib/modules/manager/pipenv/artifacts.spec.ts b/lib/modules/manager/pipenv/artifacts.spec.ts index 66644c3745d3f4..637c2804e399ad 100644 --- a/lib/modules/manager/pipenv/artifacts.spec.ts +++ b/lib/modules/manager/pipenv/artifacts.spec.ts @@ -1,5 +1,5 @@ import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { env, fs, git } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; @@ -8,7 +8,6 @@ import type { StatusResult } from '../../../util/git/types'; import type { UpdateArtifactsConfig } from '../types'; import * as pipenv from '.'; -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/git'); jest.mock('../../../util/fs'); @@ -63,7 +62,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock)); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock)); expect( await pipenv.updateArtifacts({ @@ -81,7 +80,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce('unparseable pipfile lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('unparseable pipfile lock'); expect( await pipenv.updateArtifacts({ @@ -99,7 +98,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce('current pipfile.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['Pipfile.lock'], } as StatusResult); @@ -122,7 +121,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock)); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['Pipfile.lock'], } as StatusResult); @@ -163,7 +162,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce('Current Pipfile.lock'); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['Pipfile.lock'], } as StatusResult); @@ -186,7 +185,7 @@ describe('modules/manager/pipenv/artifacts', () => { GlobalConfig.set(dockerAdminConfig); pipFileLock.default.pipenv.version = '==2020.8.13'; fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock)); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['Pipfile.lock'], } as StatusResult); @@ -209,7 +208,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock)); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['Pipfile.lock'], } as StatusResult); @@ -232,7 +231,7 @@ describe('modules/manager/pipenv/artifacts', () => { '/tmp/renovate/cache/others/pipenv' ); fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock)); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); git.getRepoStatus.mockResolvedValue({ modified: ['Pipfile.lock'], } as StatusResult); diff --git a/lib/modules/manager/poetry/artifacts.spec.ts b/lib/modules/manager/poetry/artifacts.spec.ts index 073b1d98905a48..a4450781c1b95c 100644 --- a/lib/modules/manager/poetry/artifacts.spec.ts +++ b/lib/modules/manager/poetry/artifacts.spec.ts @@ -1,6 +1,6 @@ import _fs from 'fs-extra'; import { join } from 'upath'; -import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { envMock, mockExecAll } from '../../../../test/exec-util'; import { Fixtures } from '../../../../test/fixtures'; import { env, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; @@ -15,7 +15,6 @@ const pyproject1toml = Fixtures.get('pyproject.1.toml'); const pyproject10toml = Fixtures.get('pyproject.10.toml'); jest.mock('fs-extra'); -jest.mock('../../../util/exec/common'); jest.mock('../../../util/exec/env'); jest.mock('../../datasource'); jest.mock('../../../util/host-rules'); @@ -64,7 +63,7 @@ describe('modules/manager/poetry/artifacts', () => { it('returns null if unchanged', async () => { fs.readFile.mockReturnValueOnce('Current poetry.lock' as any); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('Current poetry.lock' as any); const updatedDeps = [{ depName: 'dep1' }]; expect( @@ -80,7 +79,7 @@ describe('modules/manager/poetry/artifacts', () => { it('returns updated poetry.lock', async () => { fs.readFile.mockResolvedValueOnce('[metadata]\n' as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); const updatedDeps = [{ depName: 'dep1' }]; expect( @@ -98,7 +97,7 @@ describe('modules/manager/poetry/artifacts', () => { // TODO #7154 fs.readFile.mockResolvedValueOnce(null as never); fs.readFile.mockResolvedValueOnce('[metadata]\n' as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); hostRules.find.mockReturnValueOnce({ username: 'usernameOne', @@ -124,7 +123,7 @@ describe('modules/manager/poetry/artifacts', () => { // TODO #7154 fs.readFile.mockResolvedValueOnce(null as never); fs.readFile.mockResolvedValueOnce(Buffer.from('[metadata]\n')); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockResolvedValueOnce(Buffer.from('New poetry.lock')); hostRules.find.mockImplementation((search) => ({ password: @@ -150,7 +149,7 @@ describe('modules/manager/poetry/artifacts', () => { // TODO #7154 fs.readFile.mockResolvedValueOnce(null as never); fs.readFile.mockResolvedValueOnce('[metadata]\n' as never); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); const updatedDeps = [{ depName: 'dep1' }]; expect( @@ -168,7 +167,7 @@ describe('modules/manager/poetry/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); // poetry.lock fs.readFile.mockResolvedValueOnce('[metadata]\n' as any); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); // poetry datasource.getPkgReleases.mockResolvedValueOnce({ @@ -205,7 +204,7 @@ describe('modules/manager/poetry/artifacts', () => { fs.readFile.mockResolvedValueOnce( '[metadata]\npython-versions = "~2.7 || ^3.4"' as any ); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); // poetry datasource.getPkgReleases.mockResolvedValueOnce({ @@ -252,7 +251,7 @@ describe('modules/manager/poetry/artifacts', () => { it('returns updated poetry.lock when doing lockfile maintenance', async () => { fs.readFile.mockResolvedValueOnce('Old poetry.lock' as any); - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); expect( await updateArtifacts({ diff --git a/lib/util/exec/docker/index.spec.ts b/lib/util/exec/docker/index.spec.ts index c379bf74ae321f..c8f7fe6db0c8c3 100644 --- a/lib/util/exec/docker/index.spec.ts +++ b/lib/util/exec/docker/index.spec.ts @@ -1,8 +1,4 @@ -import { - exec, - mockExecAll, - mockExecSequence, -} from '../../../../test/exec-util'; +import { mockExecAll, mockExecSequence } from '../../../../test/exec-util'; import { GlobalConfig } from '../../../config/global'; import { SYSTEM_INSUFFICIENT_MEMORY } from '../../../constants/error-messages'; import { logger } from '../../../logger'; @@ -17,8 +13,6 @@ import { resetPrefetchedImages, } from '.'; -jest.mock('../common'); - const getPkgReleases: jest.Mock = _getPkgReleases as any; jest.mock('../../../modules/datasource'); @@ -34,13 +28,13 @@ describe('util/exec/docker/index', () => { }); it('runs prefetch command', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); await prefetchDockerImage('foo:1.2.3'); expect(execSnapshots).toMatchObject([{ cmd: 'docker pull foo:1.2.3' }]); }); it('performs prefetch once for each image', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); await prefetchDockerImage('foo:1.0.0'); await prefetchDockerImage('foo:2.0.0'); await prefetchDockerImage('bar:3.0.0'); @@ -110,25 +104,22 @@ describe('util/exec/docker/index', () => { describe('removeDockerContainer', () => { it('gracefully handles container list error', async () => { - mockExecAll(exec, new Error('unknown')); + mockExecAll(new Error('unknown')); await expect(removeDockerContainer('bar', 'foo_')).resolves.not.toThrow(); }); it('gracefully handles container removal error', async () => { - mockExecSequence(exec, [ - { stdout: '12345', stderr: '' }, - new Error('unknown'), - ]); + mockExecSequence([{ stdout: '12345', stderr: '' }, new Error('unknown')]); await expect(removeDockerContainer('bar', 'foo_')).resolves.not.toThrow(); }); it('gracefully handles empty container list', async () => { - mockExecAll(exec, { stdout: '\n', stderr: '' }); + mockExecAll({ stdout: '\n', stderr: '' }); await expect(removeDockerContainer('bar', 'foo_')).resolves.not.toThrow(); }); it('runs Docker commands for container removal', async () => { - const execSnapshots = mockExecSequence(exec, [ + const execSnapshots = mockExecSequence([ { stdout: '12345', stderr: '' }, { stdout: '', stderr: '' }, ]); @@ -146,7 +137,7 @@ describe('util/exec/docker/index', () => { }); it('short-circuits in non-Docker environment', async () => { - const execSnapshots = mockExecAll(exec); + const execSnapshots = mockExecAll(); GlobalConfig.set({ binarySource: 'global' }); await removeDanglingContainers(); expect(execSnapshots).toBeEmpty(); @@ -155,7 +146,7 @@ describe('util/exec/docker/index', () => { it('handles insufficient memory error', async () => { const err: Error & { errno: string } = new Error() as never; err.errno = 'ENOMEM'; - mockExecAll(exec, err); + mockExecAll(err); await expect(removeDanglingContainers).rejects.toThrow( SYSTEM_INSUFFICIENT_MEMORY ); @@ -164,7 +155,7 @@ describe('util/exec/docker/index', () => { it('handles missing Docker daemon', async () => { const err: Error & { stderr: string } = new Error() as never; err.stderr = 'Cannot connect to the Docker daemon'; - const execSnapshots = mockExecAll(exec, err); + const execSnapshots = mockExecAll(err); await removeDanglingContainers(); expect(execSnapshots).toMatchObject([ { cmd: 'docker ps --filter label=renovate_child -aq' }, @@ -174,7 +165,7 @@ describe('util/exec/docker/index', () => { }); it('handles unknown error', async () => { - const execSnapshots = mockExecAll(exec, new Error('unknown')); + const execSnapshots = mockExecAll(new Error('unknown')); await removeDanglingContainers(); expect(execSnapshots).toMatchObject([ { cmd: 'docker ps --filter label=renovate_child -aq' }, @@ -184,7 +175,7 @@ describe('util/exec/docker/index', () => { }); it('handles empty container list ', async () => { - const execSnapshots = mockExecAll(exec, { stdout: '\n\n\n', stderr: '' }); + const execSnapshots = mockExecAll({ stdout: '\n\n\n', stderr: '' }); await removeDanglingContainers(); expect(execSnapshots).toMatchObject([ { cmd: 'docker ps --filter label=renovate_child -aq' }, @@ -195,7 +186,7 @@ describe('util/exec/docker/index', () => { }); it('removes containers', async () => { - const execSnapshots = mockExecSequence(exec, [ + const execSnapshots = mockExecSequence([ { stdout: '111\n222\n333', stderr: '' }, { stdout: '', stderr: '' }, ]); @@ -233,7 +224,7 @@ describe('util/exec/docker/index', () => { }); it('returns executable command', async () => { - mockExecAll(exec); + mockExecAll(); const res = await generateDockerCommand( commands, preCommands, @@ -243,7 +234,7 @@ describe('util/exec/docker/index', () => { }); it('handles volumes', async () => { - mockExecAll(exec); + mockExecAll(); const volumes: VolumeOption[] = [ '/tmp/foo', ['/tmp/bar', `/tmp/bar`], @@ -262,7 +253,7 @@ describe('util/exec/docker/index', () => { }); it('handles tag parameter', async () => { - mockExecAll(exec); + mockExecAll(); const res = await generateDockerCommand(commands, preCommands, { ...dockerOptions, tag: '1.2.3', @@ -271,7 +262,7 @@ describe('util/exec/docker/index', () => { }); it('handles tag constraint', async () => { - mockExecAll(exec); + mockExecAll(); getPkgReleases.mockResolvedValueOnce({ releases: [ { version: '1.2.3' }, diff --git a/lib/util/exec/index.spec.ts b/lib/util/exec/index.spec.ts index 50c13be64ee7a9..3726adf0500357 100644 --- a/lib/util/exec/index.spec.ts +++ b/lib/util/exec/index.spec.ts @@ -1,8 +1,4 @@ -import { - ExecOptions as ChildProcessExecOptions, - exec as _cpExec, -} from 'child_process'; -import { envMock } from '../../../test/exec-util'; +import { exec as cpExec, envMock } from '../../../test/exec-util'; import { GlobalConfig } from '../../config/global'; import type { RepoGlobalConfig } from '../../config/types'; import { TEMPORARY_ERROR } from '../../constants/error-messages'; @@ -10,9 +6,6 @@ import * as dockerModule from './docker'; import type { ExecOptions, RawExecOptions, VolumeOption } from './types'; import { exec } from '.'; -const cpExec: jest.Mock = _cpExec as any; - -jest.mock('child_process'); jest.mock('../../modules/datasource'); interface TestInput { @@ -732,12 +725,12 @@ describe('util/exec/index', () => { process.env = procEnv; const actualCmd: string[] = []; - const actualOpts: ChildProcessExecOptions[] = []; - cpExec.mockImplementation((execCmd, execOpts, callback) => { + const actualOpts: RawExecOptions[] = []; + cpExec.mockImplementation((execCmd, execOpts) => { actualCmd.push(execCmd); actualOpts.push(execOpts); - callback(null, { stdout: '', stderr: '' }); - return undefined as never; + + return Promise.resolve({ stdout: '', stderr: '' }); }); GlobalConfig.set({ ...globalConfig, localDir: cwd, ...adminConfig }); await exec(cmd as string, inOpts); @@ -750,10 +743,9 @@ describe('util/exec/index', () => { process.env = processEnv; const actualCmd: string[] = []; - cpExec.mockImplementation((execCmd, execOpts, callback) => { + cpExec.mockImplementation((execCmd) => { actualCmd.push(execCmd); - callback(null, { stdout: '', stderr: '' }); - return undefined as never; + return Promise.resolve({ stdout: '', stderr: '' }); }); GlobalConfig.set({ ...globalConfig, binarySource: 'global' }); diff --git a/test/exec-util.ts b/test/exec-util.ts index 7d14937527acc4..ff9a2269eba81c 100644 --- a/test/exec-util.ts +++ b/test/exec-util.ts @@ -2,25 +2,24 @@ import is from '@sindresorhus/is'; import traverse from 'traverse'; import upath from 'upath'; import { rawExec as _exec } from '../lib/util/exec/common'; -import type { ExecOptions } from '../lib/util/exec/types'; +import type { RawExecOptions } from '../lib/util/exec/types'; import { regEx } from '../lib/util/regex'; +import { mockedFunction } from './util'; -type CallOptions = ExecOptions | null | undefined; +jest.mock('../lib/util/exec/common'); export type ExecResult = { stdout: string; stderr: string } | Error; -// TODO: fix type #7154 -export type ExecMock = jest.Mock; -export const exec: ExecMock = _exec as any; +export const exec = mockedFunction(_exec); -interface ExecSnapshot { +export interface ExecSnapshot { cmd: string; - options?: ExecOptions | null | undefined; + options?: RawExecOptions | null | undefined; } export type ExecSnapshots = ExecSnapshot[]; -export function execSnapshot(cmd: string, options?: CallOptions): ExecSnapshot { +function execSnapshot(cmd: string, options?: RawExecOptions): ExecSnapshot { const snapshot = { cmd, options, @@ -41,11 +40,10 @@ export function execSnapshot(cmd: string, options?: CallOptions): ExecSnapshot { const defaultExecResult = { stdout: '', stderr: '' }; export function mockExecAll( - execFn: ExecMock, execResult: ExecResult = defaultExecResult ): ExecSnapshots { const snapshots: ExecSnapshots = []; - execFn.mockImplementation((cmd, options) => { + exec.mockImplementation((cmd, options) => { snapshots.push(execSnapshot(cmd, options)); if (execResult instanceof Error) { throw execResult; @@ -55,13 +53,10 @@ export function mockExecAll( return snapshots; } -export function mockExecSequence( - execFn: ExecMock, - execResults: ExecResult[] -): ExecSnapshots { +export function mockExecSequence(execResults: ExecResult[]): ExecSnapshots { const snapshots: ExecSnapshots = []; execResults.forEach((execResult) => { - execFn.mockImplementationOnce((cmd, options) => { + exec.mockImplementationOnce((cmd, options) => { snapshots.push(execSnapshot(cmd, options)); if (execResult instanceof Error) { throw execResult;