Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test setup #15

Merged
merged 4 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
"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",
"node-fetch": "^3.3.1"
mikolaj-pirog marked this conversation as resolved.
Show resolved Hide resolved
}
}
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!')
});