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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2026 Gordon Bolton. MIT License.
const {
import {
DownloadClientRegistry,
registry,
initializeClients,
@@ -10,8 +10,8 @@ const {
getDownloadsByClientType,
testAllConnections,
getAllClientStatuses
} = require('../../server/utils/downloadClients');
const { vi } = require('vitest');
} from '../../server/utils/downloadClients.js';
import { vi } from 'vitest';
// Mock config and clients
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[0].name).toBe('Test1');
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[0].dlspeed).toBe(200);
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[0].name).toBe('Test2');
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 }
}
});
await client.getTorrents();
await client.getActiveDownloads();
mockSync(1, {
rid: 2,
@@ -246,7 +246,7 @@ describe('QBittorrentClient sync API', () => {
torrents_removed: ['hash01']
});
const torrents = await client.getTorrents();
const torrents = await client.getActiveDownloads();
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 }
]);
const torrents = await client.getTorrents();
const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('Fallback');
expect(client.fallbackThisCycle).toBe(true);
@@ -292,7 +292,7 @@ describe('QBittorrentClient sync API', () => {
.get('/api/v2/sync/maindata?rid=0')
.reply(200, { rid: 1, full_update: true });
const torrents = await client.getTorrents();
const torrents = await client.getActiveDownloads();
expect(torrents).toHaveLength(1);
expect(torrents[0].name).toBe('DirectLegacy');
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[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);
});
@@ -363,7 +363,7 @@ describe('QBittorrentClient sync API', () => {
// Simulate the reset that getAllTorrents performs
client.fallbackThisCycle = false;
const torrents = await client.getTorrents();
const torrents = await client.getActiveDownloads();
expect(torrents[0].name).toBe('ResetWorks');
expect(client.fallbackThisCycle).toBe(false);
});