From fdbda9e3d6564ec908733c7019305f6a3c363a9f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Sep 2017 15:27:35 +0200 Subject: Add tests for npm run scripts --- server/tests/utils/cli.ts | 24 ++++++++++++++++++++++++ server/tests/utils/index.ts | 1 + server/tests/utils/servers.ts | 9 ++++++++- server/tests/utils/videos.ts | 17 ++++++++++++++++- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 server/tests/utils/cli.ts (limited to 'server/tests/utils') diff --git a/server/tests/utils/cli.ts b/server/tests/utils/cli.ts new file mode 100644 index 000000000..5f07a832e --- /dev/null +++ b/server/tests/utils/cli.ts @@ -0,0 +1,24 @@ +import { exec } from 'child_process' + +import { ServerInfo } from './servers' + +function getEnvCli (server?: ServerInfo) { + return `NODE_ENV=test NODE_APP_INSTANCE=${server.serverNumber}` +} + +async function execCLI (command: string) { + return new Promise((res, rej) => { + exec(command, (err, stdout, stderr) => { + if (err) return rej(err) + + return res(stdout) + }) + }) +} + +// --------------------------------------------------------------------------- + +export { + execCLI, + getEnvCli +} diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 9077b0568..0fa28f2af 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts @@ -1,3 +1,4 @@ +export * from './cli' export * from './clients' export * from './config' export * from './login' diff --git a/server/tests/utils/servers.ts b/server/tests/utils/servers.ts index 272a8935e..88027f74e 100644 --- a/server/tests/utils/servers.ts +++ b/server/tests/utils/servers.ts @@ -5,6 +5,7 @@ interface ServerInfo { app: ChildProcess, url: string host: string + serverNumber: number client: { id: string, @@ -65,9 +66,10 @@ function flushTests () { }) } -function runServer (serverNumber: number) { +function runServer (serverNumber: number, configOverride?: Object) { const server: ServerInfo = { app: null, + serverNumber: serverNumber, url: `http://localhost:${9000 + serverNumber}`, host: `localhost:${9000 + serverNumber}`, client: { @@ -98,6 +100,11 @@ function runServer (serverNumber: number) { const env = Object.create(process.env) env['NODE_ENV'] = 'test' env['NODE_APP_INSTANCE'] = serverNumber.toString() + + if (configOverride !== undefined) { + env['NODE_CONFIG'] = JSON.stringify(configOverride) + } + const options = { silent: true, env: env, diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 42b7dd05a..509a2430a 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts @@ -1,8 +1,11 @@ +import { readFile } from 'fs' import * as request from 'supertest' import { join, isAbsolute } from 'path' +import * as parseTorrent from 'parse-torrent' import { makeGetRequest } from './requests' import { readFilePromise } from './miscs' +import { ServerInfo } from './servers' type VideoAttributes = { name?: string @@ -232,6 +235,17 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string .expect(specialStatus) } +function parseTorrentVideo (server: ServerInfo, videoUUID: string) { + return new Promise((res, rej) => { + const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', videoUUID + '.torrent') + readFile(torrentPath, (err, data) => { + if (err) return rej(err) + + return res(parseTorrent(data)) + }) + }) +} + // --------------------------------------------------------------------------- export { @@ -250,5 +264,6 @@ export { testVideoImage, uploadVideo, updateVideo, - rateVideo + rateVideo, + parseTorrentVideo } -- cgit v1.2.3