サーバー起動処理を共通化
This commit is contained in:
parent
6e16c9389f
commit
cc7cc56abe
|
@ -16,20 +16,12 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post } from './utils';
|
import { async, signup, request, post, launchServer } from './utils';
|
||||||
|
|
||||||
describe('API visibility', () => {
|
describe('API visibility', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
|
|
||||||
before(done => {
|
before(launchServer(g => p = g));
|
||||||
p = childProcess.spawn('node', [__dirname + '/../index.js'], {
|
|
||||||
stdio: ['inherit', 'inherit', 'ipc'],
|
|
||||||
env: { NODE_ENV: 'test', PATH: process.env.PATH }
|
|
||||||
});
|
|
||||||
p.on('message', message => {
|
|
||||||
if (message === 'ok') done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
p.kill();
|
p.kill();
|
||||||
|
|
16
test/mute.ts
16
test/mute.ts
|
@ -16,7 +16,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, react, connectStream } from './utils';
|
import { async, signup, request, post, react, connectStream, launchServer } from './utils';
|
||||||
|
|
||||||
describe('Mute', () => {
|
describe('Mute', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
|
@ -26,21 +26,11 @@ describe('Mute', () => {
|
||||||
let bob: any;
|
let bob: any;
|
||||||
let carol: any;
|
let carol: any;
|
||||||
|
|
||||||
before(done => {
|
before(launchServer(g => p = g, async () => {
|
||||||
p = childProcess.spawn('node', [__dirname + '/../index.js'], {
|
|
||||||
stdio: ['inherit', 'inherit', 'ipc'],
|
|
||||||
env: { NODE_ENV: 'test', PATH: process.env.PATH }
|
|
||||||
});
|
|
||||||
p.on('message', async message => {
|
|
||||||
if (message === 'ok') {
|
|
||||||
(p.channel as any).onread = () => {};
|
|
||||||
alice = await signup({ username: 'alice' });
|
alice = await signup({ username: 'alice' });
|
||||||
bob = await signup({ username: 'bob' });
|
bob = await signup({ username: 'bob' });
|
||||||
carol = await signup({ username: 'carol' });
|
carol = await signup({ username: 'carol' });
|
||||||
done();
|
}));
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
p.kill();
|
p.kill();
|
||||||
|
|
19
test/note.ts
19
test/note.ts
|
@ -16,7 +16,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, uploadFile } from './utils';
|
import { async, signup, request, post, uploadFile, launchServer } from './utils';
|
||||||
import { Note } from '../src/models/entities/note';
|
import { Note } from '../src/models/entities/note';
|
||||||
import { initDb } from '../src/db/postgre';
|
import { initDb } from '../src/db/postgre';
|
||||||
|
|
||||||
|
@ -27,23 +27,12 @@ describe('Note', () => {
|
||||||
let alice: any;
|
let alice: any;
|
||||||
let bob: any;
|
let bob: any;
|
||||||
|
|
||||||
before(done => {
|
before(launchServer(g => p = g, async () => {
|
||||||
p = childProcess.spawn('node', [__dirname + '/../index.js'], {
|
const connection = await initDb(true);
|
||||||
stdio: ['inherit', 'inherit', 'ipc'],
|
|
||||||
env: { NODE_ENV: 'test', PATH: process.env.PATH }
|
|
||||||
});
|
|
||||||
p.on('message', message => {
|
|
||||||
if (message === 'ok') {
|
|
||||||
(p.channel as any).onread = () => {};
|
|
||||||
initDb(true).then(async connection => {
|
|
||||||
Notes = connection.getRepository(Note);
|
Notes = connection.getRepository(Note);
|
||||||
alice = await signup({ username: 'alice' });
|
alice = await signup({ username: 'alice' });
|
||||||
bob = await signup({ username: 'bob' });
|
bob = await signup({ username: 'bob' });
|
||||||
done();
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
p.kill();
|
p.kill();
|
||||||
|
|
|
@ -16,7 +16,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { connectStream, signup, request, post } from './utils';
|
import { connectStream, signup, request, post, launchServer } from './utils';
|
||||||
import { Following } from '../built/models/entities/following';
|
import { Following } from '../built/models/entities/following';
|
||||||
const initDb = require('../built/db/postgre.js').initDb;
|
const initDb = require('../built/db/postgre.js').initDb;
|
||||||
|
|
||||||
|
@ -24,21 +24,10 @@ describe('Streaming', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
let Followings: any;
|
let Followings: any;
|
||||||
|
|
||||||
beforeEach(done => {
|
beforeEach(launchServer(g => p = g, async () => {
|
||||||
p = childProcess.spawn('node', [__dirname + '/../index.js'], {
|
const connection = await initDb(true);
|
||||||
stdio: ['inherit', 'inherit', 'ipc'],
|
|
||||||
env: { NODE_ENV: 'test', PATH: process.env.PATH }
|
|
||||||
});
|
|
||||||
p.on('message', message => {
|
|
||||||
if (message === 'ok') {
|
|
||||||
(p.channel as any).onread = () => {};
|
|
||||||
initDb(true).then(async (connection: any) => {
|
|
||||||
Followings = connection.getRepository(Following);
|
Followings = connection.getRepository(Following);
|
||||||
done();
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
p.kill();
|
p.kill();
|
||||||
|
|
|
@ -16,7 +16,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, uploadFile } from './utils';
|
import { async, signup, request, post, uploadFile, launchServer } from './utils';
|
||||||
|
|
||||||
describe('users/notes', () => {
|
describe('users/notes', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
|
@ -26,15 +26,7 @@ describe('users/notes', () => {
|
||||||
let pngNote: any;
|
let pngNote: any;
|
||||||
let jpgPngNote: any;
|
let jpgPngNote: any;
|
||||||
|
|
||||||
before(done => {
|
before(launchServer(g => p = g, async () => {
|
||||||
p = childProcess.spawn('node', [__dirname + '/../index.js'], {
|
|
||||||
stdio: ['inherit', 'inherit', 'ipc'],
|
|
||||||
env: { NODE_ENV: 'test', PATH: process.env.PATH }
|
|
||||||
});
|
|
||||||
p.on('message', async message => {
|
|
||||||
if (message === 'ok') {
|
|
||||||
(p.channel as any).onread = () => {};
|
|
||||||
|
|
||||||
alice = await signup({ username: 'alice' });
|
alice = await signup({ username: 'alice' });
|
||||||
const jpg = await uploadFile(alice, __dirname + '/resources/Lenna.jpg');
|
const jpg = await uploadFile(alice, __dirname + '/resources/Lenna.jpg');
|
||||||
const png = await uploadFile(alice, __dirname + '/resources/Lenna.png');
|
const png = await uploadFile(alice, __dirname + '/resources/Lenna.png');
|
||||||
|
@ -47,11 +39,7 @@ describe('users/notes', () => {
|
||||||
jpgPngNote = await post(alice, {
|
jpgPngNote = await post(alice, {
|
||||||
fileIds: [jpg.id, png.id]
|
fileIds: [jpg.id, png.id]
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
p.kill();
|
p.kill();
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as fs from 'fs';
|
||||||
import * as WebSocket from 'ws';
|
import * as WebSocket from 'ws';
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
import * as req from 'request';
|
import * as req from 'request';
|
||||||
|
import * as childProcess from 'child_process';
|
||||||
|
|
||||||
export const async = (fn: Function) => (done: Function) => {
|
export const async = (fn: Function) => (done: Function) => {
|
||||||
fn().then(() => {
|
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));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue