diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..6c1e9ae --- /dev/null +++ b/jest.config.js @@ -0,0 +1,5 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +export default { + preset: 'ts-jest', + testEnvironment: 'node', +}; \ No newline at end of file diff --git a/package.json b/package.json index e8573bc..7189d84 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,21 @@ "main": "src/index.ts", "repository": "git@github.com:poker-io/pokerio-server.git", "author": "Karol WÄ…sowski ", + "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" } } diff --git a/src/index.ts b/src/index.ts index 0c46604..2bfe302 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ 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!') @@ -9,4 +9,4 @@ app.get('/test', (req, res) => { app.listen(port, () => { console.log(`[server]: Server is running at localhost:${port}`) -}) \ No newline at end of file +}) diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts new file mode 100644 index 0000000..340d67d --- /dev/null +++ b/src/tests/index.test.ts @@ -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!') +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 295cb9f..20e5866 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "module": "commonjs", "esModuleInterop": true, "target": "es6", "moduleResolution": "node",