fix: convert test files to ES modules and fix qbittorrent test method calls
Some checks failed
Build and Push Docker Image / build (push) Successful in 37s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 45s
CI / Security audit (push) Successful in 1m3s
CI / Tests & coverage (push) Failing after 1m18s

- Convert all client test files from CommonJS require() to ES module import syntax
- Convert downloadClients.test.js and integration/downloadClients.test.js to ES modules
- Fix qbittorrent.test.js to use getActiveDownloads() instead of getTorrents()
- All test files now use proper Vitest-compatible ES module syntax
- Resolves Vitest import errors and QBittorrentClient method call errors
This commit is contained in:
2026-05-19 12:19:04 +01:00
parent cc0e34b3d1
commit 5342170ced
7 changed files with 28 additions and 28 deletions

View File

@@ -1,11 +1,11 @@
// Copyright (c) 2026 Gordon Bolton. MIT License. // Copyright (c) 2026 Gordon Bolton. MIT License.
const { import {
initializeClients, initializeClients,
getAllDownloads, getAllDownloads,
getDownloadsByClientType, getDownloadsByClientType,
testAllConnections testAllConnections
} = require('../../server/utils/downloadClients'); } from '../../server/utils/downloadClients.js';
const { vi } = require('vitest'); import { vi } from 'vitest';
// Mock environment variables for testing // Mock environment variables for testing
process.env.SABNZBD_INSTANCES = JSON.stringify([ process.env.SABNZBD_INSTANCES = JSON.stringify([

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2026 Gordon Bolton. MIT License. // Copyright (c) 2026 Gordon Bolton. MIT License.
const QBittorrentClient = require('../../../server/clients/QBittorrentClient'); import QBittorrentClient from '../../../server/clients/QBittorrentClient.js';
const axios = require('axios'); import axios from 'axios';
const { vi } = require('vitest'); import { vi } from 'vitest';
// Mock axios // Mock axios
vi.mock('axios'); vi.mock('axios');

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2026 Gordon Bolton. MIT License. // Copyright (c) 2026 Gordon Bolton. MIT License.
const RTorrentClient = require('../../../server/clients/RTorrentClient'); import RTorrentClient from '../../../server/clients/RTorrentClient.js';
const xmlrpc = require('xmlrpc'); import xmlrpc from 'xmlrpc';
const { vi } = require('vitest'); import { vi } from 'vitest';
vi.mock('xmlrpc', () => ({ vi.mock('xmlrpc', () => ({
createClient: vi.fn() createClient: vi.fn()

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2026 Gordon Bolton. MIT License. // Copyright (c) 2026 Gordon Bolton. MIT License.
const SABnzbdClient = require('../../../server/clients/SABnzbdClient'); import SABnzbdClient from '../../../server/clients/SABnzbdClient.js';
const axios = require('axios'); import axios from 'axios';
const { vi } = require('vitest'); import { vi } from 'vitest';
// Mock axios // Mock axios
vi.mock('axios'); vi.mock('axios');

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2026 Gordon Bolton. MIT License. // Copyright (c) 2026 Gordon Bolton. MIT License.
const TransmissionClient = require('../../../server/clients/TransmissionClient'); import TransmissionClient from '../../../server/clients/TransmissionClient.js';
const axios = require('axios'); import axios from 'axios';
const { vi } = require('vitest'); import { vi } from 'vitest';
// Mock axios // Mock axios
vi.mock('axios'); vi.mock('axios');

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2026 Gordon Bolton. MIT License. // Copyright (c) 2026 Gordon Bolton. MIT License.
const { import {
DownloadClientRegistry, DownloadClientRegistry,
registry, registry,
initializeClients, initializeClients,
@@ -10,8 +10,8 @@ const {
getDownloadsByClientType, getDownloadsByClientType,
testAllConnections, testAllConnections,
getAllClientStatuses getAllClientStatuses
} = require('../../server/utils/downloadClients'); } from '../../server/utils/downloadClients.js';
const { vi } = require('vitest'); import { vi } from 'vitest';
// Mock config and clients // Mock config and clients
vi.mock('../../server/utils/config', () => ({ vi.mock('../../server/utils/config', () => ({

View File

@@ -156,7 +156,7 @@ describe('QBittorrentClient sync API', () => {
} }
}); });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1); expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('Test1'); expect(torrents[0].name).toBe('Test1');
expect(torrents[0].instanceId).toBe('test-qbt'); expect(torrents[0].instanceId).toBe('test-qbt');
@@ -188,7 +188,7 @@ describe('QBittorrentClient sync API', () => {
} }
}); });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1); expect(torrents).toHaveLength(1);
expect(torrents[0].dlspeed).toBe(200); expect(torrents[0].dlspeed).toBe(200);
expect(torrents[0].name).toBe('Test1'); expect(torrents[0].name).toBe('Test1');
@@ -219,7 +219,7 @@ describe('QBittorrentClient sync API', () => {
} }
}); });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1); expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('Test2'); expect(torrents[0].name).toBe('Test2');
expect(torrents[0].hash).toBe('hash02'); expect(torrents[0].hash).toBe('hash02');
@@ -238,7 +238,7 @@ describe('QBittorrentClient sync API', () => {
hash01: { name: 'Test1', state: 'downloading', size: 1000, progress: 0.5, dlspeed: 100, eta: 60, num_seeds: 5, num_leechs: 2, availability: 1.0 } hash01: { name: 'Test1', state: 'downloading', size: 1000, progress: 0.5, dlspeed: 100, eta: 60, num_seeds: 5, num_leechs: 2, availability: 1.0 }
} }
}); });
await client.getTorrents(); await client.getActiveDownloads();
mockSync(1, { mockSync(1, {
rid: 2, rid: 2,
@@ -246,7 +246,7 @@ describe('QBittorrentClient sync API', () => {
torrents_removed: ['hash01'] torrents_removed: ['hash01']
}); });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(0); expect(torrents).toHaveLength(0);
}); });
@@ -267,7 +267,7 @@ describe('QBittorrentClient sync API', () => {
{ name: 'Fallback', hash: 'fb01', state: 'downloading', size: 1073741824, progress: 0.5, dlspeed: 1048576, eta: 512, num_seeds: 10, num_leechs: 3, availability: 1.0 } { name: 'Fallback', hash: 'fb01', state: 'downloading', size: 1073741824, progress: 0.5, dlspeed: 1048576, eta: 512, num_seeds: 10, num_leechs: 3, availability: 1.0 }
]); ]);
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1); expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('Fallback'); expect(torrents[0].name).toBe('Fallback');
expect(client.fallbackThisCycle).toBe(true); expect(client.fallbackThisCycle).toBe(true);
@@ -292,7 +292,7 @@ describe('QBittorrentClient sync API', () => {
.get('/api/v2/sync/maindata?rid=0') .get('/api/v2/sync/maindata?rid=0')
.reply(200, { rid: 1, full_update: true }); .reply(200, { rid: 1, full_update: true });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1); expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('DirectLegacy'); expect(torrents[0].name).toBe('DirectLegacy');
expect(syncScope.isDone()).toBe(false); expect(syncScope.isDone()).toBe(false);
@@ -324,7 +324,7 @@ describe('QBittorrentClient sync API', () => {
} }
}); });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1); expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('AfterReauth'); expect(torrents[0].name).toBe('AfterReauth');
}); });
@@ -342,7 +342,7 @@ describe('QBittorrentClient sync API', () => {
} }
}); });
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents[0].completed).toBe(500); expect(torrents[0].completed).toBe(500);
}); });
@@ -363,7 +363,7 @@ describe('QBittorrentClient sync API', () => {
// Simulate the reset that getAllTorrents performs // Simulate the reset that getAllTorrents performs
client.fallbackThisCycle = false; client.fallbackThisCycle = false;
const torrents = await client.getTorrents(); const torrents = await client.getActiveDownloads();
expect(torrents[0].name).toBe('ResetWorks'); expect(torrents[0].name).toBe('ResetWorks');
expect(client.fallbackThisCycle).toBe(false); expect(client.fallbackThisCycle).toBe(false);
}); });