Skip to content
Snippets Groups Projects
Unverified Commit c42957a8 authored by RahulGautamSingh's avatar RahulGautamSingh Committed by GitHub
Browse files

refactor(modules/versioning): fix null check issues in tests (#16145)


* fix null-check issues

* Update lib/modules/versioning/versioning-metadata.spec.ts

Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
parent fe20cfce
No related branches found
No related tags found
No related merge requests found
...@@ -71,7 +71,7 @@ describe('modules/versioning/composer/index', () => { ...@@ -71,7 +71,7 @@ describe('modules/versioning/composer/index', () => {
${'0.3.1'} | ${'~0.4'} | ${true} ${'0.3.1'} | ${'~0.4'} | ${true}
${'0.5.1'} | ${'~0.4'} | ${false} ${'0.5.1'} | ${'~0.4'} | ${false}
`('isLessThanRange("$a", "$b") === $expected', ({ a, b, expected }) => { `('isLessThanRange("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(semver.isLessThanRange(a, b)).toBe(expected); expect(semver.isLessThanRange?.(a, b)).toBe(expected);
}); });
test.each` test.each`
......
...@@ -60,7 +60,7 @@ describe('modules/versioning/docker/index', () => { ...@@ -60,7 +60,7 @@ describe('modules/versioning/docker/index', () => {
`( `(
'isLessThanRange($version, $range) === $expected', 'isLessThanRange($version, $range) === $expected',
({ version, range, expected }) => { ({ version, range, expected }) => {
expect(docker.isLessThanRange(version, range)).toBe(expected); expect(docker.isLessThanRange?.(version, range)).toBe(expected);
} }
); );
...@@ -205,7 +205,7 @@ describe('modules/versioning/docker/index', () => { ...@@ -205,7 +205,7 @@ describe('modules/versioning/docker/index', () => {
${'3.8.2'} | ${'3.8.2'} ${'3.8.2'} | ${'3.8.2'}
${undefined} | ${undefined} ${undefined} | ${undefined}
`('valueToVersion("$value") === $expected', ({ value, expected }) => { `('valueToVersion("$value") === $expected', ({ value, expected }) => {
const res = docker.valueToVersion(value); const res = docker.valueToVersion?.(value);
expect(res).toBe(expected); expect(res).toBe(expected);
}); });
}); });
...@@ -38,7 +38,7 @@ describe('modules/versioning/hashicorp/index', () => { ...@@ -38,7 +38,7 @@ describe('modules/versioning/hashicorp/index', () => {
`( `(
'isLessThanRange($version, $range) === $expected', 'isLessThanRange($version, $range) === $expected',
({ version, range, expected }) => { ({ version, range, expected }) => {
expect(semver.isLessThanRange(version, range)).toBe(expected); expect(semver.isLessThanRange?.(version, range)).toBe(expected);
} }
); );
......
...@@ -8,7 +8,7 @@ import * as allVersioning from '.'; ...@@ -8,7 +8,7 @@ import * as allVersioning from '.';
const supportedSchemes = getOptions().find( const supportedSchemes = getOptions().find(
(option) => option.name === 'versioning' (option) => option.name === 'versioning'
).allowedValues; )?.allowedValues;
describe('modules/versioning/index', () => { describe('modules/versioning/index', () => {
it('has api', () => { it('has api', () => {
...@@ -52,7 +52,7 @@ describe('modules/versioning/index', () => { ...@@ -52,7 +52,7 @@ describe('modules/versioning/index', () => {
expect(Array.from(vers.keys())).toEqual(Object.keys(loadedVers)); expect(Array.from(vers.keys())).toEqual(Object.keys(loadedVers));
for (const name of vers.keys()) { for (const name of vers.keys()) {
const ver = vers.get(name); const ver = vers.get(name)!;
expect(validate(ver, name)).toBeTrue(); expect(validate(ver, name)).toBeTrue();
} }
}); });
...@@ -88,7 +88,7 @@ describe('modules/versioning/index', () => { ...@@ -88,7 +88,7 @@ describe('modules/versioning/index', () => {
.sort(); .sort();
function getAllPropertyNames(obj: any): string[] { function getAllPropertyNames(obj: any): string[] {
const props = []; const props: string[] = [];
let o = obj; let o = obj;
do { do {
...@@ -102,7 +102,7 @@ describe('modules/versioning/index', () => { ...@@ -102,7 +102,7 @@ describe('modules/versioning/index', () => {
return props; return props;
} }
for (const supportedScheme of supportedSchemes) { for (const supportedScheme of supportedSchemes ?? []) {
it(supportedScheme, () => { it(supportedScheme, () => {
const schemeKeys = getAllPropertyNames( const schemeKeys = getAllPropertyNames(
allVersioning.get(supportedScheme) allVersioning.get(supportedScheme)
......
...@@ -145,7 +145,7 @@ describe('modules/versioning/poetry/index', () => { ...@@ -145,7 +145,7 @@ describe('modules/versioning/poetry/index', () => {
`( `(
'isLessThanRange("$version", "$range") === "$expected"', 'isLessThanRange("$version", "$range") === "$expected"',
({ version, range, expected }) => { ({ version, range, expected }) => {
expect(versioning.isLessThanRange(version, range)).toBe(expected); expect(versioning.isLessThanRange?.(version, range)).toBe(expected);
} }
); );
......
...@@ -237,7 +237,7 @@ describe('modules/versioning/regex/index', () => { ...@@ -237,7 +237,7 @@ describe('modules/versioning/regex/index', () => {
`( `(
'isLessThanRange($version, $range) === $expected', 'isLessThanRange($version, $range) === $expected',
({ version, range, expected }) => { ({ version, range, expected }) => {
expect(regex.isLessThanRange(version, range)).toBe(expected); expect(regex.isLessThanRange?.(version, range)).toBe(expected);
} }
); );
...@@ -273,9 +273,9 @@ describe('modules/versioning/regex/index', () => { ...@@ -273,9 +273,9 @@ describe('modules/versioning/regex/index', () => {
it('returns newVersion', () => { it('returns newVersion', () => {
expect( expect(
regex.getNewValue({ regex.getNewValue({
currentValue: null, currentValue: null as never,
rangeStrategy: null, rangeStrategy: null as never,
currentVersion: null, currentVersion: null as never,
newVersion: '1.2.3', newVersion: '1.2.3',
}) })
).toBe('1.2.3'); ).toBe('1.2.3');
......
...@@ -6,7 +6,7 @@ describe('modules/versioning/versioning-metadata', () => { ...@@ -6,7 +6,7 @@ describe('modules/versioning/versioning-metadata', () => {
(item) => !item.includes('.') (item) => !item.includes('.')
); );
for (const versioning of allVersioning) { for (const versioning of allVersioning) {
let readme: string; let readme: string | undefined;
try { try {
readme = await readFile( readme = await readFile(
'lib/modules/versioning/' + versioning + '/readme.md', 'lib/modules/versioning/' + versioning + '/readme.md',
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
"lib/workers/**/*.spec.ts", "lib/workers/**/*.spec.ts",
"lib/modules/datasource/**/*.spec.ts", "lib/modules/datasource/**/*.spec.ts",
"lib/modules/manager/**/*.spec.ts", "lib/modules/manager/**/*.spec.ts",
"lib/modules/versioning/**/*.spec.ts",
"lib/renovate.ts", "lib/renovate.ts",
"lib/renovate.spec.ts", "lib/renovate.spec.ts",
"lib/workers/global/autodiscover.ts", "lib/workers/global/autodiscover.ts",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment