generated from 47ng/typescript-library-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbasics.test.ts
54 lines (49 loc) · 1.53 KB
/
basics.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import axios from 'axios'
import { nanoid } from 'nanoid'
import { createServer, startServer } from '../src'
describe('Basics', () => {
beforeEach(() => {
process.env.LOG_LEVEL = 'silent'
})
test('The specified `name` property is injected', () => {
const unnamedServer = createServer()
expect(unnamedServer.name).toBeUndefined()
const namedServer = createServer({ name: 'foo' })
expect(namedServer.name).toBe('foo')
})
test('Default port should be 3000', async () => {
const key = nanoid()
const server = createServer()
server.get('/', (_, res) => {
res.send({ key })
})
await startServer(server)
const res = await axios.get('http://localhost:3000/')
expect(res.data.key).toEqual(key)
await server.close()
})
test('Port should be configurable via the environment', async () => {
process.env.PORT = '3001'
const key = nanoid()
const server = createServer()
server.get('/', (_, res) => {
res.send({ key })
})
await startServer(server)
const res = await axios.get('http://localhost:3001/')
expect(res.data.key).toEqual(key)
await server.close()
process.env.PORT = undefined
})
test('Port can be passed as a second argument to `startServer`', async () => {
const server = createServer()
const key = nanoid()
server.get('/', (_, res) => {
res.send({ key })
})
await startServer(server, 3002)
const res = await axios.get('http://localhost:3002/')
expect(res.data.key).toEqual(key)
await server.close()
})
})