github
90 of 92 branches covered (0.0%)
Branch coverage included in aggregate %.
61 of 65 new or added lines in 3 files covered. (93.85%)
4 existing lines in 1 file now uncovered.409 of 413 relevant lines covered (99.03%)
18.84 hits per line
1 |
export interface ResponseFormatter {
|
1✔ |
2 |
(body?: any, options?: ResponseInit): Response |
1✔ |
3 |
} |
1✔ |
4 |
|
1✔ |
5 |
export interface BodyTransformer {
|
1✔ |
6 |
(body: any): string
|
1✔ |
7 |
} |
1✔ |
8 |
|
1✔ |
9 |
export const createResponse = |
1✔ |
10 |
( |
|
11 |
format = 'text/plain; charset=utf-8', |
12✔ |
12 |
transform?: BodyTransformer |
12✔ |
13 |
): ResponseFormatter => |
12✔ |
14 |
(body, options?: ResponseInit) => { |
|
15 |
const { headers = {}, ...rest } = options || {}
|
|
16 |
|
27✔ |
|
if (body === undefined) {
|
|
NEW
UNCOV
|
console.log('attempting to transform undefined body') |
× |
NEW
UNCOV
|
} |
× |
|
|
27✔ |
|
if (body?.constructor.name === 'Response' || body === undefined) return body |
|
|
|
25✔ |
|
if (body === undefined) {
|
|
NEW
UNCOV
|
console.log('succeeeded in transforming undefined body') |
× |
NEW
UNCOV
|
} |
|
26 |
|
25✔ |
27 |
return new Response(transform ? transform(body) : body, { |
|
28 |
headers: {
|
27✔ |
29 |
'content-type': format, |
27✔ |
30 |
...headers, |
27✔ |
31 |
}, |
27✔ |
32 |
...rest, |
27✔ |
33 |
}) |
27✔ |
34 |
} |
27✔ |