Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

test: simplify exec mock #16698

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/modules/manager/bundler/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions lib/modules/manager/cargo/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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';
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');
Expand Down Expand Up @@ -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');

Expand All @@ -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 = [
Expand All @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand All @@ -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(
Expand All @@ -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 = [
Expand Down
25 changes: 12 additions & 13 deletions lib/modules/manager/cocoapods/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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: '',
});
Expand All @@ -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',
Expand All @@ -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({
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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' });

Expand Down Expand Up @@ -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' });

Expand Down
Loading