mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 06:51:11 +00:00
a2704ed3f1
Instead of needing to always make sure that we've cleared host rules in tests that use them - or knowing when they're touched indirectly - we can make sure that we have an `afterEach` that will clear our Host Rules. We can do this by making sure that we have a top-level `afterEach` that handles this, which needs a dynamic import to avoid eagerly importing and caching it, which would leave stale unmocked bindings for a given file's test run. We also need to make sure that `private-key.spec.ts`'s `sanitize.ts` mock is updated to also stub `clearRepoSanitizedSecretsList`, since `hostRules.clear()` now calls. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
// Check for missing or pending http mocks
|
|
import './http-mock.ts';
|
|
import { mockDeep } from 'vitest-mock-extended';
|
|
import type { Platform, PlatformScm } from '../lib/modules/platform/index.ts';
|
|
import * as _fixtures from './fixtures.ts';
|
|
|
|
// Set timezone so snapshots are consistent
|
|
process.env.TZ = 'UTC';
|
|
|
|
afterEach(async () => {
|
|
// dynamic import to avoid caching this before per-file mocks are hoisted into place
|
|
const hostRules = await import('../lib/util/host-rules.ts');
|
|
hostRules.clear();
|
|
});
|
|
|
|
vi.mock('../lib/modules/platform/index.ts', () => ({
|
|
platform: mockDeep<Platform>(),
|
|
initPlatform: vi.fn(),
|
|
getPlatformList: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../lib/modules/platform/scm.ts', () => ({
|
|
scm: mockDeep<PlatformScm>(),
|
|
}));
|
|
|
|
vi.mock('../lib/logger/index.ts', () => {
|
|
return mockDeep({
|
|
withMeta: <T>(_: Record<string, unknown>, cb: () => T): T => cb(),
|
|
});
|
|
});
|
|
|
|
vi.mock('../lib/util/git/index.ts', () => mockDeep());
|
|
|
|
vi.mock('../lib/util/exec/common.ts', () => ({ rawExec: vi.fn() }));
|
|
|
|
Object.defineProperty(global, 'fixtures', { value: _fixtures });
|
|
declare global {
|
|
const fixtures: typeof _fixtures;
|
|
}
|
|
|
|
vi.mock('../lib/util/mutex.ts', () => ({
|
|
initMutexes: () => vi.fn(),
|
|
acquireLock: () => vi.fn().mockImplementation(() => () => undefined),
|
|
}));
|