-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup supertest to test http endpoints. Split `index.ts` to `server.ts` with `listen` and `app.ts` with endpoints. This is done, so testing of endpoints will be possible without calling `listen` (that way supertest can assign its own port, also no need to worry about closing down the server). It turn out that imports of `ts` files need to end with `.js`, otherwise they will not work after `tsc`. See `server.ts` --------- Co-authored-by: Karol Wąsowski <wasowski02@protonmail.com>
- Loading branch information
1 parent
fa7d715
commit 069ac9e
Showing
6 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { app, port } from './app.js' | ||
|
||
app.listen(port, () => { | ||
console.log(`[server]: Server is running at localhost:${port}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |
This file was deleted.
Oops, something went wrong.