Skip to content

Commit

Permalink
feat(server.ts): add server to handle incoming requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Makila committed Sep 13, 2020
1 parent 3422a4d commit 8c8adf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/server.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import app from '../app';

jest.mock('../app', () => ({
listen: jest.fn((port: number, fn: () => void) => fn()),
get: () => 424242
}));
const mockApp = app as jest.Mocked<typeof app>;

describe('server', () => {
it('should listen to port provided by the app', () => {
require('../server');
expect(mockApp.listen).toHaveBeenCalledWith(424242, expect.any(Function));
});
});
8 changes: 8 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import app from './app';
import { info } from './logger';

const server = app.listen(app.get('port'), () => {
info(`Server is running on port ${app.get('port')}`);
});

export default server;

0 comments on commit 8c8adf3

Please sign in to comment.