fix: convert all test files from jest to vitest and fix QBittorrentClient import
- Convert RTorrentClient.test.js to use vi.mock() instead of jest.mock() - Convert QBittorrentClient.test.js to use vi.mock() instead of jest.mock() - Convert SABnzbdClient.test.js to use vi.mock() instead of jest.mock() - Convert TransmissionClient.test.js to use vi.mock() instead of jest.mock() - Convert downloadClients.test.js to use vi.mock() instead of jest.mock() - Convert integration/downloadClients.test.js to use vi.mock() instead of jest.mock() - Fix legacy qbittorrent.test.js to import QBittorrentClient from new location - Add getRtorrentInstances mock to downloadClients.test.js - Add RTORRENT_INSTANCES to integration test environment variables
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Copyright (c) 2026 Gordon Bolton. MIT License.
|
||||
const {
|
||||
DownloadClientRegistry,
|
||||
const {
|
||||
DownloadClientRegistry,
|
||||
registry,
|
||||
initializeClients,
|
||||
getAllClients,
|
||||
@@ -11,55 +11,57 @@ const {
|
||||
testAllConnections,
|
||||
getAllClientStatuses
|
||||
} = require('../../server/utils/downloadClients');
|
||||
const { vi } = require('vitest');
|
||||
|
||||
// Mock config and clients
|
||||
jest.mock('../../server/utils/config', () => ({
|
||||
getSABnzbdInstances: jest.fn(),
|
||||
getQbittorrentInstances: jest.fn(),
|
||||
getTransmissionInstances: jest.fn()
|
||||
vi.mock('../../server/utils/config', () => ({
|
||||
getSABnzbdInstances: vi.fn(),
|
||||
getQbittorrentInstances: vi.fn(),
|
||||
getTransmissionInstances: vi.fn(),
|
||||
getRtorrentInstances: vi.fn()
|
||||
}));
|
||||
|
||||
jest.mock('../../server/utils/logger', () => ({
|
||||
logToFile: jest.fn()
|
||||
vi.mock('../../server/utils/logger', () => ({
|
||||
logToFile: vi.fn()
|
||||
}));
|
||||
|
||||
jest.mock('../../server/clients/SABnzbdClient', () => {
|
||||
return jest.fn().mockImplementation((config) => ({
|
||||
vi.mock('../../server/clients/SABnzbdClient', () => {
|
||||
return vi.fn().mockImplementation((config) => ({
|
||||
getClientType: () => 'sabnzbd',
|
||||
getInstanceId: () => config.id,
|
||||
name: config.name,
|
||||
getActiveDownloads: jest.fn().mockResolvedValue([
|
||||
getActiveDownloads: vi.fn().mockResolvedValue([
|
||||
{ id: 'sab1', title: 'SAB Download 1', client: 'sabnzbd' }
|
||||
]),
|
||||
testConnection: jest.fn().mockResolvedValue(true),
|
||||
getClientStatus: jest.fn().mockResolvedValue({ status: 'active' })
|
||||
testConnection: vi.fn().mockResolvedValue(true),
|
||||
getClientStatus: vi.fn().mockResolvedValue({ status: 'active' })
|
||||
}));
|
||||
});
|
||||
|
||||
jest.mock('../../server/clients/QBittorrentClient', () => {
|
||||
return jest.fn().mockImplementation((config) => ({
|
||||
vi.mock('../../server/clients/QBittorrentClient', () => {
|
||||
return vi.fn().mockImplementation((config) => ({
|
||||
getClientType: () => 'qbittorrent',
|
||||
getInstanceId: () => config.id,
|
||||
name: config.name,
|
||||
getActiveDownloads: jest.fn().mockResolvedValue([
|
||||
getActiveDownloads: vi.fn().mockResolvedValue([
|
||||
{ id: 'qb1', title: 'QB Download 1', client: 'qbittorrent' }
|
||||
]),
|
||||
testConnection: jest.fn().mockResolvedValue(true),
|
||||
getClientStatus: jest.fn().mockResolvedValue({ status: 'active' }),
|
||||
resetFallbackFlag: jest.fn()
|
||||
testConnection: vi.fn().mockResolvedValue(true),
|
||||
getClientStatus: vi.fn().mockResolvedValue({ status: 'active' }),
|
||||
resetFallbackFlag: vi.fn()
|
||||
}));
|
||||
});
|
||||
|
||||
jest.mock('../../server/clients/TransmissionClient', () => {
|
||||
return jest.fn().mockImplementation((config) => ({
|
||||
vi.mock('../../server/clients/TransmissionClient', () => {
|
||||
return vi.fn().mockImplementation((config) => ({
|
||||
getClientType: () => 'transmission',
|
||||
getInstanceId: () => config.id,
|
||||
name: config.name,
|
||||
getActiveDownloads: jest.fn().mockResolvedValue([
|
||||
getActiveDownloads: vi.fn().mockResolvedValue([
|
||||
{ id: 'trans1', title: 'Trans Download 1', client: 'transmission' }
|
||||
]),
|
||||
testConnection: jest.fn().mockResolvedValue(true),
|
||||
getClientStatus: jest.fn().mockResolvedValue({ status: 'active' })
|
||||
testConnection: vi.fn().mockResolvedValue(true),
|
||||
getClientStatus: vi.fn().mockResolvedValue({ status: 'active' })
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -69,7 +71,7 @@ describe('DownloadClientRegistry', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
testRegistry = new DownloadClientRegistry();
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Initialization', () => {
|
||||
@@ -291,7 +293,7 @@ describe('DownloadClientRegistry', () => {
|
||||
|
||||
describe('Convenience Functions', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should delegate to singleton registry', async () => {
|
||||
|
||||
Reference in New Issue
Block a user