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

test(packageRules): increase matchPackageNames tests #28545

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});