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

feat(test): Detect test utils callers and simplify helpers #9707

Merged
merged 2 commits into from Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/config/cli.spec.ts
Expand Up @@ -4,7 +4,7 @@ import * as cli from './cli';
import getArgv from './config/__fixtures__/argv';
import type { RenovateOptions } from './types';

describe(getName(__filename), () => {
describe(getName(), () => {
let argv: string[];
beforeEach(() => {
argv = getArgv();
Expand Down
4 changes: 2 additions & 2 deletions lib/config/decrypt.spec.ts
Expand Up @@ -3,9 +3,9 @@ import { setAdminConfig } from './admin';
import { decryptConfig } from './decrypt';
import type { RenovateConfig } from './types';

const privateKey = loadFixture(__filename, 'private.pem', 'keys');
const privateKey = loadFixture('private.pem', 'keys');

describe(getName(__filename), () => {
describe(getName(), () => {
describe('decryptConfig()', () => {
let config: RenovateConfig;
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/definitions.spec.ts
Expand Up @@ -5,7 +5,7 @@ jest.mock('../manager', () => ({
getManagers: jest.fn(() => new Map().set('testManager', {})),
}));

describe(getName(__filename), () => {
describe(getName(), () => {
it('test manager should have no defaultConfig', () => {
const opts = getOptions();
expect(opts.filter((o) => o.name === 'testManager')).toEqual([]);
Expand Down
2 changes: 1 addition & 1 deletion lib/config/env.spec.ts
Expand Up @@ -6,7 +6,7 @@ import {
import * as env from './env';
import type { RenovateOptions } from './types';

describe(getName(__filename), () => {
describe(getName(), () => {
describe('.getConfig(env)', () => {
it('returns empty env', () => {
expect(env.getConfig({})).toEqual({ hostRules: [] });
Expand Down
2 changes: 1 addition & 1 deletion lib/config/file.spec.ts
Expand Up @@ -5,7 +5,7 @@ import { getName } from '../../test/util';
import customConfig from './config/__fixtures__/file';
import * as file from './file';

describe(getName(__filename), () => {
describe(getName(), () => {
let tmp: DirectoryResult;

beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/index.spec.ts
Expand Up @@ -13,7 +13,7 @@ try {

const defaultConfig = getConfig();

describe(getName(__filename), () => {
describe(getName(), () => {
describe('.parseConfigs(env, defaultArgv)', () => {
let configParser: typeof import('.');
let defaultArgv: string[];
Expand Down
2 changes: 1 addition & 1 deletion lib/config/massage.spec.ts
Expand Up @@ -2,7 +2,7 @@ import { getName } from '../../test/util';
import * as massage from './massage';
import type { RenovateConfig } from './types';

describe(getName(__filename), () => {
describe(getName(), () => {
describe('massageConfig', () => {
it('returns empty', () => {
const config: RenovateConfig = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/config/migrate-validate.spec.ts
Expand Up @@ -7,7 +7,7 @@ beforeEach(() => {
config = getConfig();
});

describe(getName(__filename), () => {
describe(getName(), () => {
describe('migrateAndValidate()', () => {
it('handles empty', async () => {
const res = await migrateAndValidate(config, {});
Expand Down
2 changes: 1 addition & 1 deletion lib/config/migration.spec.ts
Expand Up @@ -14,7 +14,7 @@ interface RenovateConfig extends _RenovateConfig {
node?: RenovateSharedConfig & { supportPolicy?: unknown };
}

describe(getName(__filename), () => {
describe(getName(), () => {
describe('migrateConfig(config, parentConfig)', () => {
it('migrates config', () => {
const config: RenovateConfig = {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/azure/index.spec.ts
Expand Up @@ -10,7 +10,7 @@ jest.mock('../../../platform/azure/azure-got-wrapper');

const azureApi = mocked(_azureApi);

describe(getName(__filename), () => {
describe(getName(), () => {
beforeAll(() => {
setPlatformApi('azure');
});
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/bitbucket-server/index.spec.ts
Expand Up @@ -11,7 +11,7 @@ const hostRules = mocked(_hostRules);
const bitbucketApiHost = 'https://git.company.org';
const basePath = '/rest/api/1.0/projects/some/repos/repo/browse';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.setup();
hostRules.find.mockReturnValue({ token: 'abc' });
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/bitbucket/index.spec.ts
Expand Up @@ -9,7 +9,7 @@ jest.unmock('../../../platform');
const baseUrl = 'https://api.bitbucket.org';
const basePath = '/2.0/repositories/some/repo/src/HEAD';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeAll(() => {
setPlatformApi('bitbucket');
});
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/gitea/index.spec.ts
Expand Up @@ -12,7 +12,7 @@ const hostRules = mocked(_hostRules);
const giteaApiHost = gitea.Endpoint;
const basePath = '/repos/some/repo/contents';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.setup();
hostRules.find.mockReturnValue({ token: 'abc' });
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/github/index.spec.ts
Expand Up @@ -11,7 +11,7 @@ const hostRules = mocked(_hostRules);
const githubApiHost = github.Endpoint;
const basePath = '/repos/some/repo/contents';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.setup();
hostRules.find.mockReturnValue({ token: 'abc' });
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/gitlab/index.spec.ts
Expand Up @@ -7,7 +7,7 @@ import * as gitlab from '.';
const gitlabApiHost = 'https://gitlab.com';
const basePath = '/api/v4/projects/some%2Frepo/repository';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
httpMock.setup();
Expand Down
7 changes: 2 additions & 5 deletions lib/config/presets/index.spec.ts
Expand Up @@ -16,10 +16,7 @@ jest.mock('./local');
const npm = mocked(_npm);
const local = mocked(_local);

const presetIkatyang = loadJsonFixture(
__filename,
'renovate-config-ikatyang.json'
);
const presetIkatyang = loadJsonFixture('renovate-config-ikatyang.json');

npm.getPreset = jest.fn(({ packageName, presetName }) => {
if (packageName === 'renovate-config-ikatyang') {
Expand All @@ -42,7 +39,7 @@ npm.getPreset = jest.fn(({ packageName, presetName }) => {
return null;
});

describe(getName(__filename), () => {
describe(getName(), () => {
describe('resolvePreset', () => {
let config: RenovateConfig;
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/index.spec.ts
Expand Up @@ -14,7 +14,7 @@ npm.getPreset = jest.fn((_) => null);

const ignoredPresets = ['default:group', 'default:timezone'];

describe(getName(__filename), () => {
describe(getName(), () => {
it('fails for undefined internal preset', async () => {
const preset = 'foo:bar';
const presetConfig = { extends: [preset] };
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/local/index.spec.ts
Expand Up @@ -21,7 +21,7 @@ const gitea = mocked(_gitea);
const github = mocked(_github);
const gitlab = mocked(_gitlab);

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
const preset = { resolved: 'preset' };
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/npm/index.spec.ts
Expand Up @@ -6,7 +6,7 @@ import * as npm from '.';
jest.mock('registry-auth-token');
jest.mock('delay');

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
setAdminConfig();
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/util.spec.ts
Expand Up @@ -16,7 +16,7 @@ const config: FetchPresetConfig = {

const fetch = jest.fn(() => Promise.resolve<Preset>({}));

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
fetch.mockReset();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/config/secrets.spec.ts
Expand Up @@ -5,7 +5,7 @@ import {
} from '../constants/error-messages';
import { applySecretsToConfig, validateConfigSecrets } from './secrets';

describe(getName(__filename), () => {
describe(getName(), () => {
describe('validateConfigSecrets(config)', () => {
it('works with default config', () => {
expect(() => validateConfigSecrets(defaultConfig)).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion lib/config/validation-helpers/managers.spec.ts
@@ -1,7 +1,7 @@
import { getName } from '../../../test/util';
import { check } from './managers';

describe(getName(__filename), () => {
describe(getName(), () => {
it('should have no errors', () => {
const res = check({
resolvedRule: { matchManagers: ['npm'] },
Expand Down
2 changes: 1 addition & 1 deletion lib/config/validation.spec.ts
Expand Up @@ -2,7 +2,7 @@ import { getName } from '../../test/util';
import type { RenovateConfig } from './types';
import * as configValidation from './validation';

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getParentName()', () => {
it('ignores encrypted in root', () => {
expect(configValidation.getParentName('encrypted')).toEqual('');
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/bitbucket-tags/index.spec.ts
Expand Up @@ -3,7 +3,7 @@ import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { id as datasource } from '.';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.reset();
httpMock.setup();
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/cdnjs/index.spec.ts
Expand Up @@ -4,15 +4,15 @@ import { getName, loadFixture } from '../../../test/util';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import { id as datasource } from '.';

const res1 = loadFixture(__filename, 'd3-force.json');
const res2 = loadFixture(__filename, 'bulma.json');
const res1 = loadFixture('d3-force.json');
const res2 = loadFixture('bulma.json');

const baseUrl = 'https://api.cdnjs.com/';

const pathFor = (s: string): string =>
`/libraries/${s.split('/').shift()}?fields=homepage,repository,assets`;

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
8 changes: 4 additions & 4 deletions lib/datasource/crate/index.spec.ts
Expand Up @@ -20,9 +20,9 @@ import {
jest.mock('simple-git');
const simpleGit: any = _simpleGit;

const res1 = loadFixture(__filename, 'libc');
const res2 = loadFixture(__filename, 'amethyst');
const res3 = loadFixture(__filename, 'mypkg');
const res1 = loadFixture('libc');
const res2 = loadFixture('amethyst');
const res3 = loadFixture('mypkg');

const baseUrl =
'https://raw.githubusercontent.com/rust-lang/crates.io-index/master/';
Expand Down Expand Up @@ -65,7 +65,7 @@ function setupErrorGitMock(): { mockClone: jest.Mock<any, any> } {
return { mockClone };
}

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getIndexSuffix', () => {
it('returns correct suffixes', () => {
expect(getIndexSuffix('a')).toStrictEqual(['1', 'a']);
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/dart/index.spec.ts
Expand Up @@ -3,11 +3,11 @@ import * as httpMock from '../../../test/http-mock';
import { getName, loadJsonFixture } from '../../../test/util';
import { id as datasource } from '.';

const body = loadJsonFixture(__filename, 'shared_preferences.json');
const body = loadJsonFixture('shared_preferences.json');

const baseUrl = 'https://pub.dartlang.org/api/packages/';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.setup();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/docker/index.spec.ts
Expand Up @@ -41,7 +41,7 @@ function mockEcrAuthReject(msg: string) {
);
}

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.setup();
hostRules.find.mockReturnValue({
Expand Down
11 changes: 2 additions & 9 deletions lib/datasource/galaxy-collection/index.spec.ts
Expand Up @@ -4,30 +4,23 @@ import { getName, loadFixture } from '../../../test/util';

import { id as datasource } from '.';

const communityKubernetesBase = loadFixture(
__filename,
'community_kubernetes_base.json'
);
const communityKubernetesBase = loadFixture('community_kubernetes_base.json');
const communityKubernetesVersions = loadFixture(
__filename,
'community_kubernetes_versions.json'
);
const communityKubernetesDetails121 = loadFixture(
__filename,
'community_kubernetes_version_details_1.2.1.json'
);
const communityKubernetesDetails120 = loadFixture(
__filename,
'community_kubernetes_version_details_1.2.0.json'
);
const communityKubernetesDetails0111 = loadFixture(
__filename,
'community_kubernetes_version_details_0.11.1.json'
);

const baseUrl = 'https://galaxy.ansible.com';

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getReleases', () => {
beforeEach(() => {
httpMock.setup();
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/galaxy/index.spec.ts
Expand Up @@ -4,12 +4,12 @@ import { getName, loadFixture } from '../../../test/util';

import { id as datasource } from '.';

const res1 = loadFixture(__filename, 'timezone');
const empty = loadFixture(__filename, 'empty');
const res1 = loadFixture('timezone');
const empty = loadFixture('empty');

const baseUrl = 'https://galaxy.ansible.com/';

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getReleases', () => {
beforeEach(() => {
httpMock.setup();
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/git-refs/index.spec.ts
Expand Up @@ -8,9 +8,9 @@ const simpleGit: any = _simpleGit;

const depName = 'https://github.com/example/example.git';

const lsRemote1 = loadFixture(__filename, 'ls-remote-1.txt');
const lsRemote1 = loadFixture('ls-remote-1.txt');

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getReleases', () => {
it('returns nil if response is wrong', async () => {
simpleGit.mockReturnValue({
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/git-tags/index.spec.ts
Expand Up @@ -8,9 +8,9 @@ const simpleGit: any = _simpleGit;

const depName = 'https://github.com/example/example.git';

const lsRemote1 = loadFixture(__filename, 'ls-remote-1.txt', '../git-refs');
const lsRemote1 = loadFixture('ls-remote-1.txt', '../git-refs');

describe(getName(__filename), () => {
describe(getName(), () => {
describe('getReleases', () => {
it('returns nil if response is wrong', async () => {
simpleGit.mockReturnValue({
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/github-releases/index.spec.ts
Expand Up @@ -23,7 +23,7 @@ const responseBody = [
},
];

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
hostRules.hosts.mockReturnValue([]);
hostRules.find.mockReturnValue({
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/github-tags/index.spec.ts
Expand Up @@ -10,7 +10,7 @@ const hostRules: any = _hostRules;
const githubApiHost = 'https://api.github.com';
const githubEnterpriseApiHost = 'https://git.enterprise.com';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.reset();
httpMock.setup();
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/gitlab-tags/index.spec.ts
Expand Up @@ -3,7 +3,7 @@ import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { id as datasource } from '.';

describe(getName(__filename), () => {
describe(getName(), () => {
beforeEach(() => {
httpMock.reset();
httpMock.setup();
Expand Down