-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
64 lines (54 loc) · 1.4 KB
/
index.test.js
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
55
56
57
58
59
60
61
62
63
64
'use strict'
const path = require('path')
const fetch = require('node-fetch')
const https = require('https')
const server = require('./index')
// Accept self signed SSL cert
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const logger = {
info: () => {},
trace: () => {},
debug: () => {},
}
// eslint-disable-next-line no-unused-vars
server.use('/test', (req, res, next) =>
res.status(200).json({
status: 'ok',
})
)
describe('HTTP Server', () => {
afterAll(() => jest.resetAllMocks())
beforeEach(() => {
jest.resetModules()
})
afterEach(() => {
server.close()
})
test('can start the server', async () => {
server.start({
port: 3002,
useSsl: false,
logger,
})
const res = await fetch('http://localhost:3002/test')
const json = await res.json()
expect(json).not.toBeUndefined()
expect(json.status).toBe('ok')
})
test('can start the server in secure mode', async () => {
server.start({
port: 9090,
useSsl: true,
pfx: path.join(__dirname, 'test/certs/withpassphrase.pfx'),
passphrase: path.join(__dirname, 'test/certs/passphrase.txt'),
logger,
})
const agent = new https.Agent({
rejectUnauthorized: false,
})
const res = await fetch('https://localhost:9090/test', { agent })
const json = await res.json()
expect(json).not.toBeUndefined()
expect(json.status).toBe('ok')
})
})