Skip to content

Commit

Permalink
fix(package-rules): matchCurrentVersion with null versioning (#24965)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Oct 3, 2023
1 parent c8fceec commit b66df6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/modules/versioning/index.ts
Expand Up @@ -16,8 +16,10 @@ export const getVersionings = (): Map<
VersioningApi | VersioningApiConstructor
> => versionings;

export function get(versioning = ''): VersioningApi {
const res = Versioning.safeParse(versioning);
export function get(versioning: string | null | undefined): VersioningApi {
const res = Versioning.safeParse(
versioning ? versioning : defaultVersioning.id
);

if (!res.success) {
const [issue] = res.error.issues;
Expand Down
14 changes: 14 additions & 0 deletions lib/util/package-rules/current-version.spec.ts
Expand Up @@ -5,6 +5,20 @@ describe('util/package-rules/current-version', () => {
const matcher = new CurrentVersionMatcher();

describe('match', () => {
it('returns true for null versioning', () => {
const result = matcher.matches(
{
// @ts-expect-error: for testing
versioning: null,
currentValue: '1.2.3',
},
{
matchCurrentVersion: '1.2.3',
}
);
expect(result).toBeTrue();
});

it('return false on version exception', () => {
const spy = jest.spyOn(pep440, 'matches').mockImplementationOnce(() => {
throw new Error();
Expand Down

0 comments on commit b66df6e

Please sign in to comment.