refactor(util/exec): change mocked modules in existing tests (#16519)

This commit is contained in:
Gabriel-Ladzaretti 2022-07-11 12:41:24 +03:00 committed by GitHub
parent e10aa6aa5a
commit 6202b1c264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 24 additions and 26 deletions

View file

@ -14,7 +14,7 @@ const datasource = mocked(_datasource);
const bundlerHostRules = mocked(_bundlerHostRules);
jest.mock('fs-extra');
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../datasource');
jest.mock('../../../util/fs');

View file

@ -7,7 +7,7 @@ import * as docker from '../../../util/exec/docker';
import type { UpdateArtifactsConfig } from '../types';
import * as cargo from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/git');
jest.mock('../../../util/http');

View file

@ -9,7 +9,7 @@ import * as _datasource from '../../datasource';
import type { UpdateArtifactsConfig } from '../types';
import { updateArtifacts } from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/git');
jest.mock('../../../util/fs');

View file

@ -12,7 +12,7 @@ import { PackagistDatasource } from '../../datasource/packagist';
import type { UpdateArtifactsConfig } from '../types';
import * as composer from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../datasource');
jest.mock('../../../util/fs');

View file

@ -3,7 +3,7 @@ import { fs } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import { updateArtifacts } from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/fs');
describe('modules/manager/flux/artifacts', () => {

View file

@ -10,7 +10,7 @@ import * as _hostRules from '../../../util/host-rules';
import type { UpdateArtifactsConfig } from '../types';
import * as gomod from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/git');
jest.mock('../../../util/host-rules');

View file

@ -17,7 +17,7 @@ import type { StatusResult } from '../../../util/git/types';
import type { UpdateArtifactsConfig } from '../types';
import * as gradleWrapper from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/fs');
jest.mock('../../../util/git');
jest.mock('../../../util/exec/env');

View file

@ -10,7 +10,7 @@ import * as _datasource from '../../datasource';
import type { UpdateArtifactsConfig } from '../types';
import * as helmv3 from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../datasource');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/http');

View file

@ -7,7 +7,7 @@ import type { StatusResult } from '../../../util/git/types';
import type { UpdateArtifactsConfig } from '../types';
import { updateArtifacts } from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/fs');
jest.mock('../../../util/git');

View file

@ -7,7 +7,7 @@ import * as docker from '../../../util/exec/docker';
import type { UpdateArtifactsConfig } from '../types';
import { updateArtifacts } from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/fs');
jest.mock('../../../util/host-rules');

View file

@ -5,7 +5,7 @@ import type { RepoGlobalConfig } from '../../../../config/types';
import type { PackageFile, PostUpdateConfig } from '../../types';
import * as lernaHelper from './lerna';
jest.mock('child_process');
jest.mock('../../../../util/exec/common');
jest.mock('../../../../util/exec/env');
jest.mock('../../npm/post-update/node-version');

View file

@ -5,7 +5,7 @@ import { env, fs } from '../../../../../test/util';
import { GlobalConfig } from '../../../../config/global';
import * as npmHelper from './npm';
jest.mock('child_process');
jest.mock('../../../../util/exec/common');
jest.mock('../../../../util/exec/env');
jest.mock('../../../../util/fs');
jest.mock('./node-version');

View file

@ -5,7 +5,7 @@ import { GlobalConfig } from '../../../../config/global';
import type { PostUpdateConfig } from '../../types';
import * as pnpmHelper from './pnpm';
jest.mock('child_process');
jest.mock('../../../../util/exec/common');
jest.mock('../../../../util/exec/env');
jest.mock('../../../../util/fs');
jest.mock('./node-version');

View file

@ -18,7 +18,7 @@ import * as yarnHelper from './yarn';
jest.mock('fs-extra', () =>
require('../../../../../test/fixtures').Fixtures.fsExtra()
);
jest.mock('child_process');
jest.mock('../../../../util/exec/common');
jest.mock('../../../../util/exec/env');
jest.mock('./node-version');
jest.mock('../../../datasource');

View file

@ -9,7 +9,7 @@ import type { UpdateArtifactsConfig } from '../types';
import * as util from './util';
import * as nuget from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/fs');
jest.mock('../../../util/host-rules');

View file

@ -13,7 +13,7 @@ import { constructPipCompileCmd } from './artifacts';
import { updateArtifacts } from '.';
jest.mock('fs-extra');
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/git');
jest.mock('../../../util/host-rules');

View file

@ -8,7 +8,7 @@ import type { StatusResult } from '../../../util/git/types';
import type { UpdateArtifactsConfig } from '../types';
import * as pipenv from '.';
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../../util/git');
jest.mock('../../../util/fs');

View file

@ -15,7 +15,7 @@ const pyproject1toml = Fixtures.get('pyproject.1.toml');
const pyproject10toml = Fixtures.get('pyproject.10.toml');
jest.mock('fs-extra');
jest.mock('child_process');
jest.mock('../../../util/exec/common');
jest.mock('../../../util/exec/env');
jest.mock('../../datasource');
jest.mock('../../../util/host-rules');

View file

@ -17,7 +17,7 @@ import {
resetPrefetchedImages,
} from '.';
jest.mock('child_process');
jest.mock('../common');
const getPkgReleases: jest.Mock<typeof _getPkgReleases> =
_getPkgReleases as any;

View file

@ -1,7 +1,7 @@
import { exec as _exec } from 'child_process';
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 { regEx } from '../lib/util/regex';
@ -45,13 +45,12 @@ export function mockExecAll(
execResult: ExecResult = defaultExecResult
): ExecSnapshots {
const snapshots: ExecSnapshots = [];
execFn.mockImplementation((cmd, options, callback) => {
execFn.mockImplementation((cmd, options) => {
snapshots.push(execSnapshot(cmd, options));
if (execResult instanceof Error) {
throw execResult;
}
callback(null, execResult);
return undefined as never;
return execResult as never;
});
return snapshots;
}
@ -62,13 +61,12 @@ export function mockExecSequence(
): ExecSnapshots {
const snapshots: ExecSnapshots = [];
execResults.forEach((execResult) => {
execFn.mockImplementationOnce((cmd, options, callback) => {
execFn.mockImplementationOnce((cmd, options) => {
snapshots.push(execSnapshot(cmd, options));
if (execResult instanceof Error) {
throw execResult;
}
callback(null, execResult);
return undefined as never;
return execResult as never;
});
});
return snapshots;