-
-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathping.test.js
More file actions
33 lines (25 loc) · 677 Bytes
/
Copy pathping.test.js
File metadata and controls
33 lines (25 loc) · 677 Bytes
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
import http from 'node:http'
import test from 'node:test'
import { app, events } from '../../app.js'
import ping from '../../scripts/ping.js'
ping(app, events)
test('GET /ping responds with status 200 / "pong"', (t, done) => {
const server = app.listen()
const port = server.address().port
const url = `http://localhost:${port}/ping`
t.plan(2)
t.after(() => server.close())
http.get(url, (res) => {
t.assert.strictEqual(res.statusCode, 200)
let data = ''
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
t.assert.strictEqual(data, 'pong')
done()
})
}).on('error', (e) => {
t.fail(e)
})
})