-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinstantiate.mjs
73 lines (66 loc) · 1.69 KB
/
instantiate.mjs
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
import { Bench } from 'tinybench';
import { RequestError } from "../pkg/dist-src/index.js";
const bench = new Bench({ time: 100 });
const optionsWithSimpleRequest = Object.assign({}, {
request: {
method: "POST",
url: "https://api.github.com/authorizations",
headers: {},
body: {
note: "test",
},
},
response: {
headers: {},
status: 200,
url: "https://api.github.com/",
data: {},
}
});
const optionsWithRequestHavingClientSecretInQuery = Object.assign({}, {
request: {
method: "POST",
url: "https://api.github.com/authorizations?client_secret=secret",
headers: {},
body: {
note: "test",
},
},
response: {
headers: {},
status: 200,
url: "https://api.github.com/",
data: {},
}
});
const optionsWithRequestHavingAuthorizationHeader = Object.assign({}, {
request: {
method: "POST",
url: "https://api.github.com/authorizations",
headers: {
authorization: "token secret123",
},
body: {
note: "test",
},
},
response: {
headers: {},
status: 200,
url: "https://api.github.com/",
data: {},
}
});
bench
.add('instantiate a simple RequestError', () => {
new RequestError("test", 123, optionsWithSimpleRequest)
})
.add('instantiate a RequestError with authorization header in header', () => {
new RequestError("test", 123, optionsWithRequestHavingAuthorizationHeader)
})
.add('instantiate a RequestError with client_secret in query', () => {
new RequestError("test", 123, optionsWithRequestHavingClientSecretInQuery)
})
await bench.warmup(); // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50
await bench.run();
console.table(bench.table());