Skip to content

Commit

Permalink
test(packageRules): increase matchPackageNames tests (#28545)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Apr 20, 2024
1 parent 7b66b9f commit 58b29f9
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions lib/util/package-rules/package-names.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '../../../test/util';
import { PackageNameMatcher } from './package-names';

describe('util/package-rules/package-names', () => {
Expand All @@ -16,14 +17,27 @@ describe('util/package-rules/package-names', () => {
expect(result).toBeFalse();
});

it('should return false if not matching', () => {
const result = packageNameMatcher.matches(
{
depName: 'abc',
packageName: 'def',
},
{
matchPackageNames: ['ghi'],
},
);
expect(result).toBeFalse();
});

it('should matchPackageName', () => {
const result = packageNameMatcher.matches(
{
depName: 'abc',
packageName: 'def',
},
{
matchPackageNames: ['def'],
matchPackageNames: ['def', 'ghi'],
},
);
expect(result).toBeTrue();
Expand All @@ -36,15 +50,16 @@ describe('util/package-rules/package-names', () => {
packageName: 'def',
},
{
matchPackageNames: ['abc'],
matchPackageNames: ['ghi', 'abc'],
},
);
expect(result).toBeTrue();
expect(logger.logger.once.info).toHaveBeenCalled();
});
});

describe('exclude', () => {
it('should return false if packageFile is not defined', () => {
it('should return false if packageName is not defined', () => {
const result = packageNameMatcher.excludes(
{
depName: undefined,
Expand All @@ -55,18 +70,45 @@ describe('util/package-rules/package-names', () => {
);
expect(result).toBeFalse();
});
});

it('should excludePackageName', () => {
const result = packageNameMatcher.excludes(
{
depName: 'abc',
packageName: 'def',
},
{
excludePackageNames: ['def'],
},
);
expect(result).toBeTrue();
it('should return false if not matching', () => {
const result = packageNameMatcher.excludes(
{
depName: 'abc',
packageName: 'def',
},
{
excludePackageNames: ['ghi'],
},
);
expect(result).toBeFalse();
});

it('should excludePackageName', () => {
const result = packageNameMatcher.excludes(
{
depName: 'abc',
packageName: 'def',
},
{
excludePackageNames: ['def', 'ghi'],
},
);
expect(result).toBeTrue();
});

it('should fall back to depName excludePackageName', () => {
const result = packageNameMatcher.excludes(
{
depName: 'abc',
packageName: 'def',
},
{
excludePackageNames: ['abc', 'ghi'],
},
);
expect(result).toBeTrue();
expect(logger.logger.once.info).toHaveBeenCalled();
});
});
});

0 comments on commit 58b29f9

Please sign in to comment.