1 import { join } from 'path'
2 import * as WebTorrent from 'webtorrent'
4 let webtorrent = new WebTorrent()
6 function immutableAssign <T, U> (target: T, source: U) {
7 return Object.assign<{}, T, U>({}, target, source)
10 // Default interval -> 5 minutes
11 function dateIsValid (dateString: string, interval = 300000) {
12 const dateToCheck = new Date(dateString)
13 const now = new Date()
15 return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval
18 function wait (milliseconds: number) {
19 return new Promise(resolve => setTimeout(resolve, milliseconds))
22 function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
23 if (refreshWebTorrent === true) webtorrent = new WebTorrent()
25 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
29 // We are in server/tests/utils/miscs
30 return join(__dirname, '..', '..', '..', '..')
33 // ---------------------------------------------------------------------------