Skip to content

Commit

Permalink
Test setup (#15)
Browse files Browse the repository at this point in the history
Test setup with jest. Simple test with JS fetch to test server GET
response
  • Loading branch information
mikolaj-pirog authored Mar 17, 2023
1 parent 294cfaa commit 2840189
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
};
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
"main": "src/index.ts",
"repository": "git@github.com:poker-io/pokerio-server.git",
"author": "Karol Wąsowski <wasowski02@protonmail.com>",
"type": "module",
"license": "MIT",
"scripts": {
"start": "tsc && node dist/index.js"
"start": "tsc && node dist/index.js",
"build": "tsc",
"test": "jest src/tests"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/jest": "^29.4.4",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
},
"dependencies": {
"express": "^4.18.2"
"express": "^4.18.2",
"jest": "^29.5.0"
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import express from "express"

const app = express()
const port = 42069
export const port = 42069

app.get('/test', (req, res) => {
res.send('Hello from typescript express!')
})

app.listen(port, () => {
console.log(`[server]: Server is running at localhost:${port}`)
})
})
8 changes: 8 additions & 0 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {port} from '../index'

test('Simple test', async () => {
// for some reason using port from imported varaible gives weird errors
let response = await fetch('http://localhost:42069/test')
let text = await response.text();
expect(text).toEqual('Hello from typescript express!')
});
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
Expand Down

0 comments on commit 2840189

Please sign in to comment.