From d60238a85d5882ebb5f2b697fdafd63a4fe42381 Mon Sep 17 00:00:00 2001 From: aetn23 Date: Sun, 19 Mar 2023 13:37:03 +0100 Subject: [PATCH 1/6] Add badge --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5ef0cb7 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# pokerio-server + +[![Build](https://github.com/poker-io/pokerio-server/actions/workflows/main.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/main.yml) \ No newline at end of file From 590f05ff9f8e8fb874436c12213a6d66446b6ef4 Mon Sep 17 00:00:00 2001 From: aetn23 Date: Sun, 19 Mar 2023 13:40:22 +0100 Subject: [PATCH 2/6] Add further badges --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ef0cb7..09eaa72 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # pokerio-server -[![Build](https://github.com/poker-io/pokerio-server/actions/workflows/main.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/main.yml) \ No newline at end of file +[![Build](https://github.com/poker-io/pokerio-server/actions/workflows/main.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/main.yml) +[![Lint](https://github.com/poker-io/pokerio-server/actions/workflows/eslint.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/eslint.yml) +[![Prettier](https://github.com/poker-io/pokerio-server/actions/workflows/prettier.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/prettier.yml) +[![Tests](https://github.com/poker-io/pokerio-server/actions/workflows/test.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/test.yml) +[![codecov](https://codecov.io/gh/poker-io/pokerio-server/branch/main/graph/badge.svg?token=4QCZNOWFZJ)](https://codecov.io/gh/poker-io/pokerio-server) \ No newline at end of file From 9dd5afed146cef52eb85a84c2bbb86f78318477e Mon Sep 17 00:00:00 2001 From: aetn23 Date: Sun, 19 Mar 2023 13:50:37 +0100 Subject: [PATCH 3/6] Add sections about building, running, testing --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09eaa72..c4f71a6 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,17 @@ [![Lint](https://github.com/poker-io/pokerio-server/actions/workflows/eslint.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/eslint.yml) [![Prettier](https://github.com/poker-io/pokerio-server/actions/workflows/prettier.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/prettier.yml) [![Tests](https://github.com/poker-io/pokerio-server/actions/workflows/test.yml/badge.svg)](https://github.com/poker-io/pokerio-server/blob/main/.github/workflows/test.yml) -[![codecov](https://codecov.io/gh/poker-io/pokerio-server/branch/main/graph/badge.svg?token=4QCZNOWFZJ)](https://codecov.io/gh/poker-io/pokerio-server) \ No newline at end of file +[![codecov](https://codecov.io/gh/poker-io/pokerio-server/branch/main/graph/badge.svg?token=4QCZNOWFZJ)](https://codecov.io/gh/poker-io/pokerio-server) + +## Building + +Run `yarn install` + +## Running + +Run `yarn start`. + +## Testing + +We use Jest for testing. To run it, simply type `yarn test`. +Make sure your Node's version is > v18 (`nvm install v18.15.0` to install appropriate version). \ No newline at end of file From 11e646d278d8f9451496a85d1ba9a23a894281f6 Mon Sep 17 00:00:00 2001 From: aetn23 Date: Sun, 19 Mar 2023 13:52:52 +0100 Subject: [PATCH 4/6] Run prettier --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c4f71a6..55c2bd1 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Run `yarn install` ## Running -Run `yarn start`. +Run `yarn start`. ## Testing -We use Jest for testing. To run it, simply type `yarn test`. -Make sure your Node's version is > v18 (`nvm install v18.15.0` to install appropriate version). \ No newline at end of file +We use Jest for testing. To run it, simply type `yarn test`. +Make sure your Node's version is > v18 (`nvm install v18.15.0` to install appropriate version). From 6fa180606c453a780321da4bab9df4326ac9a1d5 Mon Sep 17 00:00:00 2001 From: aetn23 Date: Tue, 21 Mar 2023 12:40:08 +0100 Subject: [PATCH 5/6] Setup supertest --- package.json | 21 +++++++++++---------- src/app.ts | 8 ++++++++ src/server.ts | 5 +++++ src/tests/app.test.ts | 12 ++++++++++++ src/tests/index.test.ts | 6 ------ 5 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/app.ts create mode 100644 src/server.ts create mode 100644 src/tests/app.test.ts delete mode 100644 src/tests/index.test.ts diff --git a/package.json b/package.json index e3154b9..b9f8f4d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "type": "module", "license": "MIT", "scripts": { - "start": "tsc && node dist/index.js", + "start": "tsc && node dist/server.js", "build": "tsc", "test": "jest src/tests --coverage --config package.json", "lint": "eslint --ext '.js,.ts,.tsx' src/", @@ -24,21 +24,22 @@ "eslint-plugin-import": "^2.25.2", "eslint-plugin-n": "^15.0.0", "eslint-plugin-promise": "^6.0.0", + "husky": "^8.0.0", "prettier": "2.8.4", + "supertest": "^6.3.3", "ts-jest": "^29.0.5", - "typescript": "4.9.5", - "husky": "^8.0.0" + "typescript": "4.9.5" }, "dependencies": { "express": "^4.18.2", "jest": "^29.5.0" }, - "jest" : { - "collectCoverage": true, - "testEnvironment": "node", - "collectCoverageFrom": [ - "src/*.ts" - ] - + "jest": { + "collectCoverage": true, + "testEnvironment": "node", + "collectCoverageFrom": [ + "src/*.ts" + ], + "preset": "ts-jest" } } diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..6a2a82e --- /dev/null +++ b/src/app.ts @@ -0,0 +1,8 @@ +import express from 'express' + +export const app = express() +export const port = 42069 + +app.get('/test', (req, res) => { + res.send('Hello from typescript express!') +}) diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..9aa44a4 --- /dev/null +++ b/src/server.ts @@ -0,0 +1,5 @@ +import { app, port } from './app.js' + +app.listen(port, () => { + console.log(`[server]: Server is running at localhost:${port}`) +}) diff --git a/src/tests/app.test.ts b/src/tests/app.test.ts new file mode 100644 index 0000000..441c86e --- /dev/null +++ b/src/tests/app.test.ts @@ -0,0 +1,12 @@ +import { app } from '../app' + +import request from 'supertest' + +test('Simple test', (done) => { + request(app) + .get('/test') + .expect(200) + .expect('Content-Type', 'text/html; charset=utf-8') + .expect('Hello from typescript express!') + .end(done) +}) diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts deleted file mode 100644 index 2e75baf..0000000 --- a/src/tests/index.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -test('Simple test', async () => { - // for some reason using port from imported varaible gives weird errors - const response = await fetch('http://localhost:42069/test') - const text = await response.text() - expect(text).toEqual('Hello from typescript express!') -}) From 034f45f7ce5bca1957fe90477021c0a1ed77aa0f Mon Sep 17 00:00:00 2001 From: aetn23 Date: Tue, 21 Mar 2023 12:46:45 +0100 Subject: [PATCH 6/6] Remove server start from workflow --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ab39dbc..e2528f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,8 +31,6 @@ jobs: - name: Start server run: | yarn install - yarn start & - sleep 10 yarn test - name: Upload coverage reports to Codecov env: