-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_deps.ts
90 lines (79 loc) · 2.14 KB
/
dev_deps.ts
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
87
88
89
90
export * from "https://deno.land/[email protected]/testing/asserts.ts";
export * from "https://deno.land/[email protected]/testing/bdd.ts";
export * from "https://deno.land/[email protected]/media_types/mod.ts";
export * from "https://deno.land/[email protected]/http/mod.ts";
import {
defineExpect,
equal,
jestMatcherMap,
jestModifierMap,
MatchResult,
} from "https://deno.land/x/[email protected]/mod.ts";
import { isString } from "https://deno.land/x/[email protected]/mod.ts";
export * from "https://esm.sh/[email protected]";
export const expect = defineExpect({
matcherMap: {
...jestMatcherMap,
toError: (
actual: unknown,
// deno-lint-ignore ban-types
error: Function,
message?: string,
) => {
if (!(actual instanceof Error)) {
return {
pass: false,
expected: "Error Object",
};
}
if (!(actual instanceof error)) {
return {
pass: false,
expected: `${error.name} Object`,
};
}
if (message) {
return {
pass: actual.message === message,
expected: message,
resultActual: actual.message,
};
}
return {
pass: true,
expected: error,
};
},
toEqualIterable,
},
modifierMap: jestModifierMap,
});
function toEqualIterable(
actual: Iterable<readonly [PropertyKey, string]>,
expected: Iterable<readonly [PropertyKey, string]>,
): MatchResult {
const act = Object.fromEntries(actual);
const exp = Object.fromEntries(expected);
return {
pass: equal(act, exp),
expected: exp,
resultActual: act,
};
}
export function queryString(
baseURL: string | URL,
urlParams: { [param: string]: string },
): string {
const url = isString(baseURL) ? new URL(baseURL) : baseURL;
Object.entries(urlParams).forEach(([key, value]) => {
url.searchParams.set(key, value);
});
return url.toString();
}
export class BaseRequest extends Request {
constructor(input: RequestInfo, init?: RequestInit) {
const headers = new Headers(init?.headers);
headers.append("accept", "application/graphql+json");
super(input, { ...init, headers });
}
}