diff options
Diffstat (limited to 'test/utils.ts')
| -rw-r--r-- | test/utils.ts | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/test/utils.ts b/test/utils.ts index f67baf0048..af190254ec 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -2,6 +2,7 @@ import * as fs from 'fs'; import * as WebSocket from 'ws'; const fetch = require('node-fetch'); import * as req from 'request'; +import * as childProcess from 'child_process'; export const async = (fn: Function) => (done: Function) => { fn().then(() => { @@ -17,7 +18,7 @@ export const request = async (endpoint: string, params: any, me?: any): Promise< } : {}; try { - const res = await fetch('http://localhost:80/api' + endpoint, { + const res = await fetch('http://localhost:8080/api' + endpoint, { method: 'POST', body: JSON.stringify(Object.assign(auth, params)) }); @@ -65,7 +66,7 @@ export const react = async (user: any, note: any, reaction: string): Promise<any export const uploadFile = (user: any, path?: string): Promise<any> => new Promise((ok, rej) => { req.post({ - url: 'http://localhost:80/api/drive/files/create', + url: 'http://localhost:8080/api/drive/files/create', formData: { i: user.token, file: fs.createReadStream(path || __dirname + '/resources/Lenna.png') @@ -78,7 +79,7 @@ export const uploadFile = (user: any, path?: string): Promise<any> => new Promis export function connectStream(user: any, channel: string, listener: (message: Record<string, any>) => any, params?: any): Promise<WebSocket> { return new Promise((res, rej) => { - const ws = new WebSocket(`ws://localhost/streaming?i=${user.token}`); + const ws = new WebSocket(`ws://localhost:8080/streaming?i=${user.token}`); ws.on('open', () => { ws.on('message', data => { @@ -102,3 +103,16 @@ export function connectStream(user: any, channel: string, listener: (message: Re }); }); } + +export function launchServer(callbackSpawnedProcess: (p: childProcess.ChildProcess) => void, moreProcess: () => Promise<void> = async () => {}) { + return (done: (err?: Error) => any) => { + const p = childProcess.spawn('node', [__dirname + '/../index.js'], { + stdio: ['inherit', 'inherit', 'inherit', 'ipc'], + env: { NODE_ENV: 'test', PATH: process.env.PATH } + }); + callbackSpawnedProcess(p); + p.on('message', message => { + if (message === 'ok') moreProcess().then(() => done()).catch(e => done(e)); + }); + }; +} |