-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathoptions.timing.test.ts
More file actions
86 lines (77 loc) · 2.81 KB
/
options.timing.test.ts
File metadata and controls
86 lines (77 loc) · 2.81 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { strict as assert } from 'node:assert';
import { setTimeout as sleep } from 'node:timers/promises';
import { describe, it, beforeAll, afterAll } from 'vite-plus/test';
import urllib from '../src/index.js';
import type { RawResponseWithMeta } from '../src/index.js';
import { startServer } from './fixtures/server.js';
describe('options.timing.test.ts', () => {
let close: any;
let _url: string;
beforeAll(async () => {
const { closeServer, url } = await startServer();
close = closeServer;
_url = url;
});
afterAll(async () => {
await close();
});
it('should timing = true work', async () => {
let response = await urllib.request(`${_url}?content-encoding=gzip`, {
dataType: 'json',
timing: true,
});
assert.equal(response.status, 200);
let res = response.res as RawResponseWithMeta;
assert(res.timing.waiting > 0);
assert(res.timing.queuing > 0);
assert(res.timing.connected > 0);
assert(res.timing.dnslookup >= 0);
assert(res.timing.dnslookup <= res.timing.connected);
assert(res.timing.requestHeadersSent > 0);
assert(res.timing.requestSent > 0);
assert(res.timing.contentDownload > 0);
assert(res.timing.contentDownload > res.timing.waiting);
assert(res.timing.contentDownload <= res.rt);
assert.equal(res.socket.handledResponses, 1);
// again connected should be zero
await sleep(1);
response = await urllib.request(`${_url}?content-encoding=gzip`, {
dataType: 'json',
timing: true,
});
assert.equal(response.status, 200);
res = response.res as RawResponseWithMeta;
assert(res.timing.waiting > 0);
assert(res.timing.queuing > 0);
assert.equal(res.timing.connected, 0);
assert.equal(res.timing.dnslookup, 0);
assert(res.timing.requestHeadersSent > 0);
assert(res.timing.requestSent > 0);
assert(res.timing.contentDownload > 0);
assert(res.timing.contentDownload > res.timing.waiting);
assert(res.timing.contentDownload <= res.rt);
assert.equal(res.socket.handledResponses, 2);
// console.log(res.timing);
});
it('should timing = false work', async () => {
const response = await urllib.request(`${_url}?content-encoding=gzip`, {
dataType: 'json',
timing: false,
});
assert.equal(response.status, 200);
const res = response.res as RawResponseWithMeta;
assert.equal(res.timing.waiting, 0);
assert.equal(res.timing.contentDownload, 0);
assert(res.rt > 0);
});
it('should timing default to true', async () => {
const response = await urllib.request(`${_url}?content-encoding=gzip`, {
dataType: 'json',
});
assert.equal(response.status, 200);
const res = response.res as RawResponseWithMeta;
assert(res.timing.waiting > 0);
assert(res.timing.contentDownload > 0);
assert(res.rt > 0);
});
});