Skip to content

Commit

Permalink
test: enforce lint style rules (#15085)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Apr 12, 2022
1 parent 7140865 commit 64f5bd5
Show file tree
Hide file tree
Showing 267 changed files with 2,198 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
env: {
node: true,
},
plugins: ['@renovate', 'typescript-enum'],
plugins: ['@renovate', 'typescript-enum', 'jest-formatting'],
extends: [
'eslint:recommended',
'plugin:import/errors',
Expand All @@ -15,6 +15,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:promise/recommended',
'plugin:jest-formatting/recommended',
'prettier',
],
parserOptions: {
Expand Down
11 changes: 11 additions & 0 deletions lib/config/decrypt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,40 @@ const repository = 'abc/def';
describe('config/decrypt', () => {
describe('decryptConfig()', () => {
let config: RenovateConfig;

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

it('returns empty with no privateKey', async () => {
delete config.encrypted;
const res = await decryptConfig(config, repository);
expect(res).toMatchObject(config);
});

it('warns if no privateKey found', async () => {
config.encrypted = { a: '1' };
const res = await decryptConfig(config, repository);
expect(res.encrypted).toBeUndefined();
expect(res.a).toBeUndefined();
});

it('handles invalid encrypted type', async () => {
config.encrypted = 1;
GlobalConfig.set({ privateKey });
const res = await decryptConfig(config, repository);
expect(res.encrypted).toBeUndefined();
});

it('handles invalid encrypted value', async () => {
config.encrypted = { a: 1 };
GlobalConfig.set({ privateKey, privateKeyOld: 'invalid-key' });
await expect(decryptConfig(config, repository)).rejects.toThrow(
'config-validation'
);
});

it('replaces npm token placeholder in npmrc', async () => {
GlobalConfig.set({
privateKey: 'invalid-key',
Expand All @@ -56,6 +62,7 @@ describe('config/decrypt', () => {
'//registry.npmjs.org/:_authToken=abcdef-ghijklm-nopqf-stuvwxyz\n//registry.npmjs.org/:_authToken=abcdef-ghijklm-nopqf-stuvwxyz\n'
);
});

it('appends npm token in npmrc', async () => {
GlobalConfig.set({ privateKey });
config.npmrc = 'foo=bar\n';
Expand All @@ -68,6 +75,7 @@ describe('config/decrypt', () => {
expect(res.npmToken).toBeUndefined();
expect(res.npmrc).toMatchSnapshot();
});

it('decrypts nested', async () => {
GlobalConfig.set({ privateKey });
config.packageFiles = [
Expand Down Expand Up @@ -95,6 +103,7 @@ describe('config/decrypt', () => {
'//registry.npmjs.org/:_authToken=abcdef-ghijklm-nopqf-stuvwxyz\n'
);
});

it('rejects invalid PGP message', async () => {
GlobalConfig.set({ privateKey: privateKeyPgp });
config.encrypted = {
Expand Down Expand Up @@ -135,6 +144,7 @@ describe('config/decrypt', () => {
'config-validation'
);
});

it('handles PGP org constraint', async () => {
GlobalConfig.set({ privateKey: privateKeyPgp });
config.encrypted = {
Expand All @@ -148,6 +158,7 @@ describe('config/decrypt', () => {
'config-validation'
);
});

it('handles PGP org/repo constraint', async () => {
GlobalConfig.set({ privateKey: privateKeyPgp });
config.encrypted = {
Expand Down
5 changes: 5 additions & 0 deletions lib/config/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('config/index', () => {
expect(config.lockFileMaintenance.schedule).toEqual(['on monday']);
expect(config.lockFileMaintenance).toMatchSnapshot();
});

it('merges packageRules', async () => {
const parentConfig = { ...defaultConfig };
Object.assign(parentConfig, {
Expand All @@ -41,6 +42,7 @@ describe('config/index', () => {
1, 2, 3, 4,
]);
});

it('merges constraints', async () => {
const parentConfig = { ...defaultConfig };
Object.assign(parentConfig, {
Expand All @@ -59,6 +61,7 @@ describe('config/index', () => {
expect(config.constraints).toMatchSnapshot();
expect(config.constraints.node).toBe('<15');
});

it('handles null parent packageRules', async () => {
const parentConfig = { ...defaultConfig };
Object.assign(parentConfig, {
Expand All @@ -71,13 +74,15 @@ describe('config/index', () => {
const config = configParser.mergeChildConfig(parentConfig, childConfig);
expect(config.packageRules).toHaveLength(2);
});

it('handles null child packageRules', async () => {
const parentConfig = { ...defaultConfig };
parentConfig.packageRules = [{ a: 3 }, { a: 4 }];
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, {});
expect(config.packageRules).toHaveLength(2);
});

it('handles undefined childConfig', async () => {
const parentConfig = { ...defaultConfig };
const configParser = await import('./index');
Expand Down
4 changes: 4 additions & 0 deletions lib/config/massage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ describe('config/massage', () => {
const res = massage.massageConfig(config);
expect(res).toEqual({});
});

it('massages strings to array', () => {
const config: RenovateConfig = {
schedule: 'before 5am' as never,
};
const res = massage.massageConfig(config);
expect(Array.isArray(res.schedule)).toBeTrue();
});

it('massages npmToken', () => {
const config: RenovateConfig = {
npmToken: 'some-token',
Expand All @@ -23,6 +25,7 @@ describe('config/massage', () => {
npmrc: '//registry.npmjs.org/:_authToken=some-token\n',
});
});

it('massages packageRules matchUpdateTypes', () => {
const config: RenovateConfig = {
packageRules: [
Expand All @@ -42,6 +45,7 @@ describe('config/massage', () => {
expect(res).toMatchSnapshot();
expect(res.packageRules).toHaveLength(3);
});

it('does not massage lockFileMaintenance', () => {
const config: RenovateConfig = {
packageRules: [
Expand Down
3 changes: 3 additions & 0 deletions lib/config/migrate-validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RenovateConfig, getConfig } from '../../test/util';
import { migrateAndValidate } from './migrate-validate';

let config: RenovateConfig;

beforeEach(() => {
jest.resetAllMocks();
config = getConfig();
Expand All @@ -16,6 +17,7 @@ describe('config/migrate-validate', () => {
warnings: [],
});
});

it('handles migration', async () => {
const input: RenovateConfig = { automerge: 'none' as any };
const res = await migrateAndValidate(config, input);
Expand All @@ -25,6 +27,7 @@ describe('config/migrate-validate', () => {
warnings: [],
});
});

it('handles invalid', async () => {
const input: RenovateConfig = { foo: 'none' };
const res = await migrateAndValidate(config, input);
Expand Down
18 changes: 18 additions & 0 deletions lib/config/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ describe('config/migration', () => {
expect(migratedConfig.packageRules).toHaveLength(9);
expect(migratedConfig.hostRules).toHaveLength(1);
});

it('migrates before and after schedules', () => {
const config = {
major: {
Expand All @@ -185,6 +186,7 @@ describe('config/migration', () => {
expect(migratedConfig.minor.schedule[0]).toBe('after 10pm every weekday');
expect(migratedConfig.minor.schedule[1]).toBe('before 7am every weekday');
});

it('migrates every friday', () => {
const config = {
schedule: 'every friday' as never,
Expand All @@ -194,6 +196,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig.schedule).toBe('on friday');
});

it('migrates semantic prefix with no scope', () => {
const config = {
semanticPrefix: 'fix',
Expand All @@ -203,6 +206,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig.semanticCommitScope).toBeNull();
});

it('does not migrate every weekday', () => {
const config = {
schedule: 'every weekday' as never,
Expand All @@ -212,6 +216,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeFalse();
expect(migratedConfig.schedule).toEqual(config.schedule);
});

it('does not migrate multi days', () => {
const config = {
schedule: 'after 5:00pm on wednesday and thursday' as never,
Expand All @@ -222,6 +227,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeFalse();
expect(migratedConfig.schedule).toEqual(config.schedule);
});

it('does not migrate hour range', () => {
const config = {
schedule: 'after 1:00pm and before 5:00pm' as never,
Expand All @@ -231,6 +237,7 @@ describe('config/migration', () => {
expect(migratedConfig.schedule).toEqual(config.schedule);
expect(isMigrated).toBeFalse();
});

it('migrates packages', () => {
const config = {
packages: [
Expand All @@ -252,6 +259,7 @@ describe('config/migration', () => {
],
});
});

it('overrides existing automerge setting', () => {
const config: TestRenovateConfig = {
automerge: 'minor' as never,
Expand All @@ -268,6 +276,7 @@ describe('config/migration', () => {
expect(migratedConfig).toMatchSnapshot();
expect(migratedConfig.packageRules[0].minor.automerge).toBeFalse();
});

it('does not migrate config', () => {
const config: TestRenovateConfig = {
enabled: true,
Expand All @@ -278,6 +287,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeFalse();
expect(migratedConfig).toMatchObject(config);
});

it('migrates subconfig', () => {
const config: TestRenovateConfig = {
lockFileMaintenance: {
Expand Down Expand Up @@ -318,6 +328,7 @@ describe('config/migration', () => {
true
);
});

it('migrates packageFiles', () => {
const config: TestRenovateConfig = {
packageFiles: [
Expand All @@ -341,6 +352,7 @@ describe('config/migration', () => {
expect(migratedConfig.packageRules[0].rangeStrategy).toBe('replace');
expect(migratedConfig.packageRules[1].rangeStrategy).toBe('pin');
});

it('migrates more packageFiles', () => {
const config: TestRenovateConfig = {
packageFiles: [
Expand Down Expand Up @@ -501,6 +513,7 @@ describe('config/migration', () => {
extends: [':unpublishSafeDisabled', 'npm:unpublishSafe'],
});
});

it('migrates combinations of packageRules', () => {
let config: TestRenovateConfig;
let res: MigratedConfig;
Expand All @@ -521,6 +534,7 @@ describe('config/migration', () => {
expect(res.isMigrated).toBeTrue();
expect(res.migratedConfig.packageRules).toHaveLength(2);
});

it('it migrates packageRules', () => {
const config: TestRenovateConfig = {
packageRules: [
Expand Down Expand Up @@ -563,6 +577,7 @@ describe('config/migration', () => {
});
});
});

it('it migrates nested packageRules', () => {
const config: TestRenovateConfig = {
packageRules: [
Expand Down Expand Up @@ -592,6 +607,7 @@ describe('config/migration', () => {
expect(migratedConfig).toMatchSnapshot();
expect(migratedConfig.packageRules).toHaveLength(3);
});

it('it migrates presets', () => {
GlobalConfig.set({
migratePresets: {
Expand All @@ -607,6 +623,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig).toEqual({ extends: ['local>org/renovate-config'] });
});

it('it migrates regexManagers', () => {
const config: RenovateConfig = {
regexManagers: [
Expand Down Expand Up @@ -652,6 +669,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig).toMatchSnapshot();
});

it('migrates empty requiredStatusChecks', () => {
const config: RenovateConfig = {
requiredStatusChecks: [],
Expand Down
1 change: 1 addition & 0 deletions lib/config/presets/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('config/presets/bitbucket-server/index', () => {
)
).toEqual({ from: 'api' });
});

it('uses custom path', async () => {
httpMock
.scope('https://api.github.example.org')
Expand Down
1 change: 1 addition & 0 deletions lib/config/presets/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ describe('config/presets/gitea/index', () => {
)
).toEqual({ from: 'api' });
});

it('uses custom endpoint with a tag', async () => {
httpMock
.scope('https://api.gitea.example.org')
Expand Down

0 comments on commit 64f5bd5

Please sign in to comment.