From 4d24741d4856c9af9ecd05475c820e924963e8ab Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 23 Jan 2019 13:35:22 +0900 Subject: [PATCH] Fix test --- src/server/index.ts | 13 +++++++++++++ test/api.ts | 5 ++++- test/streaming.ts | 10 +++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index 86dfd4b753..146a89a509 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -101,6 +101,19 @@ function createServer() { } } +// For testing +export const startServer = () => { + const server = createServer(); + + // Init stream server + require('./api/streaming')(server); + + // Listen + server.listen(config.port); + + return server; +}; + export default () => new Promise(resolve => { const server = createServer(); diff --git a/test/api.ts b/test/api.ts index fe41c751d9..c5f7eeaf43 100644 --- a/test/api.ts +++ b/test/api.ts @@ -27,7 +27,6 @@ process.on('unhandledRejection', console.dir); //#endregion const app = require('../built/server/api').default; -require('../built/server').default(); const db = require('../built/db/mongodb').default; const server = http.createServer(app.callback()); @@ -44,6 +43,10 @@ describe('API', () => { // Reset database each test beforeEach(resetDb(db)); + before(() => { + server.close(); + }); + describe('signup', () => { it('不正なユーザー名でアカウントが作成できない', async(async () => { const res = await request('/signup', { diff --git a/test/streaming.ts b/test/streaming.ts index a3022173b9..63ee1e8845 100644 --- a/test/streaming.ts +++ b/test/streaming.ts @@ -27,13 +27,13 @@ process.on('unhandledRejection', console.dir); //#endregion const app = require('../built/server/api').default; -require('../built/server').default(); +const server = require('../built/server').startServer(); const db = require('../built/db/mongodb').default; -const server = http.createServer(app.callback()); +const apiServer = http.createServer(app.callback()); //#region Utilities -const request = _request(server); +const request = _request(apiServer); const signup = _signup(request); //#endregion @@ -41,6 +41,10 @@ describe('Streaming', () => { // Reset database each test beforeEach(resetDb(db)); + before(() => { + server.close(); + }); + it('投稿がタイムラインに流れる', done => { const post = { text: 'foo'