mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 09:41:46 +00:00
7436b80cda
ci(linter): add renovate/no-redundant-mock-reset rule Vitest sets mockReset: true globally in vitest.config.mts, which resets all mocks before each test. This makes vi.resetAllMocks() / vi.clearAllMocks() and per-mock .mockReset() / .mockClear() calls inside beforeEach/afterEach hooks redundant. Add a custom oxlint rule (enabled for **/*.spec.ts and test/**) flagging such calls, and remove the 40 redundant calls it found. restoreAllMocks/mockRestore are not flagged because restoreMocks is not enabled globally. Two sites keep an inline disable with a reason: nested beforeEach hooks in filter-checks.spec.ts and onboarding/pr/index.spec.ts intentionally call mockReset() to discard once-values queued by an outer beforeEach. Requested by maintainer review feedback (review comment 3052324877). Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { provision } from './provision.ts';
|
|
|
|
const { exec } = vi.hoisted(() => ({ exec: vi.fn() }));
|
|
vi.mock('./exec.ts', () => ({ exec }));
|
|
const errorSpy = vi.spyOn(console, 'error');
|
|
|
|
it('runs mise install then pnpm install', async () => {
|
|
exec.mockResolvedValue(undefined);
|
|
|
|
await provision();
|
|
|
|
expect(exec).toHaveBeenCalledTimes(2);
|
|
expect(exec).toHaveBeenNthCalledWith(1, 'mise', ['install'], {});
|
|
expect(exec).toHaveBeenNthCalledWith(2, 'pnpm', ['install'], {});
|
|
});
|
|
|
|
it('passes cwd to both commands when provided', async () => {
|
|
exec.mockResolvedValue(undefined);
|
|
|
|
await provision('/some/worktree');
|
|
|
|
expect(exec).toHaveBeenNthCalledWith(1, 'mise', ['install'], {
|
|
cwd: '/some/worktree',
|
|
});
|
|
expect(exec).toHaveBeenNthCalledWith(2, 'pnpm', ['install'], {
|
|
cwd: '/some/worktree',
|
|
});
|
|
});
|
|
|
|
it('skips mise failure gracefully and still runs pnpm install', async () => {
|
|
exec
|
|
.mockRejectedValueOnce(new Error('mise not found'))
|
|
.mockResolvedValueOnce(undefined);
|
|
|
|
await provision();
|
|
|
|
expect(exec).toHaveBeenCalledTimes(2);
|
|
expect(exec).toHaveBeenNthCalledWith(2, 'pnpm', ['install'], {});
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
'mise is not installed or failed — skipping',
|
|
);
|
|
});
|
|
|
|
it('propagates error if pnpm install fails', async () => {
|
|
exec
|
|
.mockResolvedValueOnce(undefined)
|
|
.mockRejectedValueOnce(new Error('install failed'));
|
|
|
|
await expect(provision()).rejects.toThrow('install failed');
|
|
});
|