Files
renovate/lib/util/minimatch.spec.ts
Michael Kriese b5211d4944 test(util): cover remaining lib/util coverage gaps (#45832)
test(util): cover minimatchFilter and cachePathIsFile gaps

Brings lib/util to 100% coverage:

- minimatchFilter: the closure returned on the uncached path was never
  invoked, and the options-based cache key branch was never taken
- cachePathIsFile: only the "does not exist" path was tested, so
  stat().isFile() never ran

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>
2026-09-10 07:28:12 +00:00

56 lines
1.9 KiB
TypeScript

import { minimatch, minimatchFilter } from './minimatch.ts';
describe('util/minimatch', () => {
describe('minimatch', () => {
it('caches minimatch', () => {
expect(minimatch('foo')).toBe(minimatch('foo'));
expect(minimatch('foo', { dot: true })).toBe(
minimatch('foo', { dot: true }),
);
});
it('does not cache minimatch', () => {
expect(minimatch('foo', undefined, false)).not.toBe(
minimatch('foo', undefined, false),
);
expect(minimatch('foo')).not.toBe(minimatch('foo', undefined, false));
expect(minimatch('foo', { dot: true })).not.toBe(minimatch('foo'));
});
it('matches', () => {
const matcher = minimatch('@opentelemetry{/,}**');
expect(matcher.match('@opentelemetry-http')).toBeTrue();
expect(matcher.match('@opentelemetry/http')).toBeTrue();
expect(matcher.match('@opentelemetry/http/client')).toBeTrue();
expect(
minimatch('@opentelemetry**').match('@opentelemetry/http'),
).toBeFalse();
});
});
describe('minimatchFilter', () => {
it('should return a function', () => {
expect(minimatchFilter('*.js')).toBeFunction();
expect(minimatchFilter('*.js', undefined, false)).toBeFunction();
});
it('should correctly match filenames', () => {
const filterFunc = minimatchFilter('*.js');
expect(filterFunc('test.js')).toBe(true);
expect(filterFunc('test.txt')).toBe(false);
});
it('should correctly match filenames when uncached', () => {
const filterFunc = minimatchFilter('*.ts', undefined, false);
expect(filterFunc('test.ts')).toBe(true);
expect(filterFunc('test.txt')).toBe(false);
});
it('should respect options', () => {
const filterFunc = minimatchFilter('*.js', { dot: true });
expect(filterFunc('.test.js')).toBe(true);
expect(minimatchFilter('*.js')('.test.js')).toBe(false);
});
});
});