This commit is contained in:
syuilo 2019-01-23 13:35:22 +09:00
parent 931f17c589
commit 4d24741d48
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 24 additions and 4 deletions

View file

@ -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 => { export default () => new Promise(resolve => {
const server = createServer(); const server = createServer();

View file

@ -27,7 +27,6 @@ process.on('unhandledRejection', console.dir);
//#endregion //#endregion
const app = require('../built/server/api').default; const app = require('../built/server/api').default;
require('../built/server').default();
const db = require('../built/db/mongodb').default; const db = require('../built/db/mongodb').default;
const server = http.createServer(app.callback()); const server = http.createServer(app.callback());
@ -44,6 +43,10 @@ describe('API', () => {
// Reset database each test // Reset database each test
beforeEach(resetDb(db)); beforeEach(resetDb(db));
before(() => {
server.close();
});
describe('signup', () => { describe('signup', () => {
it('不正なユーザー名でアカウントが作成できない', async(async () => { it('不正なユーザー名でアカウントが作成できない', async(async () => {
const res = await request('/signup', { const res = await request('/signup', {

View file

@ -27,13 +27,13 @@ process.on('unhandledRejection', console.dir);
//#endregion //#endregion
const app = require('../built/server/api').default; 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 db = require('../built/db/mongodb').default;
const server = http.createServer(app.callback()); const apiServer = http.createServer(app.callback());
//#region Utilities //#region Utilities
const request = _request(server); const request = _request(apiServer);
const signup = _signup(request); const signup = _signup(request);
//#endregion //#endregion
@ -41,6 +41,10 @@ describe('Streaming', () => {
// Reset database each test // Reset database each test
beforeEach(resetDb(db)); beforeEach(resetDb(db));
before(() => {
server.close();
});
it('投稿がタイムラインに流れる', done => { it('投稿がタイムラインに流れる', done => {
const post = { const post = {
text: 'foo' text: 'foo'