mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 17:51:49 +00:00
3032c960b3
* 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
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
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');
|
||
});
|
||
});
|
||
});
|