サーバー起動処理を共通化
This commit is contained in:
@@ -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(() => {
|
||||
@@ -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', '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));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user