Faster ci using compiled ts files
This commit is contained in:
parent
79db409a41
commit
3d470a530c
|
@ -25,7 +25,7 @@ runTest () {
|
||||||
joblog="$jobname-ci.log"
|
joblog="$jobname-ci.log"
|
||||||
|
|
||||||
parallel -j $jobs --retries $retries \
|
parallel -j $jobs --retries $retries \
|
||||||
"echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ts-node/register --require tsconfig-paths/register --bail {}" \
|
"echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ./dist/server/tests/register.js --bail {}" \
|
||||||
::: $files
|
::: $files
|
||||||
|
|
||||||
cat "$joblog" | uniq -c
|
cat "$joblog" | uniq -c
|
||||||
|
@ -33,63 +33,63 @@ runTest () {
|
||||||
}
|
}
|
||||||
|
|
||||||
findTestFiles () {
|
findTestFiles () {
|
||||||
find $1 -type f -name "*.ts" | grep -v "/index.ts" | xargs echo
|
find $1 -type f -name "*.js" | grep -v "/index.js" | xargs echo
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" = "misc" ]; then
|
if [ "$1" = "misc" ]; then
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
feedsFiles=$(findTestFiles server/tests/feeds)
|
feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
|
||||||
helperFiles=$(findTestFiles server/tests/helpers)
|
helperFiles=$(findTestFiles ./dist/server/tests/helpers)
|
||||||
pluginsFiles=$(findTestFiles server/tests/plugins)
|
pluginsFiles=$(findTestFiles ./dist/server/tests/plugins)
|
||||||
miscFiles="server/tests/client.ts server/tests/misc-endpoints.ts"
|
miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
|
||||||
|
|
||||||
MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $feedsFiles $helperFiles $pluginsFiles $miscFiles
|
MOCHA_PARALLEL=true runTest "$1" 2 $feedsFiles $helperFiles $pluginsFiles $miscFiles
|
||||||
elif [ "$1" = "cli" ]; then
|
elif [ "$1" = "cli" ]; then
|
||||||
npm run build:server
|
npm run build:server
|
||||||
npm run setup:cli
|
npm run setup:cli
|
||||||
|
|
||||||
cliFiles=$(findTestFiles server/tests/cli)
|
cliFiles=$(findTestFiles ./dist/server/tests/cli)
|
||||||
|
|
||||||
runTest "$1" 1 $cliFiles
|
runTest "$1" 1 $cliFiles
|
||||||
elif [ "$1" = "api-1" ]; then
|
elif [ "$1" = "api-1" ]; then
|
||||||
npm run build:server
|
npm run build:server
|
||||||
|
|
||||||
checkParamFiles=$(findTestFiles server/tests/api/check-params)
|
checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
|
||||||
notificationsFiles=$(findTestFiles server/tests/api/notifications)
|
notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
|
||||||
searchFiles=$(findTestFiles server/tests/api/search)
|
searchFiles=$(findTestFiles ./dist/server/tests/api/search)
|
||||||
|
|
||||||
MOCHA_PARALLEL=true runTest "$1" 3 $notificationsFiles $searchFiles $checkParamFiles
|
MOCHA_PARALLEL=true runTest "$1" 3 $notificationsFiles $searchFiles $checkParamFiles
|
||||||
elif [ "$1" = "api-2" ]; then
|
elif [ "$1" = "api-2" ]; then
|
||||||
npm run build:server
|
npm run build:server
|
||||||
|
|
||||||
serverFiles=$(findTestFiles server/tests/api/server)
|
serverFiles=$(findTestFiles ./dist/server/tests/api/server)
|
||||||
usersFiles=$(findTestFiles server/tests/api/users)
|
usersFiles=$(findTestFiles ./dist/server/tests/api/users)
|
||||||
liveFiles=$(findTestFiles server/tests/api/live)
|
liveFiles=$(findTestFiles ./dist/server/tests/api/live)
|
||||||
|
|
||||||
MOCHA_PARALLEL=true runTest "$1" 3 $serverFiles $usersFiles $liveFiles
|
MOCHA_PARALLEL=true runTest "$1" 3 $serverFiles $usersFiles $liveFiles
|
||||||
elif [ "$1" = "api-3" ]; then
|
elif [ "$1" = "api-3" ]; then
|
||||||
npm run build:server
|
npm run build:server
|
||||||
|
|
||||||
videosFiles=$(findTestFiles server/tests/api/videos)
|
videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
|
||||||
|
|
||||||
MOCHA_PARALLEL=true runTest "$1" 3 $videosFiles
|
MOCHA_PARALLEL=true runTest "$1" 3 $videosFiles
|
||||||
elif [ "$1" = "api-4" ]; then
|
elif [ "$1" = "api-4" ]; then
|
||||||
npm run build:server
|
npm run build:server
|
||||||
|
|
||||||
moderationFiles=$(findTestFiles server/tests/api/moderation)
|
moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
|
||||||
redundancyFiles=$(findTestFiles server/tests/api/redundancy)
|
redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
|
||||||
activitypubFiles=$(findTestFiles server/tests/api/activitypub)
|
activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
|
||||||
|
|
||||||
MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles
|
MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles
|
||||||
elif [ "$1" = "external-plugins" ]; then
|
elif [ "$1" = "external-plugins" ]; then
|
||||||
npm run build:server
|
npm run build:server
|
||||||
|
|
||||||
externalPluginsFiles=$(findTestFiles server/tests/external-plugins)
|
externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
|
||||||
|
|
||||||
runTest "$1" 1 $externalPluginsFiles
|
runTest "$1" 1 $externalPluginsFiles
|
||||||
elif [ "$1" = "lint" ]; then
|
elif [ "$1" = "lint" ]; then
|
||||||
npm run eslint -- --ext .ts "server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
|
npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
|
||||||
npm run swagger-cli -- validate support/doc/api/openapi.yaml
|
npm run swagger-cli -- validate support/doc/api/openapi.yaml
|
||||||
|
|
||||||
( cd client
|
( cd client
|
||||||
|
|
|
@ -6,13 +6,14 @@ import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs'
|
||||||
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
|
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
|
||||||
import { cloneDeep } from 'lodash'
|
import { cloneDeep } from 'lodash'
|
||||||
import { buildSignedActivity } from '../../../helpers/activitypub'
|
import { buildSignedActivity } from '../../../helpers/activitypub'
|
||||||
|
import { buildAbsoluteFixturePath } from '@shared/extra-utils'
|
||||||
|
|
||||||
describe('Test activity pub helpers', function () {
|
describe('Test activity pub helpers', function () {
|
||||||
describe('When checking the Linked Signature', function () {
|
describe('When checking the Linked Signature', function () {
|
||||||
|
|
||||||
it('Should fail with an invalid Mastodon signature', async function () {
|
it('Should fail with an invalid Mastodon signature', async function () {
|
||||||
const body = require('./json/mastodon/create-bad-signature.json')
|
const body = require(buildAbsoluteFixturePath('./ap-json/mastodon/create-bad-signature.json'))
|
||||||
const publicKey = require('./json/mastodon/public-key.json').publicKey
|
const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
|
||||||
const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
|
const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
|
||||||
|
|
||||||
const result = await isJsonLDSignatureVerified(fromActor as any, body)
|
const result = await isJsonLDSignatureVerified(fromActor as any, body)
|
||||||
|
@ -21,8 +22,8 @@ describe('Test activity pub helpers', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with an invalid public key', async function () {
|
it('Should fail with an invalid public key', async function () {
|
||||||
const body = require('./json/mastodon/create.json')
|
const body = require(buildAbsoluteFixturePath('./ap-json/mastodon/create.json'))
|
||||||
const publicKey = require('./json/mastodon/bad-public-key.json').publicKey
|
const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/bad-public-key.json')).publicKey
|
||||||
const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
|
const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
|
||||||
|
|
||||||
const result = await isJsonLDSignatureVerified(fromActor as any, body)
|
const result = await isJsonLDSignatureVerified(fromActor as any, body)
|
||||||
|
@ -31,8 +32,8 @@ describe('Test activity pub helpers', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with a valid Mastodon signature', async function () {
|
it('Should succeed with a valid Mastodon signature', async function () {
|
||||||
const body = require('./json/mastodon/create.json')
|
const body = require(buildAbsoluteFixturePath('./ap-json/mastodon/create.json'))
|
||||||
const publicKey = require('./json/mastodon/public-key.json').publicKey
|
const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
|
||||||
const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
|
const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
|
||||||
|
|
||||||
const result = await isJsonLDSignatureVerified(fromActor as any, body)
|
const result = await isJsonLDSignatureVerified(fromActor as any, body)
|
||||||
|
@ -41,8 +42,8 @@ describe('Test activity pub helpers', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with an invalid PeerTube signature', async function () {
|
it('Should fail with an invalid PeerTube signature', async function () {
|
||||||
const keys = require('./json/peertube/invalid-keys.json')
|
const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/invalid-keys.json'))
|
||||||
const body = require('./json/peertube/announce-without-context.json')
|
const body = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
|
||||||
|
|
||||||
const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey }
|
const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey }
|
||||||
const signedBody = await buildSignedActivity(actorSignature as any, body)
|
const signedBody = await buildSignedActivity(actorSignature as any, body)
|
||||||
|
@ -54,8 +55,8 @@ describe('Test activity pub helpers', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with a valid PeerTube signature', async function () {
|
it('Should succeed with a valid PeerTube signature', async function () {
|
||||||
const keys = require('./json/peertube/keys.json')
|
const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json'))
|
||||||
const body = require('./json/peertube/announce-without-context.json')
|
const body = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
|
||||||
|
|
||||||
const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey }
|
const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey }
|
||||||
const signedBody = await buildSignedActivity(actorSignature as any, body)
|
const signedBody = await buildSignedActivity(actorSignature as any, body)
|
||||||
|
@ -73,12 +74,12 @@ describe('Test activity pub helpers', function () {
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
req.url = '/accounts/ronan/inbox'
|
req.url = '/accounts/ronan/inbox'
|
||||||
|
|
||||||
const mastodonObject = cloneDeep(require('./json/mastodon/bad-http-signature.json'))
|
const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/bad-http-signature.json')))
|
||||||
req.body = mastodonObject.body
|
req.body = mastodonObject.body
|
||||||
req.headers = mastodonObject.headers
|
req.headers = mastodonObject.headers
|
||||||
|
|
||||||
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
|
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
|
||||||
const publicKey = require('./json/mastodon/public-key.json').publicKey
|
const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
|
||||||
|
|
||||||
const actor = { publicKey }
|
const actor = { publicKey }
|
||||||
const verified = isHTTPSignatureVerified(parsed, actor as any)
|
const verified = isHTTPSignatureVerified(parsed, actor as any)
|
||||||
|
@ -91,12 +92,12 @@ describe('Test activity pub helpers', function () {
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
req.url = '/accounts/ronan/inbox'
|
req.url = '/accounts/ronan/inbox'
|
||||||
|
|
||||||
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
|
const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
|
||||||
req.body = mastodonObject.body
|
req.body = mastodonObject.body
|
||||||
req.headers = mastodonObject.headers
|
req.headers = mastodonObject.headers
|
||||||
|
|
||||||
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
|
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
|
||||||
const publicKey = require('./json/mastodon/bad-public-key.json').publicKey
|
const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/bad-public-key.json')).publicKey
|
||||||
|
|
||||||
const actor = { publicKey }
|
const actor = { publicKey }
|
||||||
const verified = isHTTPSignatureVerified(parsed, actor as any)
|
const verified = isHTTPSignatureVerified(parsed, actor as any)
|
||||||
|
@ -109,7 +110,7 @@ describe('Test activity pub helpers', function () {
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
req.url = '/accounts/ronan/inbox'
|
req.url = '/accounts/ronan/inbox'
|
||||||
|
|
||||||
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
|
const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
|
||||||
req.body = mastodonObject.body
|
req.body = mastodonObject.body
|
||||||
req.headers = mastodonObject.headers
|
req.headers = mastodonObject.headers
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ describe('Test activity pub helpers', function () {
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
req.url = '/accounts/ronan/inbox'
|
req.url = '/accounts/ronan/inbox'
|
||||||
|
|
||||||
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
|
const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
|
||||||
req.body = mastodonObject.body
|
req.body = mastodonObject.body
|
||||||
req.headers = mastodonObject.headers
|
req.headers = mastodonObject.headers
|
||||||
req.headers = 'Signature ' + mastodonObject.headers
|
req.headers = 'Signature ' + mastodonObject.headers
|
||||||
|
@ -148,12 +149,12 @@ describe('Test activity pub helpers', function () {
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
req.url = '/accounts/ronan/inbox'
|
req.url = '/accounts/ronan/inbox'
|
||||||
|
|
||||||
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
|
const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
|
||||||
req.body = mastodonObject.body
|
req.body = mastodonObject.body
|
||||||
req.headers = mastodonObject.headers
|
req.headers = mastodonObject.headers
|
||||||
|
|
||||||
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
|
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
|
||||||
const publicKey = require('./json/mastodon/public-key.json').publicKey
|
const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
|
||||||
|
|
||||||
const actor = { publicKey }
|
const actor = { publicKey }
|
||||||
const verified = isHTTPSignatureVerified(parsed, actor as any)
|
const verified = isHTTPSignatureVerified(parsed, actor as any)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import * as chai from 'chai'
|
||||||
import { buildDigest } from '@server/helpers/peertube-crypto'
|
import { buildDigest } from '@server/helpers/peertube-crypto'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
closeAllSequelize,
|
closeAllSequelize,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
|
@ -40,7 +41,7 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnounceWithoutContext (server: ServerInfo) {
|
function getAnnounceWithoutContext (server: ServerInfo) {
|
||||||
const json = require('./json/peertube/announce-without-context.json')
|
const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
|
||||||
const result: typeof json = {}
|
const result: typeof json = {}
|
||||||
|
|
||||||
for (const key of Object.keys(json)) {
|
for (const key of Object.keys(json)) {
|
||||||
|
@ -58,8 +59,8 @@ describe('Test ActivityPub security', function () {
|
||||||
let servers: ServerInfo[]
|
let servers: ServerInfo[]
|
||||||
let url: string
|
let url: string
|
||||||
|
|
||||||
const keys = require('./json/peertube/keys.json')
|
const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json'))
|
||||||
const invalidKeys = require('./json/peertube/invalid-keys.json')
|
const invalidKeys = require(buildAbsoluteFixturePath('./ap-json/peertube/invalid-keys.json'))
|
||||||
const baseHttpSignature = () => ({
|
const baseHttpSignature = () => ({
|
||||||
algorithm: HTTP_SIGNATURE.ALGORITHM,
|
algorithm: HTTP_SIGNATURE.ALGORITHM,
|
||||||
authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
|
authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { omit } from 'lodash'
|
import { omit } from 'lodash'
|
||||||
import { join } from 'path'
|
|
||||||
import { LiveVideo, VideoPrivacy } from '@shared/models'
|
import { LiveVideo, VideoPrivacy } from '@shared/models'
|
||||||
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
|
@ -24,7 +25,6 @@ import {
|
||||||
userLogin,
|
userLogin,
|
||||||
waitUntilLivePublished
|
waitUntilLivePublished
|
||||||
} from '../../../../shared/extra-utils'
|
} from '../../../../shared/extra-utils'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
|
|
||||||
describe('Test video lives API validator', function () {
|
describe('Test video lives API validator', function () {
|
||||||
const path = '/api/v1/videos/live'
|
const path = '/api/v1/videos/live'
|
||||||
|
@ -180,7 +180,7 @@ describe('Test video lives API validator', function () {
|
||||||
it('Should fail with an incorrect thumbnail file', async function () {
|
it('Should fail with an incorrect thumbnail file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
|
thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -189,7 +189,7 @@ describe('Test video lives API validator', function () {
|
||||||
it('Should fail with a big thumbnail file', async function () {
|
it('Should fail with a big thumbnail file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
|
thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -198,7 +198,7 @@ describe('Test video lives API validator', function () {
|
||||||
it('Should fail with an incorrect preview file', async function () {
|
it('Should fail with an incorrect preview file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
previewfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
|
previewfile: buildAbsoluteFixturePath('video_short.mp4')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -207,7 +207,7 @@ describe('Test video lives API validator', function () {
|
||||||
it('Should fail with a big preview file', async function () {
|
it('Should fail with a big preview file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
previewfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
|
previewfile: buildAbsoluteFixturePath('preview-big.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { omit } from 'lodash'
|
import { omit } from 'lodash'
|
||||||
import { join } from 'path'
|
|
||||||
import { User, UserRole } from '../../../../shared'
|
import { User, UserRole } from '../../../../shared'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
addVideoChannel,
|
addVideoChannel,
|
||||||
blockUser,
|
blockUser,
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
deleteMe,
|
deleteMe,
|
||||||
|
@ -600,7 +600,7 @@ describe('Test users API validators', function () {
|
||||||
it('Should fail without an incorrect input file', async function () {
|
it('Should fail without an incorrect input file', async function () {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
|
avatarfile: buildAbsoluteFixturePath('video_short.mp4')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
|
||||||
})
|
})
|
||||||
|
@ -608,7 +608,7 @@ describe('Test users API validators', function () {
|
||||||
it('Should fail with a big file', async function () {
|
it('Should fail with a big file', async function () {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
|
avatarfile: buildAbsoluteFixturePath('avatar-big.png')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
|
||||||
})
|
})
|
||||||
|
@ -616,7 +616,7 @@ describe('Test users API validators', function () {
|
||||||
it('Should fail with an unauthenticated user', async function () {
|
it('Should fail with an unauthenticated user', async function () {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
|
avatarfile: buildAbsoluteFixturePath('avatar.png')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({
|
await makeUploadRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
@ -630,7 +630,7 @@ describe('Test users API validators', function () {
|
||||||
it('Should succeed with the correct params', async function () {
|
it('Should succeed with the correct params', async function () {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
|
avatarfile: buildAbsoluteFixturePath('avatar.png')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({
|
await makeUploadRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
|
|
||||||
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
|
@ -13,9 +16,7 @@ import {
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
userLogin
|
userLogin
|
||||||
} from '../../../../shared/extra-utils'
|
} from '../../../../shared/extra-utils'
|
||||||
import { join } from 'path'
|
|
||||||
import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
|
import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
|
|
||||||
describe('Test video captions API validator', function () {
|
describe('Test video captions API validator', function () {
|
||||||
const path = '/api/v1/videos/'
|
const path = '/api/v1/videos/'
|
||||||
|
@ -51,7 +52,7 @@ describe('Test video captions API validator', function () {
|
||||||
describe('When adding video caption', function () {
|
describe('When adding video caption', function () {
|
||||||
const fields = { }
|
const fields = { }
|
||||||
const attaches = {
|
const attaches = {
|
||||||
captionfile: join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
|
captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Should fail without a valid uuid', async function () {
|
it('Should fail without a valid uuid', async function () {
|
||||||
|
@ -129,7 +130,7 @@ describe('Test video captions API validator', function () {
|
||||||
// We accept any file now
|
// We accept any file now
|
||||||
// it('Should fail with an invalid captionfile extension', async function () {
|
// it('Should fail with an invalid captionfile extension', async function () {
|
||||||
// const attaches = {
|
// const attaches = {
|
||||||
// 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
|
// 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// const captionPath = path + videoUUID + '/captions/fr'
|
// const captionPath = path + videoUUID + '/captions/fr'
|
||||||
|
@ -171,7 +172,7 @@ describe('Test video captions API validator', function () {
|
||||||
// We don't check the file validity yet
|
// We don't check the file validity yet
|
||||||
// it('Should fail with an invalid captionfile srt', async function () {
|
// it('Should fail with an invalid captionfile srt', async function () {
|
||||||
// const attaches = {
|
// const attaches = {
|
||||||
// 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
|
// 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// const captionPath = path + videoUUID + '/captions/fr'
|
// const captionPath = path + videoUUID + '/captions/fr'
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { omit } from 'lodash'
|
import { omit } from 'lodash'
|
||||||
import 'mocha'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
deleteVideoChannel,
|
deleteVideoChannel,
|
||||||
|
@ -23,9 +25,7 @@ import {
|
||||||
checkBadSortPagination,
|
checkBadSortPagination,
|
||||||
checkBadStartPagination
|
checkBadStartPagination
|
||||||
} from '../../../../shared/extra-utils/requests/check-api-params'
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
||||||
import { join } from 'path'
|
|
||||||
import { VideoChannelUpdate } from '../../../../shared/models/videos'
|
import { VideoChannelUpdate } from '../../../../shared/models/videos'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ describe('Test video channels API validator', function () {
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
[type + 'file']: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
|
[type + 'file']: buildAbsoluteFixturePath('video_short.mp4')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
|
||||||
|
@ -257,7 +257,7 @@ describe('Test video channels API validator', function () {
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
[type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
|
[type + 'file']: buildAbsoluteFixturePath('avatar-big.png')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ describe('Test video channels API validator', function () {
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
[type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
|
[type + 'file']: buildAbsoluteFixturePath('avatar.png')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({
|
await makeUploadRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
@ -283,7 +283,7 @@ describe('Test video channels API validator', function () {
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
const attaches = {
|
const attaches = {
|
||||||
[type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
|
[type + 'file']: buildAbsoluteFixturePath('avatar.png')
|
||||||
}
|
}
|
||||||
await makeUploadRequest({
|
await makeUploadRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { omit } from 'lodash'
|
import { omit } from 'lodash'
|
||||||
import { join } from 'path'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
|
@ -22,9 +23,8 @@ import {
|
||||||
checkBadSortPagination,
|
checkBadSortPagination,
|
||||||
checkBadStartPagination
|
checkBadStartPagination
|
||||||
} from '../../../../shared/extra-utils/requests/check-api-params'
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
||||||
import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
|
import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports'
|
||||||
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
|
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
|
|
||||||
describe('Test video imports API validator', function () {
|
describe('Test video imports API validator', function () {
|
||||||
const path = '/api/v1/videos/imports'
|
const path = '/api/v1/videos/imports'
|
||||||
|
@ -201,7 +201,7 @@ describe('Test video imports API validator', function () {
|
||||||
it('Should fail with an incorrect thumbnail file', async function () {
|
it('Should fail with an incorrect thumbnail file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
|
thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -210,7 +210,7 @@ describe('Test video imports API validator', function () {
|
||||||
it('Should fail with a big thumbnail file', async function () {
|
it('Should fail with a big thumbnail file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
|
thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -219,7 +219,7 @@ describe('Test video imports API validator', function () {
|
||||||
it('Should fail with an incorrect preview file', async function () {
|
it('Should fail with an incorrect preview file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
previewfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
|
previewfile: buildAbsoluteFixturePath('video_short.mp4')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -228,7 +228,7 @@ describe('Test video imports API validator', function () {
|
||||||
it('Should fail with a big preview file', async function () {
|
it('Should fail with a big preview file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
previewfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
|
previewfile: buildAbsoluteFixturePath('preview-big.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -237,7 +237,7 @@ describe('Test video imports API validator', function () {
|
||||||
it('Should fail with an invalid torrent file', async function () {
|
it('Should fail with an invalid torrent file', async function () {
|
||||||
const fields = omit(baseCorrectParams, 'targetUrl')
|
const fields = omit(baseCorrectParams, 'targetUrl')
|
||||||
const attaches = {
|
const attaches = {
|
||||||
torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
|
torrentfile: buildAbsoluteFixturePath('avatar-big.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||||
|
@ -312,7 +312,7 @@ describe('Test video imports API validator', function () {
|
||||||
|
|
||||||
fields = omit(fields, 'magnetUri')
|
fields = omit(fields, 'magnetUri')
|
||||||
const attaches = {
|
const attaches = {
|
||||||
torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
|
torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
|
||||||
}
|
}
|
||||||
|
|
||||||
await makeUploadRequest({
|
await makeUploadRequest({
|
||||||
|
|
|
@ -54,6 +54,10 @@ describe('Test contact form', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to send another contact form because of the anti spam checker', async function () {
|
it('Should not be able to send another contact form because of the anti spam checker', async function () {
|
||||||
|
this.timeout(10000)
|
||||||
|
|
||||||
|
await wait(1000)
|
||||||
|
|
||||||
await sendContactForm({
|
await sendContactForm({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
fromEmail: 'toto@example.com',
|
fromEmail: 'toto@example.com',
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { join } from 'path'
|
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import {
|
import {
|
||||||
addVideoChannel,
|
addVideoChannel,
|
||||||
|
buildAbsoluteFixturePath,
|
||||||
checkTmpIsEmpty,
|
checkTmpIsEmpty,
|
||||||
checkVideoFilesWereRemoved,
|
checkVideoFilesWereRemoved,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
|
@ -1018,9 +1018,7 @@ describe('Test multiple servers', function () {
|
||||||
.field('privacy', '1')
|
.field('privacy', '1')
|
||||||
.field('channelId', '1')
|
.field('channelId', '1')
|
||||||
|
|
||||||
const filePath = join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
|
await req.attach('videofile', buildAbsoluteFixturePath('video_short.webm'))
|
||||||
|
|
||||||
await req.attach('videofile', filePath)
|
|
||||||
.expect(HttpStatusCode.OK_200)
|
.expect(HttpStatusCode.OK_200)
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
|
@ -326,7 +326,7 @@ describe('Test plugin filter hooks', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should blacklist on remote upload', async function () {
|
it('Should blacklist on remote upload', async function () {
|
||||||
this.timeout(60000)
|
this.timeout(120000)
|
||||||
|
|
||||||
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
|
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
@ -335,7 +335,7 @@ describe('Test plugin filter hooks', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should blacklist on remote update', async function () {
|
it('Should blacklist on remote update', async function () {
|
||||||
this.timeout(60000)
|
this.timeout(120000)
|
||||||
|
|
||||||
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
|
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { registerTSPaths } from '../helpers/register-ts-paths'
|
||||||
|
|
||||||
|
registerTSPaths()
|
|
@ -1,27 +0,0 @@
|
||||||
const MailDev = require('maildev')
|
|
||||||
|
|
||||||
// must run maildev as forked ChildProcess
|
|
||||||
// failed instantiation stops main process with exit code 0
|
|
||||||
process.on('message', (msg) => {
|
|
||||||
if (msg.start) {
|
|
||||||
const maildev = new MailDev({
|
|
||||||
ip: '127.0.0.1',
|
|
||||||
smtp: msg.port,
|
|
||||||
disableWeb: true,
|
|
||||||
silent: true
|
|
||||||
})
|
|
||||||
|
|
||||||
maildev.on('new', email => {
|
|
||||||
process.send({ email })
|
|
||||||
})
|
|
||||||
|
|
||||||
maildev.listen(err => {
|
|
||||||
if (err) {
|
|
||||||
// cannot send as Error object
|
|
||||||
return process.send({ err: err.message })
|
|
||||||
}
|
|
||||||
|
|
||||||
return process.send({ err: null })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { ChildProcess, fork } from 'child_process'
|
import { ChildProcess } from 'child_process'
|
||||||
import { join } from 'path'
|
|
||||||
import { randomInt } from '../../core-utils/miscs/miscs'
|
import { randomInt } from '../../core-utils/miscs/miscs'
|
||||||
import { parallelTests } from '../server/servers'
|
import { parallelTests } from '../server/servers'
|
||||||
|
|
||||||
|
const MailDev = require('maildev')
|
||||||
|
|
||||||
class MockSmtpServer {
|
class MockSmtpServer {
|
||||||
|
|
||||||
private static instance: MockSmtpServer
|
private static instance: MockSmtpServer
|
||||||
|
@ -10,38 +11,32 @@ class MockSmtpServer {
|
||||||
private emailChildProcess: ChildProcess
|
private emailChildProcess: ChildProcess
|
||||||
private emails: object[]
|
private emails: object[]
|
||||||
|
|
||||||
private constructor () {
|
private constructor () { }
|
||||||
this.emailChildProcess = fork(join(__dirname, 'email-child-process'), [])
|
|
||||||
|
|
||||||
this.emailChildProcess.on('message', (msg: any) => {
|
|
||||||
if (msg.email) {
|
|
||||||
return this.emails.push(msg.email)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
process.on('exit', () => this.kill())
|
|
||||||
}
|
|
||||||
|
|
||||||
collectEmails (emailsCollection: object[]) {
|
collectEmails (emailsCollection: object[]) {
|
||||||
return new Promise<number>((res, rej) => {
|
return new Promise<number>((res, rej) => {
|
||||||
const port = parallelTests() ? randomInt(1000, 2000) : 1025
|
const port = parallelTests() ? randomInt(1000, 2000) : 1025
|
||||||
|
this.emails = emailsCollection
|
||||||
|
|
||||||
if (this.started) {
|
if (this.started) {
|
||||||
this.emails = emailsCollection
|
|
||||||
return res(undefined)
|
return res(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure maildev isn't started until
|
const maildev = new MailDev({
|
||||||
// unexpected exit can be reported to test runner
|
ip: '127.0.0.1',
|
||||||
this.emailChildProcess.send({ start: true, port })
|
smtp: port,
|
||||||
this.emailChildProcess.on('exit', () => {
|
disableWeb: true,
|
||||||
return rej(new Error('maildev exited unexpectedly, confirm port not in use'))
|
silent: true
|
||||||
})
|
})
|
||||||
this.emailChildProcess.on('message', (msg: any) => {
|
|
||||||
if (msg.err) return rej(new Error(msg.err))
|
maildev.on('new', email => {
|
||||||
|
this.emails.push(email)
|
||||||
|
})
|
||||||
|
|
||||||
|
maildev.listen(err => {
|
||||||
|
if (err) return rej(err)
|
||||||
|
|
||||||
this.started = true
|
this.started = true
|
||||||
this.emails = emailsCollection
|
|
||||||
|
|
||||||
return res(port)
|
return res(port)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue