Skip to content

Commit

Permalink
test: modernize code (#17470)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
  • Loading branch information
viceice and JamieMagee committed Aug 30, 2022
1 parent 6a93997 commit 4c52a27
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 50 deletions.
6 changes: 3 additions & 3 deletions lib/config/secrets.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig } from '../../test/util';
import { getConfig } from '../../test/util';
import {
CONFIG_SECRETS_INVALID,
CONFIG_VALIDATION,
Expand All @@ -8,7 +8,7 @@ import { applySecretsToConfig, validateConfigSecrets } from './secrets';
describe('config/secrets', () => {
describe('validateConfigSecrets(config)', () => {
it('works with default config', () => {
expect(() => validateConfigSecrets(defaultConfig)).not.toThrow();
expect(() => validateConfigSecrets(getConfig())).not.toThrow();
});

it('returns if no secrets', () => {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('config/secrets', () => {

describe('applySecretsToConfig(config)', () => {
it('works with default config', () => {
expect(() => applySecretsToConfig(defaultConfig)).not.toThrow();
expect(() => applySecretsToConfig(getConfig())).not.toThrow();
});

it('throws if disallowed field is used', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/config-migration/branch/rebase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fixtures } from '../../../../../test/fixtures';
import {
RenovateConfig,
defaultConfig,
getConfig,
git,
platform,
} from '../../../../../test/util';
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('workers/repository/config-migration/branch/rebase', () => {
GlobalConfig.reset();
migratedConfigData = { content: renovateConfig, filename };
config = {
...defaultConfig,
...getConfig(),
repository: 'some/repo',
};
});
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/config-migration/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import { defaultConfig, mockedFunction } from '../../../../test/util';
import { getConfig, mockedFunction } from '../../../../test/util';
import { checkConfigMigrationBranch } from './branch';
import { MigratedDataFactory } from './branch/migrated-data';
import { ensureConfigMigrationPr } from './pr';
Expand All @@ -13,7 +13,7 @@ const content = Fixtures.getJson('./migrated-data.json', './branch');
const filename = 'renovate.json';
const branchName = 'renovate/config-migration';
const config = {
...defaultConfig,
...getConfig(),
configMigration: true,
};

Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/extract/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig, git, mocked } from '../../../../test/util';
import { getConfig, git, mocked } from '../../../../test/util';
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import * as _managerFiles from './manager-files';
Expand All @@ -17,7 +17,7 @@ describe('workers/repository/extract/index', () => {
beforeEach(() => {
jest.resetAllMocks();
git.getFileList.mockResolvedValue(fileList);
config = { ...defaultConfig };
config = getConfig();
});

it('runs', async () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/vulnerability.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
RenovateConfig,
defaultConfig,
getConfig,
partial,
platform,
} from '../../../../test/util';
Expand All @@ -12,7 +12,7 @@ let config: RenovateConfig;

beforeEach(() => {
jest.resetAllMocks();
config = JSON.parse(JSON.stringify(defaultConfig));
config = getConfig();
});

describe('workers/repository/init/vulnerability', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/onboarding/branch/rebase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
RenovateConfig,
defaultConfig,
getConfig,
git,
platform,
} from '../../../../../test/util';
Expand All @@ -22,7 +22,7 @@ describe('workers/repository/onboarding/branch/rebase', () => {
beforeEach(() => {
jest.resetAllMocks();
config = {
...defaultConfig,
...getConfig(),
repository: 'some/repo',
};
});
Expand All @@ -35,7 +35,7 @@ describe('workers/repository/onboarding/branch/rebase', () => {

it('does nothing if branch is up to date', async () => {
const contents =
JSON.stringify(defaultConfig.onboardingConfig, null, 2) + '\n';
JSON.stringify(getConfig().onboardingConfig, null, 2) + '\n';
git.getFile
.mockResolvedValueOnce(contents) // package.json
.mockResolvedValueOnce(contents); // renovate.json
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/onboarding/pr/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestError, Response } from 'got';
import {
RenovateConfig,
defaultConfig,
getConfig,
git,
partial,
platform,
Expand All @@ -28,7 +28,7 @@ describe('workers/repository/onboarding/pr/index', () => {
beforeEach(() => {
jest.resetAllMocks();
config = {
...defaultConfig,
...getConfig(),
errors: [],
warnings: [],
description: [],
Expand Down
10 changes: 5 additions & 5 deletions lib/workers/repository/update/branch/auto-replace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fixtures } from '../../../../../test/fixtures';
import { defaultConfig } from '../../../../../test/util';
import { getConfig, partial } from '../../../../../test/util';
import { GlobalConfig } from '../../../../config/global';
import { WORKER_FILE_UPDATE_FAILED } from '../../../../constants/error-messages';
import { extractPackageFile } from '../../../../modules/manager/html';
Expand All @@ -25,12 +25,12 @@ describe('workers/repository/update/branch/auto-replace', () => {
});

beforeEach(() => {
upgrade = {
// TODO: fix type #7154
...JSON.parse(JSON.stringify(defaultConfig)),
upgrade = partial<BranchUpgradeConfig>({
// TODO: fix types (#7154)
...(getConfig() as any),
manager: 'html',
packageFile: 'test',
};
});
reuseExistingBranch = false;
});

Expand Down
6 changes: 2 additions & 4 deletions lib/workers/repository/update/branch/automerge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig, git, platform } from '../../../../../test/util';
import { getConfig, git, platform } from '../../../../../test/util';
import { GlobalConfig } from '../../../../config/global';
import type { RenovateConfig } from '../../../../config/types';
import { BranchStatus } from '../../../../types';
Expand All @@ -13,9 +13,7 @@ describe('workers/repository/update/branch/automerge', () => {
let config: RenovateConfig;

beforeEach(() => {
config = {
...defaultConfig,
};
config = getConfig();
GlobalConfig.reset();
});

Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/update/branch/check-existing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig, partial, platform } from '../../../../../test/util';
import { getConfig, partial, platform } from '../../../../../test/util';
import { logger } from '../../../../logger';
import type { Pr } from '../../../../modules/platform';
import { PrState } from '../../../../types';
Expand All @@ -10,9 +10,9 @@ describe('workers/repository/update/branch/check-existing', () => {
let config: BranchConfig;

beforeEach(() => {
// TODO #7154 incompatible types
// TODO: incompatible types (#7154)
config = {
...defaultConfig,
...getConfig(),
branchName: 'some-branch',
prTitle: 'some-title',
} as BranchConfig;
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/update/branch/commit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
defaultConfig,
getConfig,
git,
mockedFunction,
platform,
Expand All @@ -15,9 +15,9 @@ describe('workers/repository/update/branch/commit', () => {
let config: BranchConfig;

beforeEach(() => {
// TODO #7154 incompatible types
// TODO: incompatible types (#7154)
config = {
...defaultConfig,
...getConfig(),
branchName: 'renovate/some-branch',
commitMessage: 'some commit message',
semanticCommits: 'disabled',
Expand Down
7 changes: 4 additions & 3 deletions lib/workers/repository/update/branch/get-updated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig, git, mocked } from '../../../../../test/util';
import { getConfig, git, mocked } from '../../../../../test/util';
import { GitRefsDatasource } from '../../../../modules/datasource/git-refs';
import * as _composer from '../../../../modules/manager/composer';
import * as _gitSubmodules from '../../../../modules/manager/git-submodules';
Expand Down Expand Up @@ -29,10 +29,11 @@ describe('workers/repository/update/branch/get-updated', () => {
let config: BranchConfig;

beforeEach(() => {
// TODO: incompatible types (#7154)
config = {
...defaultConfig,
...getConfig(),
upgrades: [],
} as never;
} as BranchConfig;
npm.updateDependency = jest.fn();
git.getFile.mockResolvedValueOnce('existing content');
});
Expand Down
19 changes: 10 additions & 9 deletions lib/workers/repository/update/branch/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
defaultConfig,
fs,
getConfig,
git,
mocked,
mockedFunction,
Expand Down Expand Up @@ -100,8 +100,9 @@ describe('workers/repository/update/branch/index', () => {
git.branchExists.mockReturnValue(false);
prWorker.ensurePr = jest.fn();
prAutomerge.checkAutoMerge = jest.fn();
// TODO: incompatible types (#7154)
config = {
...defaultConfig,
...getConfig(),
branchName: 'renovate/some-branch',
errors: [],
warnings: [],
Expand Down Expand Up @@ -1294,7 +1295,7 @@ describe('workers/repository/update/branch/index', () => {
},
upgrades: [
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name',
postUpgradeTasks: {
executionMode: 'update',
Expand Down Expand Up @@ -1384,7 +1385,7 @@ describe('workers/repository/update/branch/index', () => {
...config,
upgrades: [
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name',
postUpgradeTasks: {
commands: ['exit 1'],
Expand Down Expand Up @@ -1468,7 +1469,7 @@ describe('workers/repository/update/branch/index', () => {
},
upgrades: [
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name',
postUpgradeTasks: {
executionMode: 'update',
Expand Down Expand Up @@ -1572,7 +1573,7 @@ describe('workers/repository/update/branch/index', () => {
},
upgrades: [
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name-1',
postUpgradeTasks: {
executionMode: 'update',
Expand All @@ -1586,7 +1587,7 @@ describe('workers/repository/update/branch/index', () => {
},
} as BranchUpgradeConfig,
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name-2',
postUpgradeTasks: {
executionMode: 'update',
Expand Down Expand Up @@ -1718,7 +1719,7 @@ describe('workers/repository/update/branch/index', () => {
},
upgrades: [
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name-1',
postUpgradeTasks: {
executionMode: 'branch',
Expand All @@ -1732,7 +1733,7 @@ describe('workers/repository/update/branch/index', () => {
},
} as BranchUpgradeConfig,
{
...defaultConfig,
...getConfig(),
depName: 'some-dep-name-2',
postUpgradeTasks: {
executionMode: 'branch',
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/update/branch/status-checks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig, platform } from '../../../../../test/util';
import { getConfig, platform } from '../../../../../test/util';
import { BranchStatus } from '../../../../types';
import {
ConfidenceConfig,
Expand All @@ -14,7 +14,7 @@ describe('workers/repository/update/branch/status-checks', () => {

beforeEach(() => {
config = {
...defaultConfig,
...getConfig(),
branchName: 'renovate/some-branch',
};
});
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('workers/repository/update/branch/status-checks', () => {

beforeEach(() => {
config = {
...defaultConfig,
...getConfig(),
branchName: 'renovate/some-branch',
};
});
Expand Down
7 changes: 5 additions & 2 deletions lib/workers/repository/updates/generate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { defaultConfig } from '../../../../test/util';
import type { UpdateType } from '../../../config/types';
import { getConfig } from '../../../../test/util';
import type { RenovateConfig, UpdateType } from '../../../config/types';
import { NpmDatasource } from '../../../modules/datasource/npm';
import type { BranchUpgradeConfig } from '../../types';
import { generateBranchConfig } from './generate';

let defaultConfig: RenovateConfig;

beforeEach(() => {
jest.resetAllMocks();
defaultConfig = getConfig();
});

describe('workers/repository/updates/generate', () => {
Expand Down
2 changes: 0 additions & 2 deletions test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export const logger = mocked(_logger);

export type { RenovateConfig };

export const defaultConfig = getConfig();

export { getConfig };

function getCallerFileName(): string | null {
Expand Down

0 comments on commit 4c52a27

Please sign in to comment.