mirror of
https://github.com/zoriya/flood.git
synced 2026-06-07 12:24:50 +00:00
server: tests: enable tests for Transmission
This commit is contained in:
@@ -25,7 +25,8 @@ jobs:
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
|
||||
- run: sudo apt-get install -y rtorrent
|
||||
- run: sudo add-apt-repository -y ppa:transmissionbt/ppa
|
||||
- run: sudo apt-get install -y rtorrent transmission-daemon
|
||||
|
||||
- run: npm ci --no-optional
|
||||
- run: npm run build
|
||||
|
||||
@@ -7,5 +7,6 @@ module.exports = {
|
||||
'<rootDir>/server/.jest/rtorrent.config.js',
|
||||
// TODO: qBittorrent tests are disabled at the moment.
|
||||
// '<rootDir>/server/.jest/qbittorrent.config.js',
|
||||
'<rootDir>/server/.jest/transmission.config.js',
|
||||
],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
displayName: 'transmission',
|
||||
preset: 'ts-jest/presets/js-with-babel',
|
||||
rootDir: './../',
|
||||
testEnvironment: 'node',
|
||||
testPathIgnorePatterns: ['auth.test.ts'],
|
||||
setupFilesAfterEnv: ['<rootDir>/.jest/transmission.setup.js'],
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
isolatedModules: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import {spawn} from 'child_process';
|
||||
|
||||
const temporaryRuntimeDirectory = path.resolve(os.tmpdir(), `flood.test.${crypto.randomBytes(12).toString('hex')}`);
|
||||
|
||||
const transmissionSession = path.join(temporaryRuntimeDirectory, 'transmission');
|
||||
const rpcPort = Math.floor(Math.random() * (65534 - 20000) + 20000);
|
||||
|
||||
fs.mkdirSync(transmissionSession, {recursive: true});
|
||||
|
||||
const transmissionProcess = spawn(
|
||||
'transmission-daemon',
|
||||
[
|
||||
'-f',
|
||||
'-w',
|
||||
temporaryRuntimeDirectory,
|
||||
'-g',
|
||||
transmissionSession,
|
||||
'-p',
|
||||
`${rpcPort}`,
|
||||
'-u',
|
||||
'transmission',
|
||||
'-v',
|
||||
'transmission',
|
||||
],
|
||||
{
|
||||
stdio: 'ignore',
|
||||
killSignal: 'SIGKILL',
|
||||
},
|
||||
);
|
||||
|
||||
process.argv = ['node', 'flood'];
|
||||
process.argv.push('--rundir', temporaryRuntimeDirectory);
|
||||
process.argv.push('--allowedpath', temporaryRuntimeDirectory);
|
||||
process.argv.push('--auth', 'none');
|
||||
process.argv.push('--trurl', `http://127.0.0.1:${rpcPort}/transmission/rpc`);
|
||||
process.argv.push('--truser', 'transmission');
|
||||
process.argv.push('--trpass', 'transmission');
|
||||
|
||||
afterAll((done) => {
|
||||
transmissionProcess.on('close', () => {
|
||||
if (process.env.CI !== 'true') {
|
||||
// TODO: This leads to test flakiness caused by ENOENT error
|
||||
// NeDB provides no method to close database connection
|
||||
fs.rmdirSync(temporaryRuntimeDirectory, {recursive: true});
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
transmissionProcess.kill('SIGKILL');
|
||||
});
|
||||
@@ -9,6 +9,8 @@ const request = supertest(app);
|
||||
|
||||
const authToken = `jwt=${getAuthToken('_config')}`;
|
||||
|
||||
jest.setTimeout(20000);
|
||||
|
||||
describe('GET /api/client/connection-test', () => {
|
||||
it('Checks connection status', (done) => {
|
||||
request
|
||||
|
||||
@@ -130,9 +130,16 @@ describe('POST /api/torrents/add-urls', () => {
|
||||
|
||||
// Continue after 15 seconds even if torrentAdded is not resolved to let the next step
|
||||
// determine if the torrents have been successfully added.
|
||||
Promise.race([torrentAdded, new Promise((r) => setTimeout(r, 1000 * 15))]).then(() => {
|
||||
done();
|
||||
});
|
||||
Promise.race([torrentAdded, new Promise((r) => setTimeout(r, 1000 * 15))])
|
||||
.then(async () => {
|
||||
if (process.argv.includes('--trurl')) {
|
||||
// Torrents added to Transmission will be in checking status for a while.
|
||||
await new Promise((r) => setTimeout(r, 1000 * 3));
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -343,6 +350,12 @@ describe('POST /api/torrents/create', () => {
|
||||
addedTorrents.map(async (torrent) => {
|
||||
createdTorrentHash = torrent.hash;
|
||||
expect(torrent.isPrivate).toBe(createTorrentOptions.isPrivate);
|
||||
|
||||
if (process.argv.includes('--trurl')) {
|
||||
// TODO: Test skipped as Transmission does not support isCompleted and isBasePath
|
||||
return;
|
||||
}
|
||||
|
||||
expect(torrent.percentComplete).toBe(100);
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user