Files
renovate/lib/workers/repository/common.spec.ts
Felipe Santos 3032c960b3 fix: avoid proposing replacements when the new dependency already exists (#40149)
* fix(npm): remove old dependency when replacement exists

* Add coverage ignore comments

* Simplify implementation

* Rename to removeAsString

* Move it after replaceAsString

* Improve test case

* Improve error message of replaceAsString

* Fix coverage

* Fix coverage again

* Only remove dependency at depType like replaceAsString

* Refactor tests

* Fix tsc

* fix(npm): skip update when replacement dependency already exists

* Simplify else

* Avoid returning an error

* fix(flatten): skip replacement updates when a sibling dependency already exists

* Revert the other changes

* Also handle it in the Dependency Dashboard

* Filter out earlier

* Try some other way

* Try fix dep dashboard

* Try fix again

* Extract helper

* Improve some stuff

* Improve assertion

* Remove misleading comment

* Address review comments
2026-07-13 18:13:53 +00:00

77 lines
2.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { DEBUG, ERROR, FATAL, INFO, TRACE, WARN } from 'bunyan';
import type { PackageDependency } from '../../modules/manager/types.ts';
import { formatProblemLevel, replacementAlreadyExists } from './common.ts';
describe('workers/repository/common', () => {
describe('replacementAlreadyExists()', () => {
it('returns true when sibling depName matches newName', () => {
const currentDep: PackageDependency = { depName: '@material-ui/core' };
const deps: PackageDependency[] = [
currentDep,
{ depName: '@mui/material' },
];
expect(
replacementAlreadyExists(deps, currentDep, '@mui/material'),
).toBeTrue();
});
it('returns true when sibling packageName matches newName', () => {
const currentDep: PackageDependency = { depName: 'old-pkg' };
const deps: PackageDependency[] = [
currentDep,
{ depName: 'alias', packageName: 'new-pkg' },
];
expect(replacementAlreadyExists(deps, currentDep, 'new-pkg')).toBeTrue();
});
it('returns false when no sibling matches newName', () => {
const currentDep: PackageDependency = { depName: '@material-ui/core' };
const deps: PackageDependency[] = [
currentDep,
{ depName: 'unrelated-package' },
];
expect(
replacementAlreadyExists(deps, currentDep, '@mui/material'),
).toBeFalse();
});
it('does not match the current dep itself', () => {
const currentDep: PackageDependency = { depName: '@mui/material' };
const deps: PackageDependency[] = [currentDep];
expect(
replacementAlreadyExists(deps, currentDep, '@mui/material'),
).toBeFalse();
});
});
describe('formatProblemLevel()', () => {
it('handles trace level', () => {
expect(formatProblemLevel(TRACE)).toEqual('🔬 TRACE');
});
it('handles debug level', () => {
expect(formatProblemLevel(DEBUG)).toEqual('🔍 DEBUG');
});
it('handles info level', () => {
expect(formatProblemLevel(INFO)).toEqual('ℹ️ INFO');
});
it('handles warn level', () => {
expect(formatProblemLevel(WARN)).toEqual('⚠️ WARN');
});
it('handles error level', () => {
expect(formatProblemLevel(ERROR)).toEqual('❌ ERROR');
});
it('handles fatal level', () => {
expect(formatProblemLevel(FATAL)).toEqual('💀 FATAL');
});
});
});